Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OperationLayerReHeight.cs « Operations « UVtools.Core - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 32bf0bc56ba8193994696761527c68df1994d96c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 *                     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.Globalization;
using System.Text;
using UVtools.Core.Objects;

namespace UVtools.Core.Operations
{
    [Serializable]
    public sealed class OperationLayerReHeight : Operation
    {
        private OperationLayerReHeightItem _item;

        #region Overrides

        public override Enumerations.LayerRangeSelection StartLayerRangeSelection => Enumerations.LayerRangeSelection.None;
        public override bool CanROI => false;
        public override string Title => "Adjust layer height";
        public override string Description =>
            "Adjust the layer height of the model\n\n" +
            "Adjusting to values lower than current height will reduce layer lines, adjusting to values higher" +
            " than current height will reduce model detail.\n\n" +
            "Note: Using dedicated slicer software to re-slice will usually yeild better results.";
        public override string ConfirmationText =>
            $"adjust layer height to {Item.LayerHeight}mm?";

        public override string ProgressTitle =>
            $"Adjusting layer height to {Item.LayerHeight}mm";

        public override string ProgressAction => "Height adjusted layers";

        public override bool CanCancel => false;

        public override bool CanHaveProfiles => false;

        public override StringTag Validate(params object[] parameters)
        {
            var sb = new StringBuilder();

            if (Item is null)
            {
                sb.AppendLine("No valid configurations, unable to proceed.");
            }


            return new StringTag(sb.ToString());
        }

        #endregion

        public OperationLayerReHeightItem Item
        {
            get => _item;
            set => RaiseAndSetIfChanged(ref _item, value);
        }


        public static OperationLayerReHeightItem[] GetItems(uint layerCount, decimal layerHeight)
        {
            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";
            }
        }
    }
}