Convert layer reheight to toolwindow

This commit is contained in:
Tiago Conceição
2020-09-09 01:26:02 +01:00
parent a1348c0a41
commit 5efca8cadd
15 changed files with 397 additions and 2576 deletions
+8 -8
View File
@@ -1565,24 +1565,24 @@ namespace UVtools.Core
public void ReHeight(OperationLayerReHeight operation, OperationProgress progress = null)
{
if (ReferenceEquals(progress, null)) progress = new OperationProgress();
progress.Reset("Re-Height", operation.LayerCount);
progress.Reset($"Layer re-height from {SlicerFile.LayerHeight}mm to {operation.Item.LayerHeight}mm");
var oldLayers = Layers;
Layers = new Layer[operation.LayerCount];
Layers = new Layer[operation.Item.LayerCount];
uint newLayerIndex = 0;
for (uint layerIndex = 0; layerIndex < oldLayers.Length; layerIndex++)
{
var oldLayer = oldLayers[layerIndex];
if (operation.IsDivision)
if (operation.Item.IsDivision)
{
for (byte i = 0; i < operation.Modifier; i++)
for (byte i = 0; i < operation.Item.Modifier; i++)
{
Layers[newLayerIndex] =
new Layer(newLayerIndex, oldLayer.CompressedBytes, null, this)
{
PositionZ = (float)(operation.LayerHeight * (newLayerIndex + 1)),
PositionZ = (float)(operation.Item.LayerHeight * (newLayerIndex + 1)),
ExposureTime = oldLayer.ExposureTime,
BoundingRectangle = oldLayer.BoundingRectangle,
NonZeroPixelCount = oldLayer.NonZeroPixelCount
@@ -1596,7 +1596,7 @@ namespace UVtools.Core
{
using (var mat = oldLayers[layerIndex++].LayerMat)
{
for (byte i = 1; i < operation.Modifier; i++)
for (byte i = 1; i < operation.Item.Modifier; i++)
{
using (var nextMat = oldLayers[layerIndex++].LayerMat)
{
@@ -1606,7 +1606,7 @@ namespace UVtools.Core
Layers[newLayerIndex] = new Layer(newLayerIndex, mat, null, this)
{
PositionZ = (float)(operation.LayerHeight * (newLayerIndex + 1)),
PositionZ = (float)(operation.Item.LayerHeight * (newLayerIndex + 1)),
ExposureTime = oldLayer.ExposureTime
};
newLayerIndex++;
@@ -1617,7 +1617,7 @@ namespace UVtools.Core
}
SlicerFile.LayerHeight = (float)operation.LayerHeight;
SlicerFile.LayerHeight = (float)operation.Item.LayerHeight;
SlicerFile.LayerCount = Count;
BoundingRectangle = Rectangle.Empty;
SlicerFile.RequireFullEncode = true;
@@ -5,27 +5,104 @@
* 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.Globalization;
using System.Text;
using UVtools.Core.Objects;
namespace UVtools.Core.Operations
{
public sealed class OperationLayerReHeight
public sealed class OperationLayerReHeight : Operation
{
public bool IsMultiply { get; }
public bool IsDivision => !IsMultiply;
public byte Modifier { get; }
public decimal LayerHeight { get; }
public uint LayerCount { get; }
#region Overrides
public OperationLayerReHeight(bool isMultiply, byte modifier, decimal layerHeight, uint layerCount)
public override string Title => "Layer re-height";
public override string Description =>
"Changes layer height.\n" +
"Going lower doesn't give you better XYZ accuracy but will reduce Z lines, layers will be cloned and repeated over Z for the effect.\n" +
"Going higher will reduce detail, layers will sum times the modifier for the effect.\n" +
"Note: Reslice with the new layer height is always preferable";
public override string ConfirmationText =>
$"re-height layers to {Item.LayerHeight}mm?";
public override string ProgressTitle =>
$"Re-height layers to {Item.LayerHeight}mm";
public override StringTag Validate(params object[] parameters)
{
IsMultiply = isMultiply;
Modifier = modifier;
LayerHeight = layerHeight;
LayerCount = layerCount;
var sb = new StringBuilder();
if (Item is null)
{
sb.AppendLine("No valid configurations to proceed");
}
return new StringTag(sb.ToString());
}
public override string ToString()
#endregion
public OperationLayerReHeightItem Item { get; set; }
public static OperationLayerReHeightItem[] GetItems(uint layerCount, decimal layerHeight)
{
return (IsMultiply ? 'x' : '÷') +$" {Modifier} → {LayerCount} layers at {LayerHeight}mm";
List<OperationLayerReHeightItem> list = new List<OperationLayerReHeightItem>();
for (byte i = 2; i < 255; i++) // Lower
{
if (layerHeight / i < 0.01m) break;
var countStr = (layerCount / (decimal)i).ToString(CultureInfo.InvariantCulture);
if (countStr.IndexOf(".", StringComparison.Ordinal) >= 0) continue; // Cant multiply layers
countStr = (layerHeight / i).ToString(CultureInfo.InvariantCulture);
int decimalCount = countStr.Substring(countStr.IndexOf(".", StringComparison.Ordinal)).Length - 1;
if (decimalCount > 2) continue; // Cant multiply height
var item = new OperationLayerReHeightItem(false, i, layerHeight / i, layerCount * i);
list.Add(item);
}
for (byte i = 2; i < 255; i++) // Higher
{
if (layerHeight * i > 0.2m) break;
var countStr = (layerCount / (decimal)i).ToString(CultureInfo.InvariantCulture);
if (countStr.IndexOf(".", StringComparison.Ordinal) >= 0) continue; // Cant multiply layers
countStr = (layerHeight * i).ToString(CultureInfo.InvariantCulture);
int decimalCount = countStr.Substring(countStr.IndexOf(".", StringComparison.Ordinal)).Length - 1;
if (decimalCount > 2) continue; // Cant multiply height
var item = new OperationLayerReHeightItem(true, i, layerHeight * i, layerCount / i);
list.Add(item);
}
return list.ToArray();
}
public class OperationLayerReHeightItem
{
public bool IsMultiply { get; }
public bool IsDivision => !IsMultiply;
public byte Modifier { get; }
public decimal LayerHeight { get; }
public uint LayerCount { get; }
public OperationLayerReHeightItem(bool isMultiply, byte modifier, decimal layerHeight, uint layerCount)
{
IsMultiply = isMultiply;
Modifier = modifier;
LayerHeight = layerHeight;
LayerCount = layerCount;
}
public override string ToString()
{
return (IsMultiply ? 'x' : '÷') + $" {Modifier} → {LayerCount} layers at {LayerHeight}mm";
}
}
}
}
@@ -79,6 +79,8 @@ namespace UVtools.GUI.Controls
[ReadOnly(true)] [Browsable(false)] public FrmToolWindow ParentToolWindow => ParentForm as FrmToolWindow;
[SettingsBindable(true)] public bool CanRun { get; set; } = true;
[Editor("System.ComponentModel.Design.MultilineStringEditor", typeof(UITypeEditor))]
[SettingsBindable(true)]
public string Description { get; set; }
@@ -189,8 +191,8 @@ namespace UVtools.GUI.Controls
return false;
}
public DialogResult MessageBoxError(string message, MessageBoxButtons buttons = MessageBoxButtons.OK) => GUIExtensions.MessageErrorBox($"{Text} Error", message, buttons);
public DialogResult MessageQuestionBox(string message, string title = null, MessageBoxButtons buttons = MessageBoxButtons.YesNo) => GUIExtensions.MessageQuestionBox($"{title ?? Text}", message, buttons);
public DialogResult MessageBoxError(string message, MessageBoxButtons buttons = MessageBoxButtons.OK) => GUIExtensions.MessageBoxError($"{Text} Error", message, buttons);
public DialogResult MessageQuestionBox(string message, string title = null, MessageBoxButtons buttons = MessageBoxButtons.YesNo) => GUIExtensions.MessageBoxQuestion($"{title ?? Text}", message, buttons);
#endregion
@@ -0,0 +1,89 @@
namespace UVtools.GUI.Controls.Tools
{
partial class CtrlToolLayerReHeight
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cbMultiplier = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.lbCurrent = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// cbMultiplier
//
this.cbMultiplier.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbMultiplier.FormattingEnabled = true;
this.cbMultiplier.Location = new System.Drawing.Point(78, 37);
this.cbMultiplier.Name = "cbMultiplier";
this.cbMultiplier.Size = new System.Drawing.Size(459, 28);
this.cbMultiplier.TabIndex = 12;
this.cbMultiplier.SelectedIndexChanged += new System.EventHandler(this.EventValueChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(3, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(69, 20);
this.label2.TabIndex = 11;
this.label2.Text = "Modifier:";
//
// lbCurrent
//
this.lbCurrent.AutoSize = true;
this.lbCurrent.Location = new System.Drawing.Point(3, 9);
this.lbCurrent.Name = "lbCurrent";
this.lbCurrent.Size = new System.Drawing.Size(284, 20);
this.lbCurrent.TabIndex = 10;
this.lbCurrent.Text = "Current layers: (No valid configurations)";
//
// CtrlToolLayerReHeight
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ButtonOkEnabled = false;
this.Controls.Add(this.cbMultiplier);
this.Controls.Add(this.label2);
this.Controls.Add(this.lbCurrent);
this.Description = "";
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.LayerRangeVisible = false;
this.Name = "CtrlToolLayerReHeight";
this.Size = new System.Drawing.Size(540, 94);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ComboBox cbMultiplier;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label lbCurrent;
}
}
@@ -0,0 +1,55 @@
/*
* 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.Windows.Forms;
using UVtools.Core.Extensions;
using UVtools.Core.Operations;
namespace UVtools.GUI.Controls.Tools
{
public partial class CtrlToolLayerReHeight : CtrlToolWindowContent
{
public OperationLayerReHeight Operation { get; }
public CtrlToolLayerReHeight()
{
InitializeComponent();
Operation = new OperationLayerReHeight();
SetOperation(Operation);
lbCurrent.Text = $"Current layers: {Program.SlicerFile.LayerCount} at {Program.SlicerFile.LayerHeight}mm";
var items = OperationLayerReHeight.GetItems(Program.SlicerFile.LayerCount,
(decimal) Program.SlicerFile.LayerHeight);
if (items.Length > 0)
{
cbMultiplier.Items.AddRange(items);
cbMultiplier.SelectedIndex = 0;
}
else
{
GUIExtensions.MessageBoxInformation("Not possible to re-height", "No valid configuration to be able to re-height, closing this tool now.");
CanRun = false;
}
}
private void EventValueChanged(object sender, EventArgs e)
{
ButtonOkEnabled = cbMultiplier.SelectedIndex >= 0;
}
public override void UpdateOperation()
{
base.UpdateOperation();
Operation.Item = (OperationLayerReHeight.OperationLayerReHeightItem)cbMultiplier.SelectedItem;
}
}
}
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
+5 -2
View File
@@ -12,10 +12,13 @@ namespace UVtools.Core.Extensions
{
public static class GUIExtensions
{
public static DialogResult MessageErrorBox(string title, string message, MessageBoxButtons buttons = MessageBoxButtons.OK) =>
public static DialogResult MessageBoxError(string title, string message, MessageBoxButtons buttons = MessageBoxButtons.OK) =>
MessageBox.Show(message, title, buttons, MessageBoxIcon.Error);
public static DialogResult MessageQuestionBox(string title, string message, MessageBoxButtons buttons = MessageBoxButtons.YesNo) =>
public static DialogResult MessageBoxQuestion(string title, string message, MessageBoxButtons buttons = MessageBoxButtons.YesNo) =>
MessageBox.Show(message, title, buttons, MessageBoxIcon.Question);
public static DialogResult MessageBoxInformation(string title, string message, MessageBoxButtons buttons = MessageBoxButtons.OK) =>
MessageBox.Show(message, title, buttons, MessageBoxIcon.Information);
}
}
-147
View File
@@ -1,147 +0,0 @@
namespace UVtools.GUI.Forms
{
partial class FrmToolLayerReHeight
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmToolLayerReHeight));
this.lbDescription = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.lbCurrent = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.cbMultiplier = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// lbDescription
//
this.lbDescription.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbDescription.Location = new System.Drawing.Point(13, 14);
this.lbDescription.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.lbDescription.Name = "lbDescription";
this.lbDescription.Size = new System.Drawing.Size(584, 118);
this.lbDescription.TabIndex = 0;
this.lbDescription.Text = resources.GetString("lbDescription.Text");
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Image = global::UVtools.GUI.Properties.Resources.Cancel_24x24;
this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnCancel.Location = new System.Drawing.Point(434, 202);
this.btnCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(150, 48);
this.btnCancel.TabIndex = 6;
this.btnCancel.Text = "&Cancel";
this.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.EventClick);
//
// btnOk
//
this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnOk.Image = global::UVtools.GUI.Properties.Resources.Ok_24x24;
this.btnOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnOk.Location = new System.Drawing.Point(276, 202);
this.btnOk.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(150, 48);
this.btnOk.TabIndex = 5;
this.btnOk.Text = "Re-Height";
this.btnOk.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.EventClick);
//
// lbCurrent
//
this.lbCurrent.AutoSize = true;
this.lbCurrent.Location = new System.Drawing.Point(13, 132);
this.lbCurrent.Name = "lbCurrent";
this.lbCurrent.Size = new System.Drawing.Size(234, 20);
this.lbCurrent.TabIndex = 7;
this.lbCurrent.Text = "Current layers: xxxxxxxxxxxxxxxxx";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(13, 159);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(69, 20);
this.label2.TabIndex = 8;
this.label2.Text = "Modifier:";
//
// cbMultiplier
//
this.cbMultiplier.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbMultiplier.FormattingEnabled = true;
this.cbMultiplier.Location = new System.Drawing.Point(126, 155);
this.cbMultiplier.Name = "cbMultiplier";
this.cbMultiplier.Size = new System.Drawing.Size(458, 28);
this.cbMultiplier.TabIndex = 9;
//
// FrmToolLayerReHeight
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(599, 264);
this.Controls.Add(this.cbMultiplier);
this.Controls.Add(this.label2);
this.Controls.Add(this.lbCurrent);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.lbDescription);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FrmToolLayerReHeight";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Layer Re-Height";
this.TopMost = true;
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lbDescription;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Label lbCurrent;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox cbMultiplier;
}
}
-123
View File
@@ -1,123 +0,0 @@
/*
* 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.Globalization;
using System.Windows.Forms;
using UVtools.Core.Operations;
namespace UVtools.GUI.Forms
{
public partial class FrmToolLayerReHeight : Form
{
private uint LayerCount { get; }
private decimal LayerHeight { get; }
public OperationLayerReHeight Operation => cbMultiplier.SelectedItem as OperationLayerReHeight;
#region Constructors
public FrmToolLayerReHeight(uint layerCount, float layerHeight)
{
InitializeComponent();
DialogResult = DialogResult.Cancel;
LayerCount = layerCount;
LayerHeight = (decimal) layerHeight;
lbCurrent.Text = $"Current layers: {LayerCount} at {layerHeight}mm";
for (byte i = 2; i < 255; i++) // Lower
{
if (LayerHeight / i < 0.01m) break;
var countStr = (LayerCount / (decimal)i).ToString(CultureInfo.InvariantCulture);
if (countStr.IndexOf(".", StringComparison.Ordinal) >= 0) continue; // Cant multiply layers
countStr = (LayerHeight / i).ToString(CultureInfo.InvariantCulture);
int decimalCount = countStr.Substring(countStr.IndexOf(".", StringComparison.Ordinal)).Length-1;
if (decimalCount > 2) continue; // Cant multiply height
OperationLayerReHeight operation = new OperationLayerReHeight(false, i, LayerHeight / i, LayerCount * i);
cbMultiplier.Items.Add(operation);
}
for (byte i = 2; i < 255; i++) // Higher
{
if (LayerHeight * i > 0.2m) break;
var countStr = (LayerCount / (decimal)i).ToString(CultureInfo.InvariantCulture);
if (countStr.IndexOf(".", StringComparison.Ordinal) >= 0) continue; // Cant multiply layers
countStr = (LayerHeight * i).ToString(CultureInfo.InvariantCulture);
int decimalCount = countStr.Substring(countStr.IndexOf(".", StringComparison.Ordinal)).Length-1;
if (decimalCount > 2) continue; // Cant multiply height
OperationLayerReHeight operation = new OperationLayerReHeight(true, i, LayerHeight * i, LayerCount / i);
cbMultiplier.Items.Add(operation);
}
if (cbMultiplier.Items.Count == 0)
{
MessageBox.Show("No valid configuration to be able to re-height, closing this tool now.", "Not possible to re-height", MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
}
else
{
cbMultiplier.SelectedIndex = 0;
}
}
#endregion
#region Overrides
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
if (e.KeyCode == Keys.Enter)
{
btnOk.PerformClick();
e.Handled = true;
return;
}
}
#endregion
#region Events
private void EventClick(object sender, EventArgs e)
{
if (ReferenceEquals(sender, btnOk))
{
if (!btnOk.Enabled) return;
if (MessageBox.Show($"Are you sure you want change layer height?", Text, MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
DialogResult = DialogResult.OK;
Close();
}
return;
}
if (ReferenceEquals(sender, btnCancel))
{
DialogResult = DialogResult.Cancel;
return;
}
}
#endregion
#region Methods
#endregion
}
}
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -327,8 +327,8 @@ namespace UVtools.GUI.Forms
public virtual bool ValidateForm() => true;
public DialogResult MessageErrorBox(string message) => GUIExtensions.MessageErrorBox($"{Text} Error", message);
public DialogResult MessageQuestionBox(string message, string title = null) => GUIExtensions.MessageQuestionBox($"{title ?? Text}", message);
public DialogResult MessageErrorBox(string message) => GUIExtensions.MessageBoxError($"{Text} Error", message);
public DialogResult MessageQuestionBox(string message, string title = null) => GUIExtensions.MessageBoxQuestion($"{title ?? Text}", message);
public T GetContentCtrl<T>()
{
-12
View File
@@ -51,7 +51,6 @@ namespace UVtools.GUI
this.menuMutate = new System.Windows.Forms.ToolStripMenuItem();
this.menuTools = new System.Windows.Forms.ToolStripMenuItem();
this.menuToolsRepairLayers = new System.Windows.Forms.ToolStripMenuItem();
this.menuToolsLayerReHeight = new System.Windows.Forms.ToolStripMenuItem();
this.menuToolsPattern = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuHelpWebsite = new System.Windows.Forms.ToolStripMenuItem();
@@ -485,7 +484,6 @@ namespace UVtools.GUI
//
this.menuTools.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuToolsRepairLayers,
this.menuToolsLayerReHeight,
this.menuToolsPattern});
this.menuTools.Enabled = false;
this.menuTools.Name = "menuTools";
@@ -503,15 +501,6 @@ namespace UVtools.GUI
this.menuToolsRepairLayers.Text = "&Repair layers and Issues";
this.menuToolsRepairLayers.Click += new System.EventHandler(this.EventClick);
//
// menuToolsLayerReHeight
//
this.menuToolsLayerReHeight.Enabled = false;
this.menuToolsLayerReHeight.Image = global::UVtools.GUI.Properties.Resources.ladder_16x16;
this.menuToolsLayerReHeight.Name = "menuToolsLayerReHeight";
this.menuToolsLayerReHeight.Size = new System.Drawing.Size(261, 22);
this.menuToolsLayerReHeight.Text = "Layer Re-&Height";
this.menuToolsLayerReHeight.Click += new System.EventHandler(this.EventClick);
//
// menuToolsPattern
//
this.menuToolsPattern.Enabled = false;
@@ -3105,7 +3094,6 @@ namespace UVtools.GUI
private System.Windows.Forms.ToolStripButton tsThumbnailsImport;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator21;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator22;
private System.Windows.Forms.ToolStripMenuItem menuToolsLayerReHeight;
private System.Windows.Forms.ToolStripSplitButton tsPropertiesExport;
private System.Windows.Forms.ToolStripMenuItem tsPropertiesExportFile;
private System.Windows.Forms.ToolStripMenuItem tsPropertiesExportClipboard;
+11 -50
View File
@@ -47,6 +47,7 @@ namespace UVtools.GUI
public static readonly OperationMenuItem[] MenuTools = {
new OperationMenuItem(new OperationSolidify(), Resources.square_solid_16x16),
new OperationMenuItem(new OperationMorphModel(), Resources.Geometry_16x16),
new OperationMenuItem(new OperationLayerReHeight(), Resources.ladder_16x16),
new OperationMenuItem(new OperationChangeResolution(), Resources.resize_16x16)
};
@@ -988,55 +989,6 @@ namespace UVtools.GUI
return;
}
if (ReferenceEquals(menuItem, menuToolsLayerReHeight))
{
OperationLayerReHeight operation = null;
using (var frm = new FrmToolLayerReHeight(SlicerFile.LayerCount, SlicerFile.LayerHeight))
{
if (frm.IsDisposed || frm.ShowDialog() != DialogResult.OK) return;
operation = frm.Operation;
}
DisableGUI();
FrmLoading.SetDescription(
$"Layer Re-Height from {SlicerFile.LayerHeight}mm to {operation.LayerHeight}mm");
var task = Task.Factory.StartNew(() =>
{
try
{
SlicerFile.LayerManager.ReHeight(operation, FrmLoading.RestartProgress());
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Invoke((MethodInvoker) delegate
{
// Running on the UI thread
EnableGUI(true);
});
}
});
var loadingResult = FrmLoading.ShowDialog();
UpdateLayerLimits();
RefreshInfo();
ShowLayer();
menuFileSave.Enabled =
menuFileSaveAs.Enabled = true;
return;
}
if (ReferenceEquals(menuItem, menuToolsPattern))
{
OperationPattern operation = new OperationPattern(SlicerFile.LayerManager.BoundingRectangle,
@@ -4612,6 +4564,12 @@ namespace UVtools.GUI
control = controlType.CreateInstance<CtrlToolWindowContent>();
if (control is null) return null;
}
if (!control.CanRun)
{
control.Dispose();
return null;
}
if (removeContent)
{
@@ -4650,6 +4608,9 @@ namespace UVtools.GUI
case OperationMorphModel operation:
SlicerFile.LayerManager.Morph(operation, BorderType.Default, new MCvScalar(), FrmLoading.RestartProgress());
break;
case OperationLayerReHeight operation:
SlicerFile.LayerManager.ReHeight(operation, FrmLoading.RestartProgress());
break;
case OperationChangeResolution operation:
SlicerFile.LayerManager.ChangeResolution(operation, FrmLoading.RestartProgress(false));
break;
@@ -4673,7 +4634,7 @@ namespace UVtools.GUI
}
catch (Exception ex)
{
GUIExtensions.MessageErrorBox($"{baseOperation.Title} Error", ex.Message);
GUIExtensions.MessageBoxError($"{baseOperation.Title} Error", ex.Message);
}
finally
{
+1 -1
View File
@@ -158,7 +158,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABk
FAAAAk1TRnQBSQFMAgEBBgEAAWABCgFgAQoBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
FAAAAk1TRnQBSQFMAgEBBgEAAWgBCgFoAQoBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA
AwABIAMAAQEBAAEgBgABIC4AAxgBIgMwAUsDMAFMAzIBUDMAAQEDJAE2AysBQqwAAyIBMQNWAbkDXQHi
AwAB/wMAAf8BKgEtASgB/gNTAawDTQGVAwABARgAAwkBDAMzAVIDUAGdA1cB6AMAAf4DKwH8Ay8BSqQA
AyEBMANZAewBKwEuASkB+gNRAfcDUgH0A1MB8QNIAfYDQQH5AwAB/wNPAZsDAAEBCAADFQEdAz8BbgNV
+9 -9
View File
@@ -170,6 +170,12 @@
<Compile Include="Controls\SplitButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\Tools\CtrlToolLayerReHeight.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\Tools\CtrlToolLayerReHeight.Designer.cs">
<DependentUpon>CtrlToolLayerReHeight.cs</DependentUpon>
</Compile>
<Compile Include="Controls\Tools\CtrlToolMorphModel.cs">
<SubType>UserControl</SubType>
</Compile>
@@ -247,12 +253,6 @@
<Compile Include="Forms\FrmToolWindow.Designer.cs">
<DependentUpon>FrmToolWindow.cs</DependentUpon>
</Compile>
<Compile Include="Forms\FrmToolLayerReHeight.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\FrmToolLayerReHeight.Designer.cs">
<DependentUpon>FrmToolLayerReHeight.cs</DependentUpon>
</Compile>
<Compile Include="Forms\FrmToolPattern.cs">
<SubType>Form</SubType>
</Compile>
@@ -336,6 +336,9 @@
<EmbeddedResource Include="Controls\CtrlToolWindowContent.resx">
<DependentUpon>CtrlToolWindowContent.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\Tools\CtrlToolLayerReHeight.resx">
<DependentUpon>CtrlToolLayerReHeight.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\Tools\CtrlToolMorphModel.resx">
<DependentUpon>CtrlToolMorphModel.cs</DependentUpon>
</EmbeddedResource>
@@ -375,9 +378,6 @@
<EmbeddedResource Include="Forms\FrmToolWindow.resx">
<DependentUpon>FrmToolWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\FrmToolLayerReHeight.resx">
<DependentUpon>FrmToolLayerReHeight.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\FrmToolPattern.resx">
<DependentUpon>FrmToolPattern.cs</DependentUpon>
</EmbeddedResource>