mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-08 17:42:31 +02:00
c800f887d2
- **Core:** - (Add) Getter `FileFormat.DisplayPixelCount` Gets the display total number of pixels (ResolutionX * ResolutionY) - (Add) Getter `Layer.NonZeroPixelRatio` Gets the ratio between non zero pixels and display number of pixels - (Add) Getter `Layer.NonZeroPixelPercentage` Gets the percentage of non zero pixels relative to the display number of pixels - (Add) Getter `Layer.PreviousHeightLayer()` Gets the previous layer with a different height from the current, returns null if no previous layer - (Add) Getter `Layer.NextHeightLayer()` Gets the next layer with a different height from the current, returns null if no next layer - (Add) Method `Layer.GetPreviousLayerWithAtLeastPixelCountOf()` Gets the previous layer matching at least a number of pixels, returns null if no previous layer - (Add) Method `Layer.GetNextLayerWithAtLeastPixelCountOf()` Gets the next layer matching at least a number of pixels, returns null if no next layer - (Add) Method `Operation.GetRoiOrVolumeBounds()` returns the selected ROI rectangle or model volume bounds rectangle - (Add) Documentation around `Operation` methods - (Fix) Open files in partial mode when the resolution is not defined would cause a `NullPointerException` (#474) - **Suggestion: Wait time before cure** - (Add) Proportional maximum time change: Sets the maximum allowed time difference relative to the previous layer (#471) - (Add) Proportional mass get modes: Previous, Average and Maximum relative to a defined height (#471) - (Change) Proportional set type sets fallback time to the first layer - (Fix) Proportional set type was taking current layer mass instead of looking to the previous cured layer (#471) - **Tools:** - **Edit print parameters:** - (Change) Incorporate the unit label into the numeric input box - (Change) Allow TSMC speeds to be 0 as minimum value (#472) - (Fix) PCB Exposure: The thumbnail has random noise around the image - **Settings:** - (Add) Tools: "Always prompt for confirmation before execute the operation" - (Fix) Changing layer compression method when no file is loaded would cause a error - **UI:** - (Add) Holding Shift key while drag and drop a .uvtop file will try to execute the operation without showing the window or prompt - (Add) Drag and drop a .cs or .csx file into UVtools will load and show the scripting dialog with the file selected - (Add) Errors that crash application will now show an report window with the crash information and able to fast report them - (Add) "Version" key and value on registry to tell the current installed version (Windows MSI only) - (Upgrade) AvaloniaUI from 0.10.13 to 0.10.14 - (Upgrade) .NET from 6.0.4 to 6.0.5
369 lines
12 KiB
C#
369 lines
12 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.IO;
|
|
using System.Linq;
|
|
using UVtools.Core.FileFormats;
|
|
using UVtools.Core.MeshFormats;
|
|
using UVtools.Core.Operations;
|
|
using UVtools.Core.SystemOS;
|
|
|
|
namespace UVtools.WPF;
|
|
|
|
public static class ConsoleArguments
|
|
{
|
|
/// <summary>
|
|
/// Parse arguments from command line
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns>True if is a valid argument, otherwise false</returns>
|
|
public static bool ParseArgs(string[] args)
|
|
{
|
|
if(args.Length == 0) return false;
|
|
|
|
if (args[0] is "--cmd" && args.Length > 1)
|
|
{
|
|
var newArgs = string.Join(' ', args[1..]);
|
|
SystemAware.StartProcess(Path.Combine(App.ApplicationPath, SystemAware.GetExecutableName("UVtoolsCmd")), newArgs);
|
|
return true;
|
|
}
|
|
|
|
// Convert to other file
|
|
if (args[0] is "-c" or "--convert")
|
|
{
|
|
if (args.Length < 3)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <input_file> <output_file1/ext1> [output_file2/ext2]");
|
|
return true;
|
|
}
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var slicerFile = FileFormat.FindByExtensionOrFilePath(args[1], true);
|
|
if (slicerFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid input file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
|
|
var filenameNoExt = FileFormat.GetFileNameStripExtensions(args[1], out _);
|
|
|
|
var filesToConvert = new List<KeyValuePair<FileFormat, string>>();
|
|
|
|
for (int i = 2; i < args.Length; i++)
|
|
{
|
|
var outputFile = args[i];
|
|
var targetFormat = FileFormat.FindByExtensionOrFilePath(args[i], true);
|
|
if (targetFormat is null)
|
|
{
|
|
Console.WriteLine($"Invalid output file/extension: {args[i]}");
|
|
continue;
|
|
}
|
|
|
|
if(targetFormat.IsExtensionValid(outputFile))
|
|
outputFile = $"{filenameNoExt}.{args[i]}";
|
|
|
|
|
|
filesToConvert.Add(new KeyValuePair<FileFormat, string>(targetFormat, outputFile));
|
|
}
|
|
|
|
if (filesToConvert.Count == 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//var workingDir = Path.GetDirectoryName(args[1]);
|
|
//if(!string.IsNullOrWhiteSpace(workingDir)) Directory.SetCurrentDirectory(workingDir);
|
|
|
|
Console.WriteLine($"Loading file: {args[1]}");
|
|
slicerFile.Decode(args[1]);
|
|
|
|
foreach (var (outputSlicerFile, outputFile) in filesToConvert.DistinctBy(pair => pair.Value))
|
|
{
|
|
Console.WriteLine($"Converting to: {outputFile}");
|
|
slicerFile.Convert(outputSlicerFile, outputFile);
|
|
Console.WriteLine("Converted");
|
|
|
|
}
|
|
|
|
Console.WriteLine("OK");
|
|
|
|
return true;
|
|
}
|
|
|
|
// Extract the file
|
|
if (args[0] is "-e" or "--extract")
|
|
{
|
|
if (args.Length < 2)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <input_file> [output_folder]");
|
|
return true;
|
|
}
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var slicerFile = FileFormat.FindByExtensionOrFilePath(args[1], true);
|
|
if (slicerFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid input file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var outputFolder = FileFormat.GetFileNameStripExtensions(args[1], out _);
|
|
|
|
if (args.Length >= 3 && !string.IsNullOrWhiteSpace(args[2]))
|
|
{
|
|
try
|
|
{
|
|
Path.GetFullPath(outputFolder);
|
|
outputFolder = args[2];
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Console.WriteLine($"Invalid output directory: {args[2]}");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
//var workingDir = Path.GetDirectoryName(args[1]);
|
|
//if(!string.IsNullOrWhiteSpace(workingDir)) Directory.SetCurrentDirectory(workingDir);
|
|
|
|
Console.WriteLine($"Loading file: {args[1]}");
|
|
slicerFile.Decode(args[1]);
|
|
Console.WriteLine($"Extracting to: {outputFolder}");
|
|
slicerFile.Extract(outputFolder);
|
|
Console.WriteLine("Extracted");
|
|
Console.WriteLine("OK");
|
|
return true;
|
|
}
|
|
|
|
// Convert to other file
|
|
if (args[0] is "--export-mesh")
|
|
{
|
|
if (args.Length < 2)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <input_file> [output_mesh_file]");
|
|
return true;
|
|
}
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var slicerFile = FileFormat.FindByExtensionOrFilePath(args[1], true);
|
|
if (slicerFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid input file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var outputFile = Path.Combine(Path.GetDirectoryName(args[1]), $"{Path.GetFileNameWithoutExtension(args[1])}.stl");
|
|
|
|
if (args.Length >= 3 && !string.IsNullOrWhiteSpace(args[2]))
|
|
{
|
|
outputFile = args[2];
|
|
}
|
|
|
|
var outputExtension = MeshFile.FindFileExtension(outputFile);
|
|
if (outputExtension is null)
|
|
{
|
|
Console.WriteLine($"Invalid output file extension: {outputFile}");
|
|
return true;
|
|
}
|
|
|
|
|
|
Console.WriteLine($"Loading file: {args[1]}");
|
|
slicerFile.Decode(args[1]);
|
|
|
|
Console.WriteLine($"Exporting mesh to: {outputFile}");
|
|
var operation = new OperationLayerExportMesh(slicerFile)
|
|
{
|
|
FilePath = outputFile
|
|
};
|
|
operation.Execute();
|
|
Console.WriteLine("Exported");
|
|
|
|
Console.WriteLine("OK");
|
|
|
|
return true;
|
|
}
|
|
|
|
// Run operation and save file
|
|
if (args[0] is "--run-operation")
|
|
{
|
|
if (args.Length < 3)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <input_file> <operation_file.uvtop>");
|
|
return true;
|
|
}
|
|
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
if (!File.Exists(args[2]))
|
|
{
|
|
Console.WriteLine($"Operation file does not exists: {args[2]}");
|
|
return true;
|
|
}
|
|
|
|
var slicerFile = FileFormat.FindByExtensionOrFilePath(args[1], true);
|
|
if (slicerFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid input file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var operation = Operation.Deserialize(args[2]);
|
|
|
|
if (operation is null)
|
|
{
|
|
Console.WriteLine($"Invalid operation file: {args[2]}");
|
|
return true;
|
|
}
|
|
|
|
Console.WriteLine($"Loading file: {args[1]}");
|
|
slicerFile.Decode(args[1]);
|
|
|
|
Console.WriteLine($"Running operation: {operation.Title}");
|
|
operation.SlicerFile = slicerFile;
|
|
operation.Execute();
|
|
slicerFile.Save();
|
|
Console.WriteLine("Saved");
|
|
Console.WriteLine("OK");
|
|
|
|
return true;
|
|
}
|
|
|
|
// Run operation and save file
|
|
if (args[0] is "--run-script")
|
|
{
|
|
if (args.Length < 3)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <input_file> <script_file.cs>");
|
|
return true;
|
|
}
|
|
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
if (!File.Exists(args[2]) || !(args[2].EndsWith(".csx") || args[2].EndsWith(".cs")))
|
|
{
|
|
Console.WriteLine($"Script file does not exists or invalid: {args[2]}");
|
|
return true;
|
|
}
|
|
|
|
var slicerFile = FileFormat.FindByExtensionOrFilePath(args[1], true);
|
|
if (slicerFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid input file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
Console.WriteLine($"Loading file: {args[1]}");
|
|
slicerFile.Decode(args[1]);
|
|
|
|
var operation = new OperationScripting(slicerFile);
|
|
operation.ReloadScriptFromFile(args[2]);
|
|
|
|
Console.WriteLine($"Running script: {operation.Title}");
|
|
operation.Execute();
|
|
slicerFile.Save();
|
|
Console.WriteLine("Saved");
|
|
Console.WriteLine("OK");
|
|
|
|
return true;
|
|
}
|
|
|
|
// Run operation and save file
|
|
if (args[0] is "--copy-parameters")
|
|
{
|
|
if (args.Length < 3)
|
|
{
|
|
Console.WriteLine("Invalid syntax: <from_file> <to_file>");
|
|
return true;
|
|
}
|
|
|
|
if (args[1] == args[2])
|
|
{
|
|
Console.WriteLine($"Source file must be different from target file");
|
|
return true;
|
|
}
|
|
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Source file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
if (!File.Exists(args[2]))
|
|
{
|
|
Console.WriteLine($"Target file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var fromFile = FileFormat.FindByExtensionOrFilePath(args[1], true);
|
|
if (fromFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid source file: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
var toFile = FileFormat.FindByExtensionOrFilePath(args[2], true);
|
|
if (toFile is null)
|
|
{
|
|
Console.WriteLine($"Invalid target file: {args[2]}");
|
|
return true;
|
|
}
|
|
|
|
Console.WriteLine("Loading files");
|
|
fromFile.Decode(args[1], FileFormat.FileDecodeType.Partial);
|
|
toFile.Decode(args[2], FileFormat.FileDecodeType.Partial);
|
|
|
|
var count = FileFormat.CopyParameters(fromFile, toFile);
|
|
Console.WriteLine($"Modified parameters: {count}");
|
|
if (count > 0)
|
|
{
|
|
toFile.Save();
|
|
Console.WriteLine("Saved");
|
|
}
|
|
Console.WriteLine("OK");
|
|
|
|
return true;
|
|
}
|
|
|
|
if (args[0] == "--crypt-ctb")
|
|
{
|
|
if (!File.Exists(args[1]))
|
|
{
|
|
Console.WriteLine($"Input file does not exists: {args[1]}");
|
|
return true;
|
|
}
|
|
|
|
CTBEncryptedFile.CryptFile(args[1]);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |