Files
UVtools/UVtools.Core/Operations/OperationLayerRemove.cs
T
Tiago Conceição 57b8a9dc84 v3.2.0
- **Core:**
   - (Add) Machine presets and able to load machine collection from PrusaSlicer
   - (Improvement) Core: Reference EmguCV runtimes into core instead of the UI project
- **File formats:**
   - **CXDLP:**
      - (Add) Detection support for Halot One Pro
      - (Add) Detection support for Halot One Plus
      - (Add) Detection support for Halot Sky Plus
      - (Add) Detection support for Halot Lite
      - (Improvement) Better handling and detection of printer model when converting
      - (Improvement) Discovered more fields meanings on format
      - (Fix) Exposure time in format is `round(time * 10, 1)`
      - (Fix) Speeds in format are in mm/s, was using mm/min before
   - (Add) JXS format for Uniformation GKone [Zip+GCode]
   - (Improvement) Saving and converting files now handle the file backup on Core instead on the UI, which prevents scripts and other projects lose the original file in case of error while saving
   - (Fix) After load files they was flagged as requiring a full encode, preventing fast save a fresh file
- **UVtoolsCmd:**
   - Bring back the commandline project
   - Consult README to see the available commands and syntax
   - Old terminal commands on UVtools still works for now, but consider switch to UVtoolsCmd or redirect the command using `UVtools --cmd "commands"`
- **Tools:**
   - **Change print resolution:**
      - (Add) Allow to change the display size to match the new printer
      - (Add) Machine presets to help set both resolution and display size to a correct printer and auto set fix pixel ratio
      - (Improvement) Real pixel pitch fixer due new display size information, this allow full transfers between different printers "without" invalidating the model size
      - (Improvement) Better arrangement of  the layout
   - (Add) Infill: Option "Reinforce infill if possible", it was always on before, now default is off and configurable
   - (Improvement) Always allow to export settings from tools
- **GCode:**
   - (Improvement) After print the last layer, do one lift with the same layer settings before attempt a fast move to top
   - (Improvement) Use the highest defined speed to send the build plate to top after finish print
   - (Improvement) Append a wait sync command in the end of gcode if needed
   - (Fix) When lift without a retract it still output the motor sync delay for the retract time and the wait time after retract
- **PrusaSlicer:**
   - (Add) Printer: Creality Halot One Pro CL-70
   - (Add) Printer: Creality Halot One Plus CL-79
   - (Add) Printer: Creality Halot Sky Plus CL-92
   - (Add) Printer: Creality Halot Lite CL-89L
   - (Add) Printer: Creality Halot Lite CL-89L
   - (Add) Printer: Creality CT133 Pro
   - (Add) Printer: Creality CT-005 Pro
   - (Add) Printer: Uniformation GKone
   - (Add) Printer: FlashForge Foto 8.9S
   - (Add) Printer: Elegoo Mars 2
   - (Improvement) Rename all Creality printers
   - (Fix) Creality model in print notes
2022-03-26 03:38:39 +00:00

