From e7aa50a909a1dfb923b57abc66a82a8f642a9d55 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 2 Sep 2018 13:50:43 -0700 Subject: [PATCH] Revise user configuration support --- MatterControl.csproj | 3 +++ Program.cs | 21 ++++++++++++++++++++- SlicerConfiguration/Slicer.cs | 4 ++-- Submodules/agg-sharp | 2 +- appsettings.json | 11 +++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 appsettings.json diff --git a/MatterControl.csproj b/MatterControl.csproj index 108457041..9dc5d7367 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -607,6 +607,7 @@ InspectForm.cs + @@ -730,6 +731,8 @@ + + diff --git a/Program.cs b/Program.cs index a985394dc..d6b704dbb 100644 --- a/Program.cs +++ b/Program.cs @@ -5,6 +5,8 @@ using System.Threading; using MatterHackers.Agg.Platform; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using Microsoft.Extensions.Configuration; using Mindscape.Raygun4Net; namespace MatterHackers.MatterControl @@ -17,6 +19,11 @@ namespace MatterHackers.MatterControl private static RaygunClient _raygunClient; + private class SlicerOptions + { + public bool Debug { get; set; } + } + /// /// The main entry point for the application. /// @@ -40,7 +47,19 @@ namespace MatterHackers.MatterControl _raygunClient = new RaygunClient("hQIlyUUZRGPyXVXbI6l1dA=="); // this is the PC key } - AggContext.Init(embeddedResourceName: "config.json"); + // Set default Agg providers + AggContext.Config.ProviderTypes.SystemWindow = "MatterHackers.Agg.UI.OpenGLSystemWindow, agg_platform_win32"; + AggContext.Config.ProviderTypes.SystemWindowProvider = "MatterHackers.Agg.UI.WinformsSystemWindowProvider, agg_platform_win32"; + + // Load optional user configuration + IConfiguration config = new ConfigurationBuilder() + .AddJsonFile("appsettings.json", optional: true) + .Build(); + + // Override defaults via configuration + config.Bind("Agg:ProviderTypes", AggContext.Config.ProviderTypes); + config.Bind("Agg:GraphicsMode", AggContext.Config.GraphicsMode); + Slicer.RunInProcess = config.GetValue("MatterControl:Slicer:Debug"); // Make sure we have the right working directory as we assume everything relative to the executable. Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); diff --git a/SlicerConfiguration/Slicer.cs b/SlicerConfiguration/Slicer.cs index eab507c02..5ca02ac32 100644 --- a/SlicerConfiguration/Slicer.cs +++ b/SlicerConfiguration/Slicer.cs @@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration private static Dictionary meshPrintOutputSettings = new Dictionary(); public static List extrudersUsed = new List(); - public static bool runInProcess = false; + public static bool RunInProcess = false; public static List<(Matrix4X4 matrix, string fileName)> GetStlFileLocations(IObject3D object3D, ref string mergeRules, PrinterConfig printer, IProgress progressReporter, CancellationToken cancellationToken) { @@ -293,7 +293,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration if (AggContext.OperatingSystem == OSType.Android || AggContext.OperatingSystem == OSType.Mac - || runInProcess) + || RunInProcess) { EventHandler WriteOutput = (s, e) => { diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 4d61415fe..c5d5886d5 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 4d61415fe2ae91d1d67d3ee3023286bb27bef80c +Subproject commit c5d5886d54c40e56258c88c8351227574593db1b diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 000000000..92a13a950 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,11 @@ +{ + "Agg": { + "GraphicsMode": { + "Color": 32, + "Depth": 24, + "FSAASamples": 8 + } + }, + "MatterControl": { + } +} \ No newline at end of file