Files
UVtools/UVtools.Core/Operations/OperationLayerRemove.cs
T
Tiago Conceição 1e9bbf9562 v2.7.2
* **Core:**
   * Fix some improper locks for progress counter and change to Interlocked instead
   * Fix a bug when chaging layer count by remove or add layers it will malform the file after save and crash the program with some tools and/or clipboard
   * Fix when a operation fails by other reason different from cancelation it was not restoring the backup
   * When manually delete/fix issues it will also backup the layers
* **LayerManager:**
   * LayerManager is now readonly and no longer used to transpose layers, each FileFormat have now a unique `LayerManager` instance which is set on the generic constructor
   * Implemented `List<Layer>` methods to easy modify the layers array
   * Changing the `Layers` instance will now recompute some properties, call the properties rebuild and forced sanitize of the structure
   * Better reallocation methods
* **Clipboard Manager:**
   * Add the hability to do full backups, they will be marked with an asterisk (*) at clipboard items list
   * When a partial backup is made and it backups all the layers it will be converted to full backup
   * Clipboard can now restore a snapshot directly with `RestoreSnapshot`
   * Prevent restore the initial backup upon file load and when clearing the clipboard
   * Clip's that change the layer count will perform a full backup and also do a fail-safe backup behind if previous clip is not a full backup
* **Pixel dimming:**
   * Allow to load an image file as a pattern (Do not use very large files or it will take much time to dump the data into the textbox)
   * Empty lines on patterns will be discarded and not trigger validation error
2021-03-28 04:26:01 +01:00

129 lines
3.9 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.Generic;
using UVtools.Core.FileFormats;
namespace UVtools.Core.Operations
{
[Serializable]
public sealed class OperationLayerRemove : Operation
{
#region Overrides
public override Enumerations.LayerRangeSelection StartLayerRangeSelection => Enumerations.LayerRangeSelection.Current;
public override bool CanROI => false;
public override bool PassActualLayerIndex => true;
public override string Title => "Remove layers";
public override string Description =>
"Remove Layers in a given range.";
public override string ConfirmationText =>
$"remove layers {LayerIndexStart} through {LayerIndexEnd}?";
public override string ProgressTitle =>
$"Removing layers {LayerIndexStart} through {LayerIndexEnd}";
public override string ProgressAction => "Removed layers";
public override bool CanCancel => false;
public override bool CanHaveProfiles => false;
#endregion
#region Properties
#endregion
#region Constructor
public OperationLayerRemove() { }
public OperationLayerRemove(FileFormat slicerFile) : base(slicerFile) { }
#endregion
#region Methods
protected override bool ExecuteInternally(OperationProgress progress)
{
progress.CanCancel = false;
var layersRemove = new List<uint>();
for (uint layerIndex = LayerIndexStart; layerIndex <= LayerIndexEnd; layerIndex++)
{
layersRemove.Add(layerIndex);
}
return RemoveLayers(SlicerFile, layersRemove, progress);
}
public static bool RemoveLayers(FileFormat slicerFile, List<uint> layersRemove, OperationProgress progress = null)
{
if (layersRemove.Count == 0) return false;
progress ??= new OperationProgress(false);
progress.Reset("Removed layers", (uint)layersRemove.Count);
foreach (var layerIndex in layersRemove)
{
slicerFile[layerIndex] = null;
progress++;
}
slicerFile.LayerManager.RemoveNulls();
/*var oldLayers = slicerFile.LayerManager.Layers;
var layerHeight = slicerFile.LayerHeight;
var layers = new Layer[oldLayers.Length - layersRemove.Count];
// Re-set
uint newLayerIndex = 0;
for (uint layerIndex = 0; layerIndex < oldLayers.Length; layerIndex++)
{
if (layersRemove.Contains(layerIndex)) continue;
layers[newLayerIndex] = oldLayers[layerIndex];
layers[newLayerIndex].Index = newLayerIndex;
// Re-Z
float posZ = layerHeight;
if (newLayerIndex > 0)
{
if (oldLayers[layerIndex - 1].PositionZ == oldLayers[layerIndex].PositionZ)
{
posZ = layers[newLayerIndex - 1].PositionZ;
}
else
{
posZ = Layer.RoundHeight(layers[newLayerIndex - 1].PositionZ + layerHeight);
}
}
layers[newLayerIndex].PositionZ = posZ;
layers[newLayerIndex].IsModified = true;
newLayerIndex++;
progress++;
}
slicerFile.LayerManager.Layers = layers;*/
return true;
}
#endregion
}
}