214 lines
6.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.Collections.Generic;
using System.Linq;
using System.Text;
using UVtools.Core.FileFormats;
using UVtools.Core.Layers;
namespace UVtools.Core.Operations;
[Serializable]
public sealed class OperationLayerRemove : Operation
{
#region Members
private bool _useThreshold;
private uint _pixelThreshold;
#endregion
#region Overrides
public override LayerRangeSelection StartLayerRangeSelection => LayerRangeSelection.Current;
public override bool CanROI => false;
public override bool PassActualLayerIndex => true;
public override string IconClass => "mdi-layers-remove";
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}"+
(_useThreshold ? $" with an pixel threshold of {_pixelThreshold}px" : string.Empty)
+"?";
public override string ProgressTitle =>
$"Removing layers {LayerIndexStart} through {LayerIndexEnd}" +
(_useThreshold ? $" with an pixel threshold of {_pixelThreshold}px" : string.Empty);
public override string ProgressAction => "Removed layers";
public override bool CanCancel => false;
public override bool CanHaveProfiles => false;
public override string? ValidateInternally()
{
var sb = new StringBuilder();
var layersToRemove = LayerRemoveCount;
if (LayerRemoveCount == 0)
{
sb.AppendLine("The used values will not remove any layer, please adjust.");
}
if (layersToRemove == SlicerFile.LayerCount)
{
sb.AppendLine("You can't remove all layers from the file. Keep at least one.");
}
return sb.ToString();
}
#endregion
#region Properties
public bool UseThreshold
{
get => _useThreshold;
set
{
if(!RaiseAndSetIfChanged(ref _useThreshold, value)) return;
RaisePropertyChanged(nameof(LayerRemoveCount));
}
}
public uint PixelThreshold
{
get => _pixelThreshold;
set
{
if(!RaiseAndSetIfChanged(ref _pixelThreshold, value)) return;
RaisePropertyChanged(nameof(LayerRemoveCount));
}
}
public uint LayerRemoveCount
{
get
{
if (!_useThreshold) return LayerRangeCount;
uint layers = 0;
for (uint layerIndex = LayerIndexStart; layerIndex <= LayerIndexEnd; layerIndex++)
{
if (SlicerFile[layerIndex].NonZeroPixelCount > _pixelThreshold) continue;
layers++;
}
return layers;
}
}
#endregion
#region Constructor
public OperationLayerRemove() { }
public OperationLayerRemove(FileFormat slicerFile) : base(slicerFile) { }
#endregion
#region Equality
private bool Equals(OperationLayerRemove other)
{
return _useThreshold == other._useThreshold && _pixelThreshold == other._pixelThreshold;
}
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || obj is OperationLayerRemove other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(_useThreshold, _pixelThreshold);
}
#endregion
#region Methods
protected override bool ExecuteInternally(OperationProgress progress)
{
progress.CanCancel = false;
var layersRemove = new List<uint>();
for (uint layerIndex = LayerIndexStart; layerIndex <= LayerIndexEnd; layerIndex++)
{
if(_useThreshold && SlicerFile[layerIndex].NonZeroPixelCount > _pixelThreshold) continue;
layersRemove.Add(layerIndex);
}
return RemoveLayers(SlicerFile, layersRemove, progress);
}
public static bool RemoveLayers(FileFormat slicerFile, IEnumerable<uint> layersRemove, OperationProgress? progress = null)
{
if (!layersRemove.Any()) return false;
progress ??= new OperationProgress(false);
progress.Reset("Removed layers", (uint)layersRemove.Count());
var layers = slicerFile.ToList();
int removedBottomLayers = 0;
//uint lastRemovedBottomLayerIndex = 0;
var lastBottomLayer = slicerFile.LastBottomLayer;
// Register bottom layers
if (slicerFile.BottomLayerCount > 0)
{
var layersRemoveAsc = layersRemove.OrderBy(index => index);
foreach (var layerIndex in layersRemoveAsc)
{
if (!slicerFile[layerIndex].IsBottomLayer) continue;
removedBottomLayers++;
//lastRemovedBottomLayerIndex = layerIndex;
}
}
// Remove layers
var layersRemoveDesc = layersRemove.OrderByDescending(index => index);
foreach (var layerIndex in layersRemoveDesc)
{
layers.RemoveAt((int)layerIndex);
// Shift layer positions
var relativeZ = slicerFile[layerIndex].RelativePositionZ;
if (relativeZ <= 0) continue;
for (uint i = layerIndex + 1; i < slicerFile.LayerCount; i++)
{
slicerFile[i].PositionZ -= relativeZ;
}
progress++;
}
// Should never happen, still use this safe-check
if (slicerFile.LayerCount != layers.Count)
{
// Try to copy bottom parameters to shifted new bottom layers
if (removedBottomLayers > 0 && lastBottomLayer is not null)
{
var startIndex = (uint) Math.Max(lastBottomLayer.Index + 1, layersRemove.Count());
var endIndex = startIndex + removedBottomLayers;
var copyFromFromLayerIndex = (uint)Math.Max(0, (int)lastBottomLayer.Index);
for (var layerIndex = startIndex; layerIndex < endIndex && layerIndex < slicerFile.LayerCount; layerIndex++)
{
slicerFile[copyFromFromLayerIndex].CopyParametersTo(slicerFile[layerIndex]);
}
}
slicerFile.SuppressRebuildPropertiesWork(() => slicerFile.Layers = layers.ToArray());
}
return true;
}
#endregion
}