Files
UVtools/UVtools.WPF/Program.cs
T
Tiago Conceição 6dc26f7434 v3.8.0
- **File formats:**
  - (Add) Property: DisplayTotalOnTime
  - (Add) Property: DisplayTotalOffTime
  - (Add) SL1File Property: high_viscosity_tilt_time
- **Tools**
  - **I printed this file**
    - (Add) Display on time for the print information
    - (Improvement) Labels on numeric box
    - (Improvement) Show print time label formatted as hh:mm:ss
  - **PCB Exposure:**
    - (Improvement) Increase "Exposure time" maximum from 200s to 1000s (#592)
    - (Fix) Set `BottomLightHeight` to 0
    - (Fix) Set `TransitionLayerCount` to 0
- **Issues:**
  - (Improvement) Overhang detection by using a dynamic cross kernel
  - (Improvement) Bring back the discard logic of "false-positive" islands based on overhang detection but improve the threshold of the detection to be safer (#591, #591)
- **PrusaSlicer:**
  - (Change) Elegoo Mars 2 to use file version 4
  - (Change) Elegoo Mars 2 Pro to use file version 4
- (Add) Status bar: On and Off time (hh:mm:ss) as tooltip in the Print time label
- (Improvement) When any of libcvextern dependencies are missing, it try to show the missing libraries in the error message (Linux only)
- (Improvement) Auto-upgrade procedure for non-Windows systems
- (Improvement) macOS arm64 (M1/M2) can now run natively if installed via the auto installer script
- (Fix) Error on Mat cache manager when file have only one layer
- (Fix) Suggestion "Transition layer count" shows as never applied when using with file formats that use in-firmware transition layers
- (Upgrade) openCV from 4.5.4 to 4.6.0
  - Custom library is now built to strip unused dependencies and reduce library size
- (Remove) arch and rhel packages in favor of a generic linux
2022-10-30 00:52:49 +01:00

186 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Numerics;
using System.Threading.Tasks;
using Avalonia;
using AvaloniaEdit.Utils;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Features2D;
using Emgu.CV.Fuzzy;
using Emgu.CV.PpfMatch3d;
using Emgu.CV.XFeatures2D;
using Projektanker.Icons.Avalonia;
using Projektanker.Icons.Avalonia.FontAwesome;
using Projektanker.Icons.Avalonia.MaterialDesign;
using UVtools.Core.EmguCV;
using UVtools.Core.Extensions;
using UVtools.Core.MeshFormats;
using UVtools.Core.SystemOS;
namespace UVtools.WPF;
#nullable enable
public static class Program
{
public static string[] Args = Array.Empty<string>();
public static bool IsCrashReport;
public static Stopwatch ProgramStartupTime = null!;
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
ProgramStartupTime = Stopwatch.StartNew();
Args = args;
try
{
if (ConsoleArguments.ParseArgs(args)) return;
}
catch (Exception e)
{
Console.WriteLine(e);
return;
}
if (Args.Length > 2)
{
switch (Args[0])
{
case "--crash-report":
IsCrashReport = true;
break;
case "--debug":
App.IsDebug = true;
break;
}
}
/*using var mat = CvInvoke.Imread(@"D:\layer0.png", ImreadModes.Grayscale);
var contours = mat.FindContours(out var hierarchy, RetrType.Tree, ChainApproxMethod.ChainApproxTc89Kcos);
using var mesh = new STLMeshFile(@"D:\test.stl", FileMode.Create);
mesh.BeginWrite();
var groups = EmguContours.GetPositiveContoursInGroups(contours, hierarchy);
foreach (var group in groups)
{
var z = 0;
for (int i = 0; i < group.Size; i++)
{
var list = new List<PointF>();
for (int x = 0; x < contours[i].Size; x++)
{
list.Add(contours[i][x]);
}
using var sub = new Subdiv2D(list.ToArray());
var triangles = sub.GetDelaunayTriangles();
foreach (var triangle2Df in triangles)
{
mesh.WriteTriangle(
new Vector3(triangle2Df.V0.X, triangle2Df.V0.Y, z),
new Vector3(triangle2Df.V1.X, triangle2Df.V1.Y, z),
new Vector3(triangle2Df.V2.X, triangle2Df.V2.Y, z),
new Vector3(triangle2Df.Centeroid.X, triangle2Df.Centeroid.Y, z)
);
}
z++;
}
break;
}
mesh.EndWrite();
return;*/
/*Slicer slicer = new(Size.Empty, SizeF.Empty, "D:\\Cube100x100x100.stl");
var slices = slicer.SliceModel(0.05f);
foreach (var slice in slices)
{
using var mat = EmguExtensions.InitMat(new Size(1000, 1000));
var contour = slice.Value.ToContour();
using var vec = new VectorOfPoint(contour);
CvInvoke.FillPoly(mat, vec, EmguExtensions.WhiteColor, LineType.AntiAlias);
mat.Save(@$"D:\SLICE\{slice.Key}.png");
}*/
// PrusaSlicer to Machine.cs
//var machines = Machine.GetMachinesFromPrusaSlicer();
//var machinesText = Machine.GenerateMachinePresetsFromPrusaSlicer();
// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException += (sender, e) => HandleUnhandledException("Non-UI", (Exception)e.ExceptionObject);
TaskScheduler.UnobservedTaskException += (sender, e) => HandleUnhandledException("Task", e.Exception);
//AppDomain.CurrentDomain.FirstChanceException += CurrentDomainOnFirstChanceException;
try
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
catch (Exception e)
{
HandleUnhandledException("Application", e);
}
// Closing
}
private static void HandleUnhandledException(string category, Exception ex)
{
ErrorLog.AppendLine($"Fatal {category} Error", ex.ToString());
if (!IsCrashReport)
{
try
{
string? file = null;
if (App.SlicerFile is not null)
{
file = $"{App.SlicerFile.Filename} [Version: {App.SlicerFile.Version}] [Class: {App.SlicerFile.GetType().Name}]";
}
SystemAware.StartThisApplication($"--crash-report \"{category}\" \"{ex}\" \"{file}\"");
//var errorMsg = $"An application error occurred. Please contact the administrator with the following information:\n\n{ex}";
//await App.MainWindow.MessageBoxError(errorMsg, "Fatal Non-UI Error");
}
catch (Exception exception)
{
Debug.WriteLine(exception);
Console.WriteLine(exception);
}
}
Environment.Exit(-1);
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.With(new Win32PlatformOptions { AllowEglInitialization = false/*, UseWgl = true*/})
.With(new X11PlatformOptions { UseGpu = true/*, UseEGL = true*/ })
.With(new MacOSPlatformOptions { ShowInDock = true })
.With(new AvaloniaNativePlatformOptions { UseGpu = true })
.WithIcons(container => container
.Register<FontAwesomeIconProvider>()
.Register<MaterialDesignIconProvider>())
//.UseSkia()
.LogToTrace();
}