Skip to content

Commit

Permalink
v3.9.1
Browse files Browse the repository at this point in the history
- (Improvement) Performance on pixel editor when using high count of layers below and/or above
- (Fix) Unable to disable specific issues detection
  • Loading branch information
sn4k3 committed Dec 3, 2022
1 parent 8168988 commit 1da6f52
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 76 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 03/12/2022 - v3.9.1

- (Improvement) Performance on pixel editor when using high count of layers below and/or above
- (Fix) Unable to disable specific issues detection

## 01/12/2022 - v3.9.0

- **File formats:**
Expand Down
34 changes: 2 additions & 32 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
- **File formats:**
- (Add) File extension: .gktwo.ctb to `ChituboxFile` to be able to convert files for UniFormation GKtwo under special CTB format
- (Add) UniFormation GKtwo compatibility under CTB format, if exporting JXS rename to CTB before open
- (Fix) CTB, CBDDLP, PHOTON, FDG, PHZ: Read and write files larger then 4GB (#608)
- **PCB Exposure:**
- (Add) Offset X/Y to offset the PCB from it origin
- (Add) Allow to toggle between "Show preview image cropped by it bounds" and "Show full preview image (The final result)"
- (Improvement) Use rectangle instead of line for center line primitive (#607)
- (Fix) Implement rotation to polygon and center line primitives (#607)
- (Fix) Macros in a single line was not being parsed (#607)
- (Fix) Invert color per file was not affecting primitives
- **Network printers:**
- (Add) Socket requests with TCP and UDP
- (Add) AnyCubic printer preset (However it can't upload a file)
- (Add) Scripts in request path to allow a first request to fetch data to the final request:
- A script starts with **<\?** and ends with **?>**
- First parameter is the first request to get response content from
- Second parameter is the regex pattern to match content with
- Third parameter is the final request that supports a parameter from regex matching group, eg: **{#1}** is match Group[1] value
- **Example:** <\? getfiles > {0}\/(\d+\.[\da-zA-Z]+), > printfile,{#1} ?>
- (Change) Allow to print a filename without send it when upload request path is empty
- (Fix) Do not show printers with empty requests
- (Change) Default layer compression to Lz4 instead of Png
- (Improvement) Application is now culture aware but set part of `NumberFormat` to the `InvariantCulture.NumberFormat`
- (Improvement) Material cost now show with the current culture currency symbol due previous change
- (Improvement) Better submit of bug reports using sections and forms
- (Improvement) Linux: AppImage now have a help manual with possible arguments and parameters
- (Improvement) macOS: Codesign app on auto-installer and auto-upgrade to bypass arm64 run restriction (#431)
- (Improvement) macOS: Rebuilt arm64 libcvextern.dylib to run with less dependencies (#431)
- (Improvement) macOS: Try to show missing dependencies from openCV (if any) on the error message
- (Fix) UI: layers sorted lexicographically instead of numerically in the issues list view (#611)
- (Fix) PrusaSlicer printer parameters: UniFormation GKtwo
- (Improvement) Performance on pixel editor when using high count of layers below and/or above
- (Fix) Unable to disable specific issues detection

26 changes: 26 additions & 0 deletions UVtools.Core/FileFormats/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5729,6 +5729,18 @@ public bool TryParseLayerIndexRange(string value, out uint layerIndexStart, out
return layerIndexStart <= layerIndexEnd;
}

/// <summary>
/// Constrains a layer index to be inside the range between 0 and <see cref="LastLayerIndex"/>
/// </summary>
/// <param name="layerIndex">Layer index to sanitize</param>
/// <returns>True if sanitized, otherwise false</returns>
public bool SanitizeLayerIndex(ref int layerIndex)
{
var originalValue = layerIndex;
layerIndex = Math.Clamp(layerIndex, 0, (int)LastLayerIndex);
return originalValue != layerIndex;
}

/// <summary>
/// Constrains a layer index to be inside the range between 0 and <see cref="LastLayerIndex"/>
/// </summary>
Expand All @@ -5741,11 +5753,25 @@ public bool SanitizeLayerIndex(ref uint layerIndex)
return originalValue != layerIndex;
}

/// <summary>
/// Constrains a layer index to be inside the range between 0 and <see cref="LastLayerIndex"/>
/// </summary>
/// <param name="layerIndex">Layer index to sanitize</param>
public uint SanitizeLayerIndex(int layerIndex)
{
return (uint)Math.Clamp(layerIndex, 0, LastLayerIndex);
}

/// <summary>
/// Constrains a layer index to be inside the range between 0 and <see cref="LastLayerIndex"/>
/// </summary>
/// <param name="layerIndex">Layer index to sanitize</param>
public uint SanitizeLayerIndex(uint layerIndex)
{
return Math.Min(layerIndex, LastLayerIndex);
}


/// <summary>
/// Re-assign layer indexes and parent <see cref="FileFormat"/>
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions UVtools.Core/Operations/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public virtual uint LayerIndexStart
{
if (SlicerFile is not null)
{
value = Math.Min(value, SlicerFile.LastLayerIndex);
SlicerFile.SanitizeLayerIndex(ref value);
}
if (!RaiseAndSetIfChanged(ref _layerIndexStart, value)) return;
RaisePropertyChanged(nameof(LayerRangeCount));
Expand All @@ -235,7 +235,7 @@ public virtual uint LayerIndexEnd
{
if (SlicerFile is not null)
{
value = Math.Min(value, SlicerFile.LastLayerIndex);
SlicerFile.SanitizeLayerIndex(ref value);
}
if(!RaiseAndSetIfChanged(ref _layerIndexEnd, value)) return;
RaisePropertyChanged(nameof(LayerRangeCount));
Expand Down Expand Up @@ -463,7 +463,7 @@ public void SelectLastLayer()
public void SelectFirstToCurrentLayer(uint currentLayerIndex)
{
LayerIndexStart = 0;
LayerIndexEnd = Math.Min(currentLayerIndex, SlicerFile.LastLayerIndex);
LayerIndexEnd = SlicerFile.SanitizeLayerIndex(currentLayerIndex);
}

/// <summary>
Expand All @@ -472,7 +472,7 @@ public void SelectFirstToCurrentLayer(uint currentLayerIndex)
/// <param name="currentLayerIndex">From layer index to select</param>
public void SelectCurrentToLastLayer(uint currentLayerIndex)
{
LayerIndexStart = Math.Min(currentLayerIndex, SlicerFile.LastLayerIndex);
LayerIndexStart = SlicerFile.SanitizeLayerIndex(currentLayerIndex);
LayerIndexEnd = SlicerFile.LastLayerIndex;
}

Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/Operations/OperationLayerArithmetic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public bool Parse()
{
uint.TryParse(rangeSplit[0], out var startLayer);
if (!uint.TryParse(rangeSplit[1], out var endLayer)) endLayer = SlicerFile.LastLayerIndex;
endLayer = Math.Min(endLayer, SlicerFile.LastLayerIndex);
SlicerFile.SanitizeLayerIndex(ref endLayer);
for (var index = startLayer; index <= endLayer; index++)
{
if (group.SetLayers.Contains(index)) continue;
Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/UVtools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl>
<PackageProjectUrl>https://github.com/sn4k3/UVtools</PackageProjectUrl>
<Description>MSLA/DLP, file analysis, calibration, repair, conversion and manipulation</Description>
<Version>3.9.0</Version>
<Version>3.9.1</Version>
<Copyright>Copyright © 2020 PTRTECH</Copyright>
<PackageIcon>UVtools.png</PackageIcon>
<Platforms>AnyCPU;x64</Platforms>
Expand Down
20 changes: 16 additions & 4 deletions UVtools.WPF/MainWindow.Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public async void RemoveRepairIssues(IEnumerable<MainIssue> issues, bool promptC

Clipboard.Snapshot();

var task = await Task.Factory.StartNew(() =>
var task = await Task.Run(() =>
{
Progress.Reset("Removing selected issues", (uint)processParallelIssues.Count);
try
Expand Down Expand Up @@ -448,7 +448,7 @@ private async Task UpdateIslandsOverhangs(List<uint> whiteListLayers)
}*/

var resultIssues = await Task.Factory.StartNew(() =>
var resultIssues = await Task.Run(() =>
{
try
{
Expand Down Expand Up @@ -636,7 +636,7 @@ private async Task ComputeIssues(IssuesDetectionConfiguration config)
IsGUIEnabled = false;
ShowProgressWindow("Computing Issues");

var resultIssues = await Task.Factory.StartNew(() =>
var resultIssues = await Task.Run(() =>
{
try
{
Expand Down Expand Up @@ -825,7 +825,19 @@ public void SetResinTrapDetectionStartLayer(char which)
}
}

public IssuesDetectionConfiguration GetIssuesDetectionConfiguration(bool enable = true)
public IssuesDetectionConfiguration GetIssuesDetectionConfiguration()
{
return new IssuesDetectionConfiguration(
GetIslandDetectionConfiguration(),
GetOverhangDetectionConfiguration(),
GetResinTrapDetectionConfiguration(),
GetTouchingBoundsDetectionConfiguration(),
GetPrintHeightDetectionConfiguration(),
GetEmptyLayerDetectionConfiguration()
);
}

public IssuesDetectionConfiguration GetIssuesDetectionConfiguration(bool enable)
{
return new IssuesDetectionConfiguration(
GetIslandDetectionConfiguration(enable),
Expand Down
4 changes: 2 additions & 2 deletions UVtools.WPF/MainWindow.LayerPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,13 @@ public void GoLastLayer()
public void GoUpLayers(uint layers)
{
if (!IsFileLoaded) return;
ActualLayer = Math.Min(SlicerFile.LastLayerIndex, ActualLayer + layers);
ActualLayer = SlicerFile.SanitizeLayerIndex(ActualLayer + layers);
}

public void GoDownLayers(uint layers)
{
if (!IsFileLoaded) return;
ActualLayer = (uint)Math.Max(0, (int)ActualLayer - layers);
ActualLayer = SlicerFile.SanitizeLayerIndex((int)ActualLayer - (int)layers);
}

public void GoMassLayer(string which)
Expand Down
58 changes: 40 additions & 18 deletions UVtools.WPF/MainWindow.PixelEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,21 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)
WriteableBitmap bitmap = (WriteableBitmap)LayerImageBox.Image;
//var context = CreateRenderTarget().CreateDrawingContext(bitmap);


//Bitmap bmp = pbLayer.Image as Bitmap;
if (SelectedPixelOperationTabIndex == (byte)PixelOperation.PixelOperationType.Drawing)
{
uint minLayer = (uint) Math.Max(0, (int)_actualLayer - DrawingPixelDrawing.LayersBelow);
uint maxLayer = Math.Min(SlicerFile.LastLayerIndex, _actualLayer + DrawingPixelDrawing.LayersAbove);
var drawings = new List<PixelOperation>();
uint minLayer = SlicerFile.SanitizeLayerIndex((int)ActualLayer - (int)DrawingPixelDrawing.LayersBelow);
uint maxLayer = SlicerFile.SanitizeLayerIndex(ActualLayer + DrawingPixelDrawing.LayersAbove);
for (uint layerIndex = minLayer; layerIndex <= maxLayer; layerIndex++)
{
var operationDrawing = new PixelDrawing(layerIndex, realLocation, DrawingPixelDrawing.LineType,
DrawingPixelDrawing.BrushShape, DrawingPixelDrawing.RotationAngle, DrawingPixelDrawing.BrushSize, DrawingPixelDrawing.Thickness, DrawingPixelDrawing.RemovePixelBrightness, DrawingPixelDrawing.PixelBrightness, isAdd);

//if (PixelHistory.Contains(operation)) continue;
AddDrawing(operationDrawing);
//AddDrawing(operationDrawing);
drawings.Add(operationDrawing);

if (layerIndex == _actualLayer)
{
Expand Down Expand Up @@ -386,13 +388,18 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)
//RefreshLayerImage();
}
}

AddDrawings(drawings);
return;
}
else if (SelectedPixelOperationTabIndex == (byte)PixelOperation.PixelOperationType.Text)
{
if (string.IsNullOrEmpty(DrawingPixelText.Text) || DrawingPixelText.FontScale < 0.2) return;

uint minLayer = (uint) Math.Max(0, (int)ActualLayer - DrawingPixelText.LayersBelow);
uint maxLayer = Math.Min(SlicerFile.LastLayerIndex, ActualLayer + DrawingPixelText.LayersAbove);
var drawings = new List<PixelOperation>();
uint minLayer = SlicerFile.SanitizeLayerIndex((int)ActualLayer - (int)DrawingPixelText.LayersBelow);
uint maxLayer = SlicerFile.SanitizeLayerIndex(ActualLayer + DrawingPixelText.LayersAbove);

for (uint layerIndex = minLayer; layerIndex <= maxLayer; layerIndex++)
{
var operationText = new PixelText(layerIndex, realLocation, DrawingPixelText.LineType,
Expand All @@ -401,8 +408,9 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)

//if (PixelHistory.Contains(operation)) continue;
//PixelHistory.Add(operation);
AddDrawing(operationText);

//AddDrawing(operationText);
drawings.Add(operationText);

/*var color = isAdd
? Settings.PixelEditor.AddPixelColor : Settings.PixelEditor.RemovePixelColor;
Expand All @@ -415,20 +423,24 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)
}*/
}

AddDrawings(drawings);
ShowLayer();
return;
}
else if (SelectedPixelOperationTabIndex == (byte)PixelOperation.PixelOperationType.Eraser)
{
if (LayerCache.Image.GetByte(realLocation) < 10) return;
uint minLayer = (uint) Math.Max(0, (int)ActualLayer - DrawingPixelEraser.LayersBelow);
uint maxLayer = Math.Min(SlicerFile.LastLayerIndex, ActualLayer + DrawingPixelEraser.LayersAbove);

var drawings = new List<PixelOperation>();
uint minLayer = SlicerFile.SanitizeLayerIndex((int)ActualLayer - (int)DrawingPixelEraser.LayersBelow);
uint maxLayer = SlicerFile.SanitizeLayerIndex(ActualLayer + DrawingPixelEraser.LayersAbove);
for (uint layerIndex = minLayer; layerIndex <= maxLayer; layerIndex++)
{
var operationEraser = new PixelEraser(layerIndex, realLocation, DrawingPixelEraser.PixelBrightness);

//if (PixelHistory.Contains(operation)) continue;
AddDrawing(operationEraser);
//AddDrawing(operationEraser);
drawings.Add(operationEraser);

/*if (layerIndex == _actualLayer)
{
Expand All @@ -445,6 +457,7 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)
}*/
}

AddDrawings(drawings);
ShowLayer();
return;
}
Expand All @@ -461,6 +474,7 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)
CvInvoke.Circle(LayerCache.ImageBgr, location, operationSupport.TipDiameter / 2,
new MCvScalar(Settings.PixelEditor.SupportsColor.B, Settings.PixelEditor.SupportsColor.G, Settings.PixelEditor.SupportsColor.R), -1);
RefreshLayerImage();
return;
}
else if (SelectedPixelOperationTabIndex == (byte)PixelOperation.PixelOperationType.DrainHole)
{
Expand All @@ -473,6 +487,7 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)
CvInvoke.Circle(LayerCache.ImageBgr, location, operationDrainHole.Diameter / 2,
new MCvScalar(Settings.PixelEditor.DrainHoleColor.B, Settings.PixelEditor.DrainHoleColor.G, Settings.PixelEditor.DrainHoleColor.R), -1);
RefreshLayerImage();
return;
}
else
{
Expand All @@ -482,11 +497,18 @@ void DrawPixel(bool isAdd, Point location, KeyModifiers keyModifiers)

public void AddDrawing(PixelOperation operation)
{
operation.Index = (uint)Drawings.Count;
Drawings.Insert(0, operation);
for (int i = 0; i < Drawings.Count; i++)
}

public void AddDrawings(IEnumerable<PixelOperation> operations)
{
uint count = (uint)Drawings.Count;
foreach (var operation in operations)
{
Drawings[i].Index = (uint) (Drawings.Count - i);
operation.Index = count++;
}
Drawings.InsertRange(0, operations);
}

public async void DrawModifications(bool exitEditor)
Expand Down Expand Up @@ -534,31 +556,31 @@ public async void DrawModifications(bool exitEditor)
ShowProgressWindow("Drawing pixels");
Clipboard.Snapshot();

var task = await Task.Factory.StartNew(async () =>
var task = await Task.Run(() =>
{
try
{
SlicerFile.DrawModifications(Drawings, Progress);
return true;
return Task.FromResult(true);
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
await Dispatcher.UIThread.InvokeAsync(async () =>
Dispatcher.UIThread.InvokeAsync(async () =>
{
await this.MessageBoxError(ex.ToString(), "Drawing operation failed!");
});
}
return false;
return Task.FromResult(false);
});

IsGUIEnabled = true;

if (!task.Result)
if (!task)
{
Clipboard.RestoreSnapshot();
ShowLayer();
Expand Down
4 changes: 2 additions & 2 deletions UVtools.WPF/MainWindow.Suggestions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async void ApplySuggestionsClicked()
IsGUIEnabled = false;
ShowProgressWindow($"Applying {suggestions.Length} suggestions", false);

var executed = await Task.Factory.StartNew(() =>
var executed = await Task.Run(() =>
{
uint executed = 0;
Expand Down Expand Up @@ -141,7 +141,7 @@ public async void ApplySuggestionClicked(Suggestion suggestion)
IsGUIEnabled = false;
ShowProgressWindow(suggestion.Title, false);

var result = await Task.Factory.StartNew(() =>
var result = await Task.Run(() =>
{
try
{
Expand Down
Loading

0 comments on commit 1da6f52

Please sign in to comment.