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

Program.cs « UVtools.Cmd - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1224f738337f011d7ef8d572b2405076ff52297 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using UVtools.Core;

namespace UVtools.Cmd
{
    class Program
    {
        public static async Task<int> Main(params string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
            Stopwatch sw = new Stopwatch();
            uint count = 0;
            var rootCommand = new RootCommand("MSLA/DLP, file analysis, repair, conversion and manipulation")
            {
                new Option(new []{"-f", "--file"}, "Input file to read")
                {
                    Required = true,
                    Argument = new Argument<FileSystemInfo>("filepath").ExistingOnly()
                },
                new Option(new []{"-o", "--output"}, "Output file to save the modifications, if aware, it saves to the same input file")
                {
                    Argument = new Argument<FileSystemInfo>("filepath")
                },
                new Option(new []{"-e", "--extract"}, "Extract file content to a folder")
                {
                    Argument = new Argument<DirectoryInfo>("folder")
                },
                new Option(new []{"-c", "--convert"}, "Converts input into a output file format by it extension")
                {
                    Argument = new Argument<FileSystemInfo>("filepath")
                },

                new Option(new []{"-p", "--properties"}, "Print a list of all properties/settings"),
                new Option(new []{"-gcode"}, "Print the GCode if available"),
                new Option(new []{"-i", "--issues"}, "Compute and print a list of all issues"),
                new Option(new []{"-r", "--repair"}, "Attempt to repair all issues"){
                    Argument = new Argument<int[]>("[start layer index] [end layer index]")
                },

                new Option(new []{"-mr", "--mut-resize"}, "Resizes layer images in a X and/or Y factor, starting from 100% value")
                {
                    Argument = new Argument<double[]>("[x%] [y%] [start layer index] [end layer index] [fade 0/1]")
                },
                new Option(new []{"-ms", "--mut-solidify"}, "Closes all inner holes")
                {
                    Argument = new Argument<uint[]>("[start layer index] [end layer index]")
                },
                new Option(new []{"-me", "--mut-erode"}, "Erodes away the boundaries of foreground object")
                {
                    Argument = new Argument<uint[]>("[start iterations] [end iterations] [start layer index] [end layer index] [fade 0/1]")
                },
                new Option(new []{"-md", "--mut-dilate"}, "It is just opposite of erosion")
                {
                    Argument = new Argument<uint[]>("[start iterations] [end iterations] [start layer index] [end layer index] [fade 0/1]")
                },
                new Option(new []{"-mc", "--mut-close"}, "Dilation followed by Erosion")
                {
                    Argument = new Argument<uint[]>("[start iterations] [end iterations] [start layer index] [end layer index] [fade 0/1]")
                },
                new Option(new []{"-mo", "--mut-open"}, "Erosion followed by Dilation")
                {
                    Argument = new Argument<uint[]>("[start iterations] [end iterations] [start layer index] [end layer index] [fade 0/1]")
                },
                new Option(new []{"-mg", "--mut-gradient"}, "The difference between dilation and erosion of an image")
                {
                    Argument = new Argument<uint[]>("[kernel size] [start layer index] [end layer index] [fade 0/1]")
                },
                
                new Option(new []{"-mpy", "--mut-py"}, "Performs downsampling step of Gaussian pyramid decomposition")
                {
                    Argument = new Argument<uint[]>("[start layer index] [end layer index]")
                },
                new Option(new []{"-mgb", "--mut-gaussian-blur"}, "Each pixel is a sum of fractions of each pixel in its neighborhood")
                {
                    Argument = new Argument<ushort[]>("[aperture] [sigmaX] [sigmaY]")
                },
                new Option(new []{"-mmb", "--mut-median-blur"}, "Each pixel becomes the median of its surrounding pixels")
                {
                    Argument = new Argument<ushort>("[aperture]")
                },
            };

            rootCommand.Handler = CommandHandler.Create(
                (
                    FileSystemInfo file,
                    FileSystemInfo convert,
                    DirectoryInfo extract,
                    bool properties,
                    bool gcode,
                    bool issues,
                    bool repair
                    ) =>
            {
                var fileFormat = FileFormat.FindByExtension(file.FullName, true, true);
                if (ReferenceEquals(fileFormat, null))
                {
                    Console.WriteLine($"Error: {file.FullName} is not a known nor valid format.");
                }
                else
                {
                    Console.Write($"Reading: {file}");
                    sw.Restart();
                    fileFormat.Decode(file.FullName);
                    sw.Stop();
                    Console.WriteLine($", in {sw.ElapsedMilliseconds}ms");
                    Console.WriteLine("----------------------");
                    Console.WriteLine($"Layers: {fileFormat.LayerCount} x {fileFormat.LayerHeight}mm = {fileFormat.TotalHeight}mm");
                    Console.WriteLine($"Resolution: {new Size((int) fileFormat.ResolutionX, (int) fileFormat.ResolutionY)}");
                    Console.WriteLine($"AntiAlias: {fileFormat.ValidateAntiAliasingLevel()}");
                    
                    Console.WriteLine($"Bottom Layer Count: {fileFormat.InitialLayerCount}");
                    Console.WriteLine($"Bottom Exposure Time: {fileFormat.InitialExposureTime}s");
                    Console.WriteLine($"Layer Exposure Time: {fileFormat.LayerExposureTime}s");
                    Console.WriteLine($"Print Time: {fileFormat.PrintTime}s");
                    Console.WriteLine($"Cost: {fileFormat.MaterialCost}$");
                    Console.WriteLine($"Resin Name: {fileFormat.MaterialName}");
                    Console.WriteLine($"Machine Name: {fileFormat.MachineName}");

                    Console.WriteLine($"Thumbnails: {fileFormat.CreatedThumbnailsCount}");
                    Console.WriteLine("----------------------");
                }

                if (!ReferenceEquals(extract, null))
                {
                    Console.Write($"Extracting to {extract.FullName}");
                    sw.Restart();
                    fileFormat.Extract(extract.FullName);
                    sw.Stop();
                    Console.WriteLine($", finished in {sw.ElapsedMilliseconds}ms");
                }

                if (properties)
                {
                    count = 0;
                    Console.WriteLine("Listing all properties:");
                    Console.WriteLine("----------------------");
                    foreach (var config in fileFormat.Configs)
                    {
                        Console.WriteLine("******************************");
                        Console.WriteLine($"\t{config.GetType().Name}");
                        Console.WriteLine("******************************");
                        foreach (PropertyInfo propertyInfo in config.GetType()
                            .GetProperties(BindingFlags.Public | BindingFlags.Instance))
                        {
                            count++;
                            if (propertyInfo.Name.Equals("Item")) continue;
                            Console.WriteLine($"{propertyInfo.Name}: {propertyInfo.GetValue(config)}");
                        }
                    }

                    Console.WriteLine("----------------------");
                    Console.WriteLine($"Total properties: {count}");
                }

                if (gcode)
                {
                    if (ReferenceEquals(fileFormat.GCode, null))
                    {
                        Console.WriteLine("No GCode available");
                    }
                    else
                    {
                        Console.WriteLine("----------------------");
                        Console.WriteLine(fileFormat.GCode);
                        Console.WriteLine("----------------------");
                        Console.WriteLine($"Total lines: {fileFormat.GCode.Length}");
                    }
                    
                }

                if (issues)
                {
                    Console.WriteLine("Computing Issues, please wait.");
                    sw.Restart();
                    var issuesDict = fileFormat.LayerManager.GetAllIssues();
                    sw.Stop();
                    
                    Console.WriteLine("Issues:");
                    Console.WriteLine("----------------------");
                    count = 0;
                    for (uint layerIndex = 0; layerIndex < fileFormat.LayerCount; layerIndex++)
                    {
                        if(!issuesDict.TryGetValue(layerIndex, out var list)) continue;
                        foreach (var issue in list)
                        {
                            Console.WriteLine(issue);
                            count++;
                        }
                    }

                    Console.WriteLine("----------------------");
                    Console.WriteLine($"Total Issues: {count} in {sw.ElapsedMilliseconds}ms");
                }

                if (!ReferenceEquals(convert, null))
                {
                    var fileConvert = FileFormat.FindByExtension(convert.FullName, true, true);
                    if (ReferenceEquals(fileFormat, null))
                    {
                        Console.WriteLine($"Error: {convert.FullName} is not a known nor valid format.");
                    }
                    else
                    {
                        Console.WriteLine($"Converting {fileFormat.GetType().Name} to {fileConvert.GetType().Name}: {convert.Name}");

                        try
                        {
                            sw.Restart();
                            fileFormat.Convert(fileConvert, convert.FullName);
                            sw.Stop();
                            Console.WriteLine($"Convertion done in {sw.ElapsedMilliseconds}ms");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        
                    }
                    
                }

                
            });


            await rootCommand.InvokeAsync(args);
            //await rootCommand.InvokeAsync("-f body_Tough0.1mm_SL1_5h16m_HOLLOW_DRAIN.sl1 -i");

            return 1;

        }
    }
}