From fd4cde55c6a84fcd492e6aa9a7cb3d5a3eb99983 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 5 Sep 2018 13:21:25 -0700 Subject: [PATCH] Remove Winforms dependencies from MatterControl assembly --- ApplicationView/ApplicationController.cs | 21 +--- .../ApplicationSettingsView.cs | 49 +--------- .../InspectForm.Designer.cs | 0 .../InspectForm.cs | 0 .../InspectForm.resx | 0 .../MatterControl.Winforms.csproj | 95 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++ .../WindowsPlatformsFeatures.cs | 82 ++++++++++++---- MatterControl.csproj | 23 ----- PluginSystem/INativePlatformFeatures.cs | 48 ++++++++++ PluginSystem/MatterControlPluginSystem.csproj | 1 + Program.cs | 3 +- RootSystemWindow.cs | 24 +---- Submodules/agg-sharp | 2 +- .../MatterControl.AutomationTests.csproj | 4 + .../MatterControl.Tests.csproj | 4 + 16 files changed, 262 insertions(+), 130 deletions(-) rename {Utilities => MatterControl.Winforms}/InspectForm.Designer.cs (100%) rename {Utilities => MatterControl.Winforms}/InspectForm.cs (100%) rename {Utilities => MatterControl.Winforms}/InspectForm.resx (100%) create mode 100644 MatterControl.Winforms/MatterControl.Winforms.csproj create mode 100644 MatterControl.Winforms/Properties/AssemblyInfo.cs rename {ApplicationView => MatterControl.Winforms}/WindowsPlatformsFeatures.cs (73%) create mode 100644 PluginSystem/INativePlatformFeatures.cs diff --git a/ApplicationView/ApplicationController.cs b/ApplicationView/ApplicationController.cs index 0fd30fda7..e87c32500 100644 --- a/ApplicationView/ApplicationController.cs +++ b/ApplicationView/ApplicationController.cs @@ -1250,12 +1250,7 @@ namespace MatterHackers.MatterControl this.RebuildSceneOperations(this.Theme); -#if DEBUG && !__ANDROID__ - if (AggContext.StaticData is FileSystemStaticData staticData) - { - staticData.PurgeCache(); - } -#endif + AggContext.StaticData.PurgeCache(); } public bool RunAnyRequiredPrinterSetup(PrinterConfig printer, ThemeConfig theme) @@ -2497,20 +2492,6 @@ namespace MatterHackers.MatterControl public enum ReportSeverity2 { Warning, Error } - public interface INativePlatformFeatures - { - event EventHandler PictureTaken; - void TakePhoto(string imageFileName); - void OpenCameraPreview(); - void PlaySound(string fileName); - void ConfigureWifi(); - bool CameraInUseByExternalProcess { get; set; } - bool IsNetworkConnected(); - void FindAndInstantiatePlugins(SystemWindow systemWindow); - void ProcessCommandline(); - void PlatformInit(Action reporter); - } - public static class Application { private static ProgressBar progressBar; diff --git a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs index f617dfbb8..35441c750 100644 --- a/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs +++ b/ConfigurationPage/ApplicationSettings/ApplicationSettingsView.cs @@ -158,7 +158,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage if (languageCode == "L10N") { - GenerateLocalizationValidationFile(); +#if DEBUG + AppContext.Platform.GenerateLocalizationValidationFile(); +#endif } ApplicationController.Instance.ResetTranslationMap(); @@ -424,50 +426,5 @@ namespace MatterHackers.MatterControl.ConfigurationPage return container; } - - [Conditional("DEBUG")] - private void GenerateLocalizationValidationFile() - { -#if !__ANDROID__ - if (AggContext.StaticData is FileSystemStaticData fileSystemStaticData) - { - char currentChar = 'A'; - - // Note: Functionality only expected to work on Desktop/Debug builds and as such, is coupled to FileSystemStaticData - string outputPath = fileSystemStaticData.MapPath(Path.Combine("Translations", "L10N", "Translation.txt")); - string sourceFilePath = fileSystemStaticData.MapPath(Path.Combine("Translations", "Master.txt")); - - // Ensure the output directory exists - Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); - - using (var outstream = new StreamWriter(outputPath)) - { - foreach (var line in File.ReadAllLines(sourceFilePath)) - { - if (line.StartsWith("Translated:")) - { - var pos = line.IndexOf(':'); - var segments = new string[] - { - line.Substring(0, pos), - line.Substring(pos + 1), - }; - - outstream.WriteLine("{0}:{1}", segments[0], new string(segments[1].ToCharArray().Select(c => c == ' ' ? ' ' : currentChar).ToArray())); - - if (currentChar++ == 'Z') - { - currentChar = 'A'; - } - } - else - { - outstream.WriteLine(line); - } - } - } - } -#endif - } } } \ No newline at end of file diff --git a/Utilities/InspectForm.Designer.cs b/MatterControl.Winforms/InspectForm.Designer.cs similarity index 100% rename from Utilities/InspectForm.Designer.cs rename to MatterControl.Winforms/InspectForm.Designer.cs diff --git a/Utilities/InspectForm.cs b/MatterControl.Winforms/InspectForm.cs similarity index 100% rename from Utilities/InspectForm.cs rename to MatterControl.Winforms/InspectForm.cs diff --git a/Utilities/InspectForm.resx b/MatterControl.Winforms/InspectForm.resx similarity index 100% rename from Utilities/InspectForm.resx rename to MatterControl.Winforms/InspectForm.resx diff --git a/MatterControl.Winforms/MatterControl.Winforms.csproj b/MatterControl.Winforms/MatterControl.Winforms.csproj new file mode 100644 index 000000000..f67eac9aa --- /dev/null +++ b/MatterControl.Winforms/MatterControl.Winforms.csproj @@ -0,0 +1,95 @@ + + + + + Debug + AnyCPU + {D6DC2669-7B1F-40FE-89BF-45D4C94473E3} + Library + Properties + MatterControl.Winforms + MatterControl.Winforms + v4.7.1 + 512 + true + + + true + full + false + ..\bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + InspectForm.cs + + + + + + + {0b8d6f56-bd7f-4426-b858-d9292b084656} + MatterControl + + + {865172a0-a1a9-49c2-9386-f2fdb4e141b7} + MatterControlPluginSystem + + + {657dbc6d-c3ea-4398-a3fa-ddb73c14f71b} + Agg + + + {04667764-dc7b-4b95-aef6-b4e6c87a54e9} + DataConverters3D + + + {74f6bb6c-9d02-4512-a59a-21940e35c532} + Gui + + + {670bddff-927b-425d-9dd1-22acb14356eb} + PlatformWin32 + + + {545b6912-77ff-4b34-ba76-6c3d6a32be6a} + RenderOpenGl + + + {d3e41b4e-bfbb-44ca-94c8-95c00f754fdd} + VectorMath + + + + + InspectForm.cs + + + + \ No newline at end of file diff --git a/MatterControl.Winforms/Properties/AssemblyInfo.cs b/MatterControl.Winforms/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1035c00bb --- /dev/null +++ b/MatterControl.Winforms/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MatterControl.Winforms")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MatterControl.Winforms")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d6dc2669-7b1f-40fe-89bf-45d4c94473e3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ApplicationView/WindowsPlatformsFeatures.cs b/MatterControl.Winforms/WindowsPlatformsFeatures.cs similarity index 73% rename from ApplicationView/WindowsPlatformsFeatures.cs rename to MatterControl.Winforms/WindowsPlatformsFeatures.cs index 9d1034727..79e577882 100644 --- a/ApplicationView/WindowsPlatformsFeatures.cs +++ b/MatterControl.Winforms/WindowsPlatformsFeatures.cs @@ -28,7 +28,6 @@ either expressed or implied, of the FreeBSD Project. */ using System; -using System.Collections.Generic; using System.IO; using MatterHackers.Agg; using MatterHackers.Agg.UI; @@ -93,23 +92,9 @@ namespace MatterHackers.MatterControl public void FindAndInstantiatePlugins(SystemWindow systemWindow) { - string oemName = ApplicationSettings.Instance.GetOEMName(); foreach (MatterControlPlugin plugin in PluginFinder.CreateInstancesOf()) { - string pluginInfo = plugin.GetPluginInfoJSon(); - Dictionary nameValuePairs = Newtonsoft.Json.JsonConvert.DeserializeObject>(pluginInfo); - - if (nameValuePairs != null && nameValuePairs.ContainsKey("OEM")) - { - if (nameValuePairs["OEM"] == oemName) - { - plugin.Initialize(systemWindow); - } - } - else - { - plugin.Initialize(systemWindow); - } + plugin.Initialize(systemWindow); } } @@ -161,7 +146,72 @@ namespace MatterHackers.MatterControl AggContext.StaticData = new FileSystemStaticData(); } + if (Clipboard.Instance == null) + { + Clipboard.SetSystemClipboard(new WindowsFormsClipboard()); + } + + WinformsSystemWindow.InspectorCreator = (inspectingWindow) => + { + if (inspectingWindow == AppContext.RootSystemWindow) + { + // If this is MatterControlApplication, include Scene + var partContext = ApplicationController.Instance.DragDropData; + return new InspectForm(inspectingWindow, partContext.SceneContext?.Scene ?? null, partContext.View3DWidget); + } + else + { + // Otherwise, exclude Scene + return new InspectForm(inspectingWindow); + } + }; + + ApplicationSettings.Instance.set("HardwareHasCamera", "false"); } + + public void GenerateLocalizationValidationFile() + { + if (AggContext.StaticData is FileSystemStaticData fileSystemStaticData) + { + char currentChar = 'A'; + + // Note: Functionality only expected to work on Desktop/Debug builds and as such, is coupled to FileSystemStaticData + string outputPath = fileSystemStaticData.MapPath(Path.Combine("Translations", "L10N", "Translation.txt")); + string sourceFilePath = fileSystemStaticData.MapPath(Path.Combine("Translations", "Master.txt")); + + // Ensure the output directory exists + Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); + + using (var outstream = new StreamWriter(outputPath)) + { + foreach (var line in File.ReadAllLines(sourceFilePath)) + { + if (line.StartsWith("Translated:")) + { + var pos = line.IndexOf(':'); + var segments = new string[] + { + line.Substring(0, pos), + line.Substring(pos + 1), + }; + + outstream.WriteLine("{0}:{1}", segments[0], new string(segments[1].ToCharArray().Select(c => c == ' ' ? ' ' : currentChar).ToArray())); + + if (currentChar++ == 'Z') + { + currentChar = 'A'; + } + } + else + { + outstream.WriteLine(line); + } + } + } + } + } } + +} } \ No newline at end of file diff --git a/MatterControl.csproj b/MatterControl.csproj index 7d2e35c1a..970017ec2 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -186,7 +186,6 @@ - @@ -316,12 +315,6 @@ - - Form - - - InspectForm.cs - @@ -559,13 +552,8 @@ - - - - Submodules\agg-sharp\PlatformWin32\OpenTK.dll - @@ -598,9 +586,6 @@ - - InspectForm.cs - @@ -661,10 +646,6 @@ {d3e41b4e-bfbb-44ca-94c8-95c00f754fdd} VectorMath - - {5754893a-e806-4d67-96b4-d64d3f85d1e4} - MatterHackers.VeldridProvider - {c46ca728-dd2f-4dd1-971a-aaa89d9dff95} MatterSlice @@ -689,10 +670,6 @@ {86f6aaf2-9b50-40b8-a427-1897d76471c5} PolygonMesh - - {670bddff-927b-425d-9dd1-22acb14356eb} - PlatformWin32 - {865172a0-a1a9-49c2-9386-f2fdb4e141b7} MatterControlPluginSystem diff --git a/PluginSystem/INativePlatformFeatures.cs b/PluginSystem/INativePlatformFeatures.cs new file mode 100644 index 000000000..4cdf57be3 --- /dev/null +++ b/PluginSystem/INativePlatformFeatures.cs @@ -0,0 +1,48 @@ +/* +Copyright (c) 2018, Lars Brubaker, John Lewin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using System; + +namespace MatterHackers.Agg.UI +{ + public interface INativePlatformFeatures + { + event EventHandler PictureTaken; + void TakePhoto(string imageFileName); + void OpenCameraPreview(); + void PlaySound(string fileName); + void ConfigureWifi(); + bool CameraInUseByExternalProcess { get; set; } + bool IsNetworkConnected(); + void FindAndInstantiatePlugins(SystemWindow systemWindow); + void ProcessCommandline(); + void PlatformInit(Action reporter); + void GenerateLocalizationValidationFile(); + } +} \ No newline at end of file diff --git a/PluginSystem/MatterControlPluginSystem.csproj b/PluginSystem/MatterControlPluginSystem.csproj index b6edf75d6..5eb5495da 100644 --- a/PluginSystem/MatterControlPluginSystem.csproj +++ b/PluginSystem/MatterControlPluginSystem.csproj @@ -45,6 +45,7 @@ + diff --git a/Program.cs b/Program.cs index 408b38410..15071fbf4 100644 --- a/Program.cs +++ b/Program.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.IO; using System.Threading; using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.SettingsManagement; using MatterHackers.MatterControl.SlicerConfiguration; @@ -94,7 +95,7 @@ namespace MatterHackers.MatterControl } // Init platformFeaturesProvider before ShowAsSystemWindow - string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl"; + string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms"; AppContext.Platform = AggContext.CreateInstanceFrom(platformFeaturesProvider); AppContext.Platform.ProcessCommandline(); diff --git a/RootSystemWindow.cs b/RootSystemWindow.cs index a92797275..3c0477f3a 100644 --- a/RootSystemWindow.cs +++ b/RootSystemWindow.cs @@ -53,7 +53,7 @@ namespace MatterHackers.MatterControl private AverageMillisecondTimer millisecondTimer = new AverageMillisecondTimer(); - internal static bool ShowMemoryUsed = false; + public static bool ShowMemoryUsed = false; private int drawCount = 0; @@ -122,28 +122,6 @@ namespace MatterHackers.MatterControl } this.Maximized = ApplicationSettings.Instance.get(ApplicationSettingsKey.MainWindowMaximized) == "true"; - -#if IS_WINDOWS_FORMS - if (Clipboard.Instance == null) - { - Clipboard.SetSystemClipboard(new WindowsFormsClipboard()); - } - - WinformsSystemWindow.InspectorCreator = (inspectingWindow) => - { - if (inspectingWindow == this) - { - // If this is MatterControlApplication, include Scene - var partContext = ApplicationController.Instance.DragDropData; - return new InspectForm(inspectingWindow, partContext.SceneContext?.Scene ?? null, partContext.View3DWidget); - } - else - { - // Otherwise, exclude Scene - return new InspectForm(inspectingWindow); - } - }; -#endif } public static (int width, int height) GetStartupBounds(int overrideWidth = -1, int overrideHeight = -1) diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index cf361853c..6eebd27a0 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit cf361853c36e3b99bd4a970e7a6c7e9fb70a1800 +Subproject commit 6eebd27a04e2adab433af0a3447fec2936ba5a3f diff --git a/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj b/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj index 76ab4fe89..bdde90b67 100644 --- a/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj +++ b/Tests/MatterControl.AutomationTests/MatterControl.AutomationTests.csproj @@ -78,6 +78,10 @@ {97d5ade3-c1b4-4b46-8a3e-718a4f7f079f} MatterControl.Printing + + {865172a0-a1a9-49c2-9386-f2fdb4e141b7} + MatterControlPluginSystem + {657dbc6d-c3ea-4398-a3fa-ddb73c14f71b} Agg diff --git a/Tests/MatterControl.Tests/MatterControl.Tests.csproj b/Tests/MatterControl.Tests/MatterControl.Tests.csproj index 2c8e46596..a386fa1d7 100644 --- a/Tests/MatterControl.Tests/MatterControl.Tests.csproj +++ b/Tests/MatterControl.Tests/MatterControl.Tests.csproj @@ -92,6 +92,10 @@ {97d5ade3-c1b4-4b46-8a3e-718a4f7f079f} MatterControl.Printing + + {865172a0-a1a9-49c2-9386-f2fdb4e141b7} + MatterControlPluginSystem + {657dbc6d-c3ea-4398-a3fa-ddb73c14f71b} Agg