diff --git a/MatterControlLib/ApplicationView/AppContext.cs b/MatterControlLib/ApplicationView/AppContext.cs new file mode 100644 index 000000000..77659d3f8 --- /dev/null +++ b/MatterControlLib/ApplicationView/AppContext.cs @@ -0,0 +1,245 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public static class AppContext + { + /// + /// Gets or sets native platform features + /// + public static INativePlatformFeatures Platform { get; set; } + + public static MatterControlOptions Options { get; set; } = new MatterControlOptions(); + + public static bool IsLoading { get; internal set; } = true; + + /// + /// Gets the root SystemWindow + /// + public static SystemWindow RootSystemWindow { get; internal set; } + + public static ThemeConfig Theme => themeset.Theme; + + public static ThemeConfig MenuTheme => themeset.MenuTheme; + + private static ThemeSet themeset; + + public static ThemeSet ThemeSet => themeset; + + public static Dictionary ThemeProviders { get; } + + private static Dictionary themes = new Dictionary(); + + static AppContext() + { + ThemeProviders = new Dictionary(); + + string themesPath = Path.Combine("Themes", "System"); + + var staticData = AggContext.StaticData; + + // Load available themes from StaticData + if (staticData.DirectoryExists(themesPath)) + { + var themeFiles = staticData.GetDirectories(themesPath).SelectMany(d => staticData.GetFiles(d).Where(p => Path.GetExtension(p) == ".json")); + foreach (var themeFile in themeFiles) + { + themes[Path.GetFileNameWithoutExtension(themeFile)] = themeFile; + } + + foreach (var directoryTheme in AggContext.StaticData.GetDirectories(themesPath).Where(d => Path.GetFileName(d) != "Menus").Select(d => new DirectoryTheme(d))) + { + ThemeProviders.Add(directoryTheme.Name, directoryTheme); + } + } + + // Load theme + try + { + if (File.Exists(ProfileManager.Instance.ProfileThemeSetPath)) + { + themeset = JsonConvert.DeserializeObject(File.ReadAllText(ProfileManager.Instance.ProfileThemeSetPath)); + themeset.Theme.EnsureDefaults(); + + // If the serialized format is older than the current format, null and fall back to latest default below + if (themeset.SchemeVersion != ThemeSet.LatestSchemeVersion) + { + themeset = null; + } + } + } + catch { } + + if (themeset == null) + { + var themeProvider = ThemeProviders["Modern"]; + themeset = themeProvider.GetTheme("Modern-Dark"); + } + + DefaultThumbView.ThumbColor = new Color(themeset.Theme.TextColor, 30); + + ToolTipManager.CreateToolTip = MatterControlToolTipWidget; + } + + private static GuiWidget MatterControlToolTipWidget(string toolTipText) + { + var toolTipPopover = new ClickablePopover(ArrowDirection.Up, new BorderDouble(0, 0), 7, 0); + + var markdownWidegt = new MarkdownWidget(Theme, false) + { + HAnchor = HAnchor.Absolute, + VAnchor = VAnchor.Fit, + Width = 350 * GuiWidget.DeviceScale, + BackgroundColor = Theme.BackgroundColor, + Border = 1, + BorderColor = Color.Black, + }; + + markdownWidegt.Markdown = toolTipText; + markdownWidegt.Width = 350; + var maxLineWidth = markdownWidegt.Descendants().Max(i => i.MaxLineWidth); + markdownWidegt.Width = maxLineWidth + 15; + + return markdownWidegt; + } + + public static ThemeConfig LoadTheme(string themeName) + { + try + { + if (themes.TryGetValue(themeName, out string themePath)) + { + string json = AggContext.StaticData.ReadAllText(themePath); + + var themeConfig = JsonConvert.DeserializeObject(json); + themeConfig.EnsureDefaults(); + + return themeConfig; + } + } + catch + { + Console.WriteLine("Error loading theme: " + themeName); + } + + return new ThemeConfig(); + } + + public static void SetThemeAccentColor(Color accentColor) + { + themeset.SetAccentColor(accentColor); + AppContext.SetTheme(themeset); + } + + public static void SetTheme(ThemeSet themeSet) + { + themeset = themeSet; + + File.WriteAllText( + ProfileManager.Instance.ProfileThemeSetPath, + JsonConvert.SerializeObject( + themeset, + Formatting.Indented, + new JsonSerializerSettings + { + ContractResolver = new ThemeContractResolver() + })); + + UiThread.RunOnIdle(() => + { + UserSettings.Instance.set(UserSettingsKey.ActiveThemeName, themeset.Name); + + // Explicitly fire ReloadAll in response to user interaction + ApplicationController.Instance.ReloadAll().ConfigureAwait(false); + }); + } + + public class MatterControlOptions + { + public bool McwsTestEnvironment { get; set; } + } + } +} diff --git a/MatterControlLib/ApplicationView/Application.cs b/MatterControlLib/ApplicationView/Application.cs new file mode 100644 index 000000000..dd49e9560 --- /dev/null +++ b/MatterControlLib/ApplicationView/Application.cs @@ -0,0 +1,752 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public static class Application + { + private static ProgressBar progressBar; + private static TextWidget statusText; + private static FlowLayoutWidget progressPanel; + private static string lastSection = ""; + private static Stopwatch timer; + + public static bool EnableF5Collect { get; set; } + + public static bool EnableNetworkTraffic { get; set; } = true; + + public static MiniTouchScreen MiniTouchScreen { get; set; } = new MiniTouchScreen(); + + public static SystemWindow LoadRootWindow(int width, int height) + { + timer = Stopwatch.StartNew(); + + if (false) + { + // set the default font + AggContext.DefaultFont = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Regular); + AggContext.DefaultFontBold = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Bold); + AggContext.DefaultFontItalic = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Italic); + AggContext.DefaultFontBoldItalic = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Bold_Italic); + } + + var systemWindow = new RootSystemWindow(width, height); + + var overlay = new GuiWidget() + { + BackgroundColor = AppContext.Theme.BackgroundColor, + }; + overlay.AnchorAll(); + + systemWindow.AddChild(overlay); + + var mutedAccentColor = AppContext.Theme.SplashAccentColor; + + var spinner = new LogoSpinner(overlay, rotateX: -0.05) + { + MeshColor = mutedAccentColor + }; + + progressPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + Position = new Vector2(0, height * .25), + HAnchor = HAnchor.Center | HAnchor.Fit, + VAnchor = VAnchor.Fit, + MinimumSize = new Vector2(400, 100), + Margin = new BorderDouble(0, 0, 0, 200) + }; + overlay.AddChild(progressPanel); + + progressPanel.AddChild(statusText = new TextWidget("", textColor: AppContext.Theme.TextColor) + { + MinimumSize = new Vector2(200, 30), + HAnchor = HAnchor.Center, + AutoExpandBoundsToText = true + }); + + progressPanel.AddChild(progressBar = new ProgressBar() + { + FillColor = mutedAccentColor, + BorderColor = Color.Gray, // theme.BorderColor75, + Height = 11, + Width = 230, + HAnchor = HAnchor.Center, + VAnchor = VAnchor.Absolute + }); + + AppContext.RootSystemWindow = systemWindow; + + // hook up a keyboard watcher to rout keys when not handled by children + + systemWindow.KeyPressed += SystemWindow_KeyPressed; + + systemWindow.KeyDown += (s, keyEvent) => + { + var view3D = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); + var printerTabPage = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); + var offsetDist = 50; + var arrowKeyOperation = keyEvent.Shift ? TrackBallTransformType.Translation : TrackBallTransformType.Rotation; + + var gcode2D = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); + + if (keyEvent.KeyCode == Keys.F1) + { + ApplicationController.Instance.ActivateHelpTab(); + } + + if (EnableF5Collect + && keyEvent.KeyCode == Keys.F5) + { + GC.Collect(); + systemWindow.Invalidate(); + } + + if (!keyEvent.Handled + && gcode2D != null) + { + switch (keyEvent.KeyCode) + { + case Keys.Oemplus: + case Keys.Add: + if (keyEvent.Control) + { + // Zoom out + gcode2D.Zoom(1.2); + keyEvent.Handled = true; + } + + break; + + case Keys.OemMinus: + case Keys.Subtract: + if (keyEvent.Control) + { + // Zoom in + gcode2D.Zoom(.8); + keyEvent.Handled = true; + } + + break; + } + } + + if (!keyEvent.Handled + && view3D != null) + { + switch (keyEvent.KeyCode) + { + case Keys.C: + if (keyEvent.Control) + { + view3D.Scene.Copy(); + keyEvent.Handled = true; + } + + break; + + case Keys.P: + if (keyEvent.Control) + { + view3D.PushToPrinterAndPrint(); + } + + break; + + case Keys.X: + if (keyEvent.Control) + { + view3D.Scene.Cut(); + keyEvent.Handled = true; + } + + break; + + case Keys.Y: + if (keyEvent.Control) + { + view3D.Scene.UndoBuffer.Redo(); + keyEvent.Handled = true; + } + + break; + + case Keys.A: + if (keyEvent.Control) + { + view3D.SelectAll(); + keyEvent.Handled = true; + } + + break; + + case Keys.S: + if (keyEvent.Control) + { + view3D.Save(); + keyEvent.Handled = true; + } + + break; + + case Keys.V: + if (keyEvent.Control) + { + view3D.sceneContext.Paste(); + keyEvent.Handled = true; + } + + break; + + case Keys.Oemplus: + case Keys.Add: + if (keyEvent.Control) + { + // Zoom out + Offset3DView(view3D, new Vector2(0, offsetDist), TrackBallTransformType.Scale); + keyEvent.Handled = true; + } + + break; + + case Keys.OemMinus: + case Keys.Subtract: + if (keyEvent.Control) + { + // Zoom in + Offset3DView(view3D, new Vector2(0, -offsetDist), TrackBallTransformType.Scale); + keyEvent.Handled = true; + } + + break; + + case Keys.Z: + if (keyEvent.Control) + { + if (keyEvent.Shift) + { + view3D.Scene.Redo(); + } + else + { + // undo last operation + view3D.Scene.Undo(); + } + + keyEvent.Handled = true; + } + + break; + + case Keys.Insert: + if (keyEvent.Shift) + { + view3D.sceneContext.Paste(); + keyEvent.Handled = true; + } + + break; + + case Keys.Delete: + case Keys.Back: + view3D.Scene.DeleteSelection(); + keyEvent.Handled = true; + keyEvent.SuppressKeyPress = true; + break; + + case Keys.Escape: + if (view3D.CurrentSelectInfo.DownOnPart) + { + view3D.CurrentSelectInfo.DownOnPart = false; + + view3D.Scene.SelectedItem.Matrix = view3D.TransformOnMouseDown; + + keyEvent.Handled = true; + keyEvent.SuppressKeyPress = true; + } + + foreach (var interactionVolume in view3D.InteractionLayer.InteractionVolumes) + { + interactionVolume.CancelOperation(); + } + + break; + + case Keys.Left: + if (keyEvent.Control + && printerTabPage != null + && !printerTabPage.sceneContext.ViewState.ModelView) + { + // Decrement slider + printerTabPage.LayerFeaturesIndex -= 1; + } + else + { + if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) + { + NudgeItem(view3D, object3D, ArrowDirection.Left, keyEvent); + } + else + { + // move or rotate view left + Offset3DView(view3D, new Vector2(-offsetDist, 0), arrowKeyOperation); + } + } + + keyEvent.Handled = true; + keyEvent.SuppressKeyPress = true; + break; + + case Keys.Right: + if (keyEvent.Control + && printerTabPage != null + && !printerTabPage.sceneContext.ViewState.ModelView) + { + // Increment slider + printerTabPage.LayerFeaturesIndex += 1; + } + else + { + if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) + { + NudgeItem(view3D, object3D, ArrowDirection.Right, keyEvent); + } + else + { + // move or rotate view right + Offset3DView(view3D, new Vector2(offsetDist, 0), arrowKeyOperation); + } + } + + keyEvent.Handled = true; + keyEvent.SuppressKeyPress = true; + break; + + case Keys.Up: + if (view3D.Printer != null + && printerTabPage != null + && view3D.Printer.ViewState.ViewMode != PartViewMode.Model) + { + printerTabPage.LayerScrollbar.Value += 1; + } + else + { + if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) + { + NudgeItem(view3D, object3D, ArrowDirection.Up, keyEvent); + } + else + { + Offset3DView(view3D, new Vector2(0, offsetDist), arrowKeyOperation); + } + } + + keyEvent.Handled = true; + keyEvent.SuppressKeyPress = true; + break; + + case Keys.Down: + if (view3D.Printer != null + && printerTabPage != null + && view3D.Printer.ViewState.ViewMode != PartViewMode.Model) + { + printerTabPage.LayerScrollbar.Value -= 1; + } + else + { + if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) + { + NudgeItem(view3D, object3D, ArrowDirection.Down, keyEvent); + } + else + { + Offset3DView(view3D, new Vector2(0, -offsetDist), arrowKeyOperation); + } + } + + keyEvent.Handled = true; + keyEvent.SuppressKeyPress = true; + break; + } + } + }; + + // Hook SystemWindow load and spin up MatterControl once we've hit first draw + systemWindow.Load += (s, e) => + { + // Show the End User License Agreement if it has not been shown (on windows it is shown in the installer) + if (AggContext.OperatingSystem != OSType.Windows + && UserSettings.Instance.get(UserSettingsKey.SoftwareLicenseAccepted) != "true") + { + var eula = new LicenseAgreementPage(LoadMC) + { + Margin = new BorderDouble(5) + }; + + systemWindow.AddChild(eula); + } + else + { + LoadMC(); + } + }; + + void LoadMC() + { + ReportStartupProgress(0.02, "First draw->RunOnIdle"); + + // UiThread.RunOnIdle(() => + Task.Run(async () => + { + try + { + ReportStartupProgress(0.15, "MatterControlApplication.Initialize"); + + ApplicationController.LoadTranslationMap(); + + var mainView = await Initialize(systemWindow, (progress0To1, status) => + { + ReportStartupProgress(0.2 + progress0To1 * 0.7, status); + }); + + ReportStartupProgress(0.9, "AddChild->MainView"); + systemWindow.AddChild(mainView, 0); + + ReportStartupProgress(1, ""); + systemWindow.BackgroundColor = Color.Transparent; + overlay.Close(); + } + catch (Exception ex) + { + UiThread.RunOnIdle(() => + { + statusText.Visible = false; + + var errorTextColor = Color.White; + + progressPanel.Margin = 0; + progressPanel.VAnchor = VAnchor.Center | VAnchor.Fit; + progressPanel.BackgroundColor = Color.DarkGray; + progressPanel.Padding = 20; + progressPanel.Border = 1; + progressPanel.BorderColor = Color.Red; + + var theme = new ThemeConfig(); + + progressPanel.AddChild( + new TextWidget("Startup Failure".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: errorTextColor)); + + progressPanel.AddChild( + new TextWidget(ex.Message, pointSize: theme.FontSize9, textColor: errorTextColor)); + + var closeButton = new TextButton("Close", theme) + { + BackgroundColor = theme.SlightShade, + HAnchor = HAnchor.Right, + VAnchor = VAnchor.Absolute + }; + closeButton.Click += (s1, e1) => + { + systemWindow.Close(); + }; + + spinner.SpinLogo = false; + progressBar.Visible = false; + + progressPanel.AddChild(closeButton); + }); + } + + AppContext.IsLoading = false; + }); + } + + ReportStartupProgress(0, "ShowAsSystemWindow"); + + return systemWindow; + } + + private static void SystemWindow_KeyPressed(object sender, KeyPressEventArgs keyEvent) + { + if (sender is SystemWindow systemWindow) + { + var view3D = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); + var printerTabPage = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); + + if (!keyEvent.Handled + && view3D != null) + { + switch (keyEvent.KeyChar) + { + case 'w': + case 'W': + view3D.ResetView(); + keyEvent.Handled = true; + break; + + case ' ': + view3D.Scene.ClearSelection(); + keyEvent.Handled = true; + break; + } + } + } + } + + private static void NudgeItem(View3DWidget view3D, IObject3D item, ArrowDirection arrowDirection, KeyEventArgs keyEvent) + { + + var world = view3D.InteractionLayer.World; + + var vector3 = default(Vector3); + + // TODO: analyze the view and adjust movements to be relative to the current perspective + // + // Naive movements in Identity space + switch (arrowDirection) + { + case ArrowDirection.Left: + vector3 = new Vector3(-view3D.InteractionLayer.SnapGridDistance, 0, 0); + break; + + case ArrowDirection.Right: + vector3 = new Vector3(view3D.InteractionLayer.SnapGridDistance, 0, 0); + break; + + case ArrowDirection.Up: + if (keyEvent.Control) + { + vector3 = new Vector3(0, 0, view3D.InteractionLayer.SnapGridDistance); + } + else + { + vector3 = new Vector3(0, view3D.InteractionLayer.SnapGridDistance, 0); + } + + break; + + case ArrowDirection.Down: + if (keyEvent.Control) + { + vector3 = new Vector3(0, 0, -view3D.InteractionLayer.SnapGridDistance); + } + else + { + vector3 = new Vector3(0, -view3D.InteractionLayer.SnapGridDistance, 0); + } + + break; + } + + var matrix = world.GetXYInViewRotation(item.GetCenter()); + + item.Translate(vector3.Transform(matrix)); + } + + private static void Offset3DView(View3DWidget view3D, Vector2 offset, TrackBallTransformType operation) + { + var center = view3D.TrackballTumbleWidget.LocalBounds.Center; + + view3D.TrackballTumbleWidget.TrackBallController.OnMouseDown(center, Matrix4X4.Identity, operation); + view3D.TrackballTumbleWidget.TrackBallController.OnMouseMove(center + offset); + view3D.TrackballTumbleWidget.TrackBallController.OnMouseUp(); + view3D.TrackballTumbleWidget.Invalidate(); + } + + public static async Task Initialize(SystemWindow systemWindow, Action reporter) + { + var loading = "Loading..."; +#if DEBUG + loading = null; +#endif + reporter?.Invoke(0.01, (loading != null) ? loading : "PlatformInit"); + AppContext.Platform.PlatformInit((status) => + { + reporter?.Invoke(0.01, (loading != null) ? loading : status); + }); + + // TODO: Appears to be unused and should be removed + // set this at startup so that we can tell next time if it got set to true in close + UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1; + + reporter?.Invoke(0.05, (loading != null) ? loading : "ApplicationController"); + var applicationController = ApplicationController.Instance; + + // Accessing any property on ProfileManager will run the static constructor and spin up the ProfileManager instance + reporter?.Invoke(0.2, (loading != null) ? loading : "ProfileManager"); + bool na2 = ProfileManager.Instance.IsGuestProfile; + + await ProfileManager.Instance.Initialize(); + + reporter?.Invoke(0.25, (loading != null) ? loading : "Initialize printer"); + + reporter?.Invoke(0.3, (loading != null) ? loading : "Plugins"); + ApplicationController.Plugins.InitializePlugins(systemWindow); + + reporter?.Invoke(0.4, (loading != null) ? loading : "MainView"); + applicationController.MainView = new MainViewWidget(applicationController.Theme); + + reporter?.Invoke(0.91, (loading != null) ? loading : "OnLoadActions"); + applicationController.OnLoadActions(); + + // Wired up to MainView.Load with the intent to fire startup actions and tasks in order with reporting + async void InitialWindowLoad(object s, EventArgs e) + { + try + { + PrinterSettings.SliceEngines["MatterSlice"] = new EngineMappingsMatterSlice(); + + // Initial load builds UI elements, then constructs workspace tabs as they're encountered in RestoreUserTabs() + await applicationController.RestoreUserTabs(); + + // Batch startup actions + await applicationController.Tasks.Execute( + "Finishing Startup".Localize(), + null, + (progress, cancellationToken) => + { + var status = new ProgressStatus(); + + int itemCount = ApplicationController.StartupActions.Count; + + double i = 1; + + foreach (var action in ApplicationController.StartupActions.OrderByDescending(t => t.Priority)) + { + status.Status = action.Title; + progress.Report(status); + + action.Action?.Invoke(); + status.Progress0To1 = i++ / itemCount; + progress.Report(status); + } + + return Task.CompletedTask; + }); + + // Batch execute startup tasks + foreach (var task in ApplicationController.StartupTasks.OrderByDescending(t => t.Priority)) + { + await applicationController.Tasks.Execute(task.Title, null, task.Action); + } + + + if (UserSettings.Instance.get(UserSettingsKey.ShownWelcomeMessage) != "false") + { + UiThread.RunOnIdle(() => + { + DialogWindow.Show(); + }); + } + } + catch + { + } + + // Unhook after execution + applicationController.MainView.Load -= InitialWindowLoad; + } + + // Hook after first draw + applicationController.MainView.Load += InitialWindowLoad; + + return applicationController.MainView; + } + + private static void ReportStartupProgress(double progress0To1, string section) + { + UiThread.RunOnIdle(() => + { + statusText.Text = section; + progressBar.RatioComplete = progress0To1; + progressPanel.Invalidate(); + + Console.WriteLine($"Time to '{lastSection}': {timer.ElapsedMilliseconds}"); + timer.Restart(); + + lastSection = section; + }); + } + } +} diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index b687b63ba..ed368255a 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -27,25 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; using global::MatterControl.Printing; -using Markdig.Agg; -using Markdig.Renderers.Agg; using MatterHackers.Agg; using MatterHackers.Agg.Font; using MatterHackers.Agg.Image; @@ -73,10 +55,24 @@ using MatterHackers.MatterControl.Tour; using MatterHackers.PolygonMesh; using MatterHackers.PolygonMesh.Processors; using MatterHackers.VectorMath; -using MatterHackers.VectorMath.TrackBall; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; [assembly: InternalsVisibleTo("MatterControl.Tests")] [assembly: InternalsVisibleTo("MatterControl.AutomationTests")] @@ -112,184 +108,6 @@ namespace MatterHackers.MatterControl Titillium, } - public class WorkspacesChangedEventArgs : EventArgs - { - public WorkspacesChangedEventArgs(PartWorkspace workspace, OperationType operation) - { - this.Operation = operation; - this.Workspace = workspace; - } - - public OperationType Operation { get; } - - public PartWorkspace Workspace { get; } - - public enum OperationType - { - Add, - Remove, - Restore - } - } - - public static class AppContext - { - /// - /// Gets or sets native platform features - /// - public static INativePlatformFeatures Platform { get; set; } - - public static MatterControlOptions Options { get; set; } = new MatterControlOptions(); - - public static bool IsLoading { get; internal set; } = true; - - /// - /// Gets the root SystemWindow - /// - public static SystemWindow RootSystemWindow { get; internal set; } - - public static ThemeConfig Theme => themeset.Theme; - - public static ThemeConfig MenuTheme => themeset.MenuTheme; - - private static ThemeSet themeset; - - public static ThemeSet ThemeSet => themeset; - - public static Dictionary ThemeProviders { get; } - - private static Dictionary themes = new Dictionary(); - - static AppContext() - { - ThemeProviders = new Dictionary(); - - string themesPath = Path.Combine("Themes", "System"); - - var staticData = AggContext.StaticData; - - // Load available themes from StaticData - if (staticData.DirectoryExists(themesPath)) - { - var themeFiles = staticData.GetDirectories(themesPath).SelectMany(d => staticData.GetFiles(d).Where(p => Path.GetExtension(p) == ".json")); - foreach (var themeFile in themeFiles) - { - themes[Path.GetFileNameWithoutExtension(themeFile)] = themeFile; - } - - foreach (var directoryTheme in AggContext.StaticData.GetDirectories(themesPath).Where(d => Path.GetFileName(d) != "Menus").Select(d => new DirectoryTheme(d))) - { - ThemeProviders.Add(directoryTheme.Name, directoryTheme); - } - } - - // Load theme - try - { - if (File.Exists(ProfileManager.Instance.ProfileThemeSetPath)) - { - themeset = JsonConvert.DeserializeObject(File.ReadAllText(ProfileManager.Instance.ProfileThemeSetPath)); - themeset.Theme.EnsureDefaults(); - - // If the serialized format is older than the current format, null and fall back to latest default below - if (themeset.SchemeVersion != ThemeSet.LatestSchemeVersion) - { - themeset = null; - } - } - } - catch { } - - if (themeset == null) - { - var themeProvider = ThemeProviders["Modern"]; - themeset = themeProvider.GetTheme("Modern-Dark"); - } - - DefaultThumbView.ThumbColor = new Color(themeset.Theme.TextColor, 30); - - ToolTipManager.CreateToolTip = MatterControlToolTipWidget; - } - - private static GuiWidget MatterControlToolTipWidget(string toolTipText) - { - var toolTipPopover = new ClickablePopover(ArrowDirection.Up, new BorderDouble(0, 0), 7, 0); - - var markdownWidegt = new MarkdownWidget(Theme, false) - { - HAnchor = HAnchor.Absolute, - VAnchor = VAnchor.Fit, - Width = 350 * GuiWidget.DeviceScale, - BackgroundColor = Theme.BackgroundColor, - Border = 1, - BorderColor = Color.Black, - }; - - markdownWidegt.Markdown = toolTipText; - markdownWidegt.Width = 350; - var maxLineWidth = markdownWidegt.Descendants().Max(i => i.MaxLineWidth); - markdownWidegt.Width = maxLineWidth + 15; - - return markdownWidegt; - } - - public static ThemeConfig LoadTheme(string themeName) - { - try - { - if (themes.TryGetValue(themeName, out string themePath)) - { - string json = AggContext.StaticData.ReadAllText(themePath); - - var themeConfig = JsonConvert.DeserializeObject(json); - themeConfig.EnsureDefaults(); - - return themeConfig; - } - } - catch - { - Console.WriteLine("Error loading theme: " + themeName); - } - - return new ThemeConfig(); - } - - public static void SetThemeAccentColor(Color accentColor) - { - themeset.SetAccentColor(accentColor); - AppContext.SetTheme(themeset); - } - - public static void SetTheme(ThemeSet themeSet) - { - themeset = themeSet; - - File.WriteAllText( - ProfileManager.Instance.ProfileThemeSetPath, - JsonConvert.SerializeObject( - themeset, - Formatting.Indented, - new JsonSerializerSettings - { - ContractResolver = new ThemeContractResolver() - })); - - UiThread.RunOnIdle(() => - { - UserSettings.Instance.set(UserSettingsKey.ActiveThemeName, themeset.Name); - - // Explicitly fire ReloadAll in response to user interaction - ApplicationController.Instance.ReloadAll().ConfigureAwait(false); - }); - } - - public class MatterControlOptions - { - public bool McwsTestEnvironment { get; set; } - } - } - public class ApplicationController { public event EventHandler ApplicationError; @@ -940,7 +758,7 @@ namespace MatterHackers.MatterControl new OperationGroup("Array") { Collapse = true, - TitleResolver = () => "Array".Localize(), + TitleResolver = () => "Array Options".Localize(), StickySelection = true, Operations = new List() { @@ -1382,10 +1200,14 @@ namespace MatterHackers.MatterControl { var frame = new ImageBuffer(size, size); var graphics = frame.NewGraphics2D(); - graphics.Render(new Stroke(new Arc(frame.Width / 2, frame.Height / 2, - size / 4 - strokeWidth / 2, size / 4 - strokeWidth / 2, + graphics.Render(new Stroke(new Arc(frame.Width / 2, + frame.Height / 2, + size / 4 - strokeWidth / 2, + size / 4 - strokeWidth / 2, MathHelper.Tau / frameCount * i, - MathHelper.Tau / 4 + MathHelper.Tau / frameCount * i), strokeWidth), color); + MathHelper.Tau / 4 + MathHelper.Tau / frameCount * i), + strokeWidth), + color); workingAnimation.AddImage(frame); } @@ -1485,7 +1307,6 @@ namespace MatterHackers.MatterControl AggContext.StaticData.LoadIcon(Path.Combine("Library", "history_folder.png")), () => new RootHistoryContainer())); - // Create a new library context for the SaveAs view this.LibraryTabContext = new LibraryConfig() { @@ -2162,7 +1983,7 @@ namespace MatterHackers.MatterControl [NamedTypeFace.Liberation_Mono] = TypeFace.LoadFrom(AggContext.StaticData.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg"))) }; - static object locker = new object(); + private static object locker = new object(); public static TypeFace GetTypeFace(NamedTypeFace namedTypeFace) { @@ -2808,7 +2629,6 @@ namespace MatterHackers.MatterControl // string json = await httpClient.GetStringAsync("https://matterhackers.github.io/MatterControl-Docs/Help/product-tour.json"); return JsonConvert.DeserializeObject>(json); - }, Path.Combine("OemSettings", "ProductTour.json")); } @@ -2816,11 +2636,11 @@ namespace MatterHackers.MatterControl return _productTour; } - public event EventHandler AddPrintersTabRightElement; + public event EventHandler ApplicationTopBarCreated; public void NotifyPrintersTabRightElement(GuiWidget sourceExentionArea) { - AddPrintersTabRightElement?.Invoke(this, new WidgetSourceEventArgs(sourceExentionArea)); + ApplicationTopBarCreated?.Invoke(this, new ApplicationTopBarCreatedEventArgs(sourceExentionArea)); // after adding content to the right side make sure we hold the space in the tab bar var leftChild = sourceExentionArea.Parent.Children.First(); @@ -3349,8 +3169,8 @@ namespace MatterHackers.MatterControl string markdownText = @"**Find more at MatterHackers** Supplies and accessories: -- [Filament](https://www.matterhackers.com/store/c/3d-printer-filament) -- [Bed Adhesives](https://www.matterhackers.com/store/c/3d-printer-adhesive) +- [Filament](https://www.matterhackers.com/store/c/3d-printer-filament) +- [Bed Adhesives](https://www.matterhackers.com/store/c/3d-printer-adhesive) - [Digital Designs](https://www.matterhackers.com/store/c/digital-designs) Support and tutorials: @@ -3547,866 +3367,9 @@ Support and tutorials: } } - public class WidgetSourceEventArgs : EventArgs + public enum ReportSeverity2 { - public GuiWidget Source { get; } - - public WidgetSourceEventArgs(GuiWidget source) - { - this.Source = source; - } + Warning, + Error } - - public class DragDropData - { - public View3DWidget View3DWidget { get; set; } - - public ISceneContext SceneContext { get; set; } - } - - public class RunningTaskDetails : IProgress - { - public event EventHandler ProgressChanged; - - public Func DetailsItemAction { get; set; } - - private CancellationTokenSource tokenSource; - - private bool? _isExpanded = null; - - public RunningTaskDetails(CancellationTokenSource tokenSource) - { - this.tokenSource = tokenSource; - } - - public string Title { get; set; } - - public object Owner { get; set; } - - public RunningTaskOptions Options { get; internal set; } - - public bool IsExpanded - { - get - { - if (_isExpanded == null) - { - if (this.Options is RunningTaskOptions options - && !string.IsNullOrWhiteSpace(options.ExpansionSerializationKey)) - { - string dbValue = UserSettings.Instance.get(options.ExpansionSerializationKey); - _isExpanded = dbValue != "0"; - } - else - { - _isExpanded = false; - } - } - - return _isExpanded ?? false; - } - - set - { - _isExpanded = value; - - if (this.Options?.ExpansionSerializationKey is string expansionKey - && !string.IsNullOrWhiteSpace(expansionKey)) - { - UserSettings.Instance.set(expansionKey, (_isExpanded ?? false) ? "1" : "0"); - } - } - } - - public void Report(ProgressStatus progressStatus) - { - this.ProgressChanged?.Invoke(this, progressStatus); - } - - public void CancelTask() - { - this.tokenSource.Cancel(); - } - } - - public class RunningTaskOptions - { - /// - /// Gets or sets the Rich progress widget to be shown when expanded - /// - public Func RichProgressWidget { get; set; } - - /// - /// Gets or sets the database key used to round trip expansion state - /// - public string ExpansionSerializationKey { get; set; } - - /// - /// Gets or sets the state of the pause resume button - /// - public Func IsPaused { get; set; } - - public Action PauseAction { get; set; } - - public Action ResumeAction { get; set; } - - public Action StopAction { get; set; } - - public string StopToolTip { get; set; } = "Cancel".Localize(); - - public string ResumeToolTip { get; set; } = "Resume".Localize(); - - public string PauseToolTip { get; set; } = "Pause".Localize(); - - /// - /// Gets or sets a value indicating whether indicates if the task should suppress pause/resume/stop operations - /// - public bool ReadOnlyReporting { get; set; } = false; - } - - public class RunningTasksConfig - { - public event EventHandler TasksChanged; - - private ObservableCollection executingTasks = new ObservableCollection(); - - public IEnumerable RunningTasks => executingTasks.ToList(); - - public RunningTasksConfig() - { - executingTasks.CollectionChanged += (s, e) => - { - UiThread.RunOnIdle(() => this.TasksChanged?.Invoke(this, null)); - }; - } - - public Task Execute(string taskTitle, object owner, Func, CancellationToken, Task> func, RunningTaskOptions taskActions = null) - { - var tokenSource = new CancellationTokenSource(); - - var taskDetails = new RunningTaskDetails(tokenSource) - { - Options = taskActions, - Title = taskTitle, - Owner = owner, - }; - - executingTasks.Add(taskDetails); - - return Task.Run(async () => - { - try - { - await func?.Invoke(taskDetails, tokenSource.Token); - } - catch - { - } - - UiThread.RunOnIdle(() => - { - executingTasks.Remove(taskDetails); - }); - }); - } - } - - public enum ReportSeverity2 { Warning, Error } - - public class MiniTouchScreen - { - public bool Enabled - { - get - { - return !string.IsNullOrEmpty(Make); - } - } - - public string Make { get; set; } - - public string Model { get; set; } - } - - public static class Application - { - private static ProgressBar progressBar; - private static TextWidget statusText; - private static FlowLayoutWidget progressPanel; - private static string lastSection = ""; - private static Stopwatch timer; - - public static bool EnableF5Collect { get; set; } - - public static bool EnableNetworkTraffic { get; set; } = true; - - public static MiniTouchScreen MiniTouchScreen { get; set; } = new MiniTouchScreen(); - - public static SystemWindow LoadRootWindow(int width, int height) - { - timer = Stopwatch.StartNew(); - - if (false) - { - // set the default font - AggContext.DefaultFont = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Regular); - AggContext.DefaultFontBold = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Bold); - AggContext.DefaultFontItalic = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Italic); - AggContext.DefaultFontBoldItalic = ApplicationController.GetTypeFace(NamedTypeFace.Nunito_Bold_Italic); - } - - var systemWindow = new RootSystemWindow(width, height); - - var overlay = new GuiWidget() - { - BackgroundColor = AppContext.Theme.BackgroundColor, - }; - overlay.AnchorAll(); - - systemWindow.AddChild(overlay); - - var mutedAccentColor = AppContext.Theme.SplashAccentColor; - - var spinner = new LogoSpinner(overlay, rotateX: -0.05) - { - MeshColor = mutedAccentColor - }; - - progressPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) - { - Position = new Vector2(0, height * .25), - HAnchor = HAnchor.Center | HAnchor.Fit, - VAnchor = VAnchor.Fit, - MinimumSize = new Vector2(400, 100), - Margin = new BorderDouble(0, 0, 0, 200) - }; - overlay.AddChild(progressPanel); - - progressPanel.AddChild(statusText = new TextWidget("", textColor: AppContext.Theme.TextColor) - { - MinimumSize = new Vector2(200, 30), - HAnchor = HAnchor.Center, - AutoExpandBoundsToText = true - }); - - progressPanel.AddChild(progressBar = new ProgressBar() - { - FillColor = mutedAccentColor, - BorderColor = Color.Gray, // theme.BorderColor75, - Height = 11, - Width = 230, - HAnchor = HAnchor.Center, - VAnchor = VAnchor.Absolute - }); - - AppContext.RootSystemWindow = systemWindow; - - // hook up a keyboard watcher to rout keys when not handled by children - - systemWindow.KeyPressed += SystemWindow_KeyPressed; - - systemWindow.KeyDown += (s, keyEvent) => - { - var view3D = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); - var printerTabPage = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); - var offsetDist = 50; - var arrowKeyOperation = keyEvent.Shift ? TrackBallTransformType.Translation : TrackBallTransformType.Rotation; - - var gcode2D = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); - - if (keyEvent.KeyCode == Keys.F1) - { - ApplicationController.Instance.ActivateHelpTab(); - } - - if (EnableF5Collect - && keyEvent.KeyCode == Keys.F5) - { - GC.Collect(); - systemWindow.Invalidate(); - } - - if (!keyEvent.Handled - && gcode2D != null) - { - switch (keyEvent.KeyCode) - { - case Keys.Oemplus: - case Keys.Add: - if (keyEvent.Control) - { - // Zoom out - gcode2D.Zoom(1.2); - keyEvent.Handled = true; - } - - break; - - case Keys.OemMinus: - case Keys.Subtract: - if (keyEvent.Control) - { - // Zoom in - gcode2D.Zoom(.8); - keyEvent.Handled = true; - } - - break; - } - } - - if (!keyEvent.Handled - && view3D != null) - { - switch (keyEvent.KeyCode) - { - case Keys.C: - if (keyEvent.Control) - { - view3D.Scene.Copy(); - keyEvent.Handled = true; - } - - break; - - case Keys.P: - if (keyEvent.Control) - { - view3D.PushToPrinterAndPrint(); - } - - break; - - case Keys.X: - if (keyEvent.Control) - { - view3D.Scene.Cut(); - keyEvent.Handled = true; - } - - break; - - case Keys.Y: - if (keyEvent.Control) - { - view3D.Scene.UndoBuffer.Redo(); - keyEvent.Handled = true; - } - - break; - - case Keys.A: - if (keyEvent.Control) - { - view3D.SelectAll(); - keyEvent.Handled = true; - } - - break; - - case Keys.S: - if (keyEvent.Control) - { - view3D.Save(); - keyEvent.Handled = true; - } - - break; - - case Keys.V: - if (keyEvent.Control) - { - view3D.sceneContext.Paste(); - keyEvent.Handled = true; - } - - break; - - case Keys.Oemplus: - case Keys.Add: - if (keyEvent.Control) - { - // Zoom out - Offset3DView(view3D, new Vector2(0, offsetDist), TrackBallTransformType.Scale); - keyEvent.Handled = true; - } - - break; - - case Keys.OemMinus: - case Keys.Subtract: - if (keyEvent.Control) - { - // Zoom in - Offset3DView(view3D, new Vector2(0, -offsetDist), TrackBallTransformType.Scale); - keyEvent.Handled = true; - } - - break; - - case Keys.Z: - if (keyEvent.Control) - { - if (keyEvent.Shift) - { - view3D.Scene.Redo(); - } - else - { - // undo last operation - view3D.Scene.Undo(); - } - - keyEvent.Handled = true; - } - - break; - - case Keys.Insert: - if (keyEvent.Shift) - { - view3D.sceneContext.Paste(); - keyEvent.Handled = true; - } - - break; - - case Keys.Delete: - case Keys.Back: - view3D.Scene.DeleteSelection(); - keyEvent.Handled = true; - keyEvent.SuppressKeyPress = true; - break; - - case Keys.Escape: - if (view3D.CurrentSelectInfo.DownOnPart) - { - view3D.CurrentSelectInfo.DownOnPart = false; - - view3D.Scene.SelectedItem.Matrix = view3D.TransformOnMouseDown; - - keyEvent.Handled = true; - keyEvent.SuppressKeyPress = true; - } - - foreach (var interactionVolume in view3D.InteractionLayer.InteractionVolumes) - { - interactionVolume.CancelOperation(); - } - - break; - - case Keys.Left: - if (keyEvent.Control - && printerTabPage != null - && !printerTabPage.sceneContext.ViewState.ModelView) - { - // Decrement slider - printerTabPage.LayerFeaturesIndex -= 1; - } - else - { - if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) - { - NudgeItem(view3D, object3D, ArrowDirection.Left, keyEvent); - } - else - { - // move or rotate view left - Offset3DView(view3D, new Vector2(-offsetDist, 0), arrowKeyOperation); - } - } - - keyEvent.Handled = true; - keyEvent.SuppressKeyPress = true; - break; - - case Keys.Right: - if (keyEvent.Control - && printerTabPage != null - && !printerTabPage.sceneContext.ViewState.ModelView) - { - // Increment slider - printerTabPage.LayerFeaturesIndex += 1; - } - else - { - if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) - { - NudgeItem(view3D, object3D, ArrowDirection.Right, keyEvent); - } - else - { - // move or rotate view right - Offset3DView(view3D, new Vector2(offsetDist, 0), arrowKeyOperation); - } - } - - keyEvent.Handled = true; - keyEvent.SuppressKeyPress = true; - break; - - case Keys.Up: - if (view3D.Printer != null - && printerTabPage != null - && view3D.Printer.ViewState.ViewMode != PartViewMode.Model) - { - printerTabPage.LayerScrollbar.Value += 1; - } - else - { - if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) - { - NudgeItem(view3D, object3D, ArrowDirection.Up, keyEvent); - } - else - { - Offset3DView(view3D, new Vector2(0, offsetDist), arrowKeyOperation); - } - } - - keyEvent.Handled = true; - keyEvent.SuppressKeyPress = true; - break; - - case Keys.Down: - if (view3D.Printer != null - && printerTabPage != null - && view3D.Printer.ViewState.ViewMode != PartViewMode.Model) - { - printerTabPage.LayerScrollbar.Value -= 1; - } - else - { - if (view3D.sceneContext.Scene.SelectedItem is IObject3D object3D) - { - NudgeItem(view3D, object3D, ArrowDirection.Down, keyEvent); - } - else - { - Offset3DView(view3D, new Vector2(0, -offsetDist), arrowKeyOperation); - } - } - - keyEvent.Handled = true; - keyEvent.SuppressKeyPress = true; - break; - } - } - }; - - // Hook SystemWindow load and spin up MatterControl once we've hit first draw - systemWindow.Load += (s, e) => - { - // Show the End User License Agreement if it has not been shown (on windows it is shown in the installer) - if (AggContext.OperatingSystem != OSType.Windows - && UserSettings.Instance.get(UserSettingsKey.SoftwareLicenseAccepted) != "true") - { - var eula = new LicenseAgreementPage(LoadMC) - { - Margin = new BorderDouble(5) - }; - - systemWindow.AddChild(eula); - } - else - { - LoadMC(); - } - }; - - void LoadMC() - { - ReportStartupProgress(0.02, "First draw->RunOnIdle"); - - // UiThread.RunOnIdle(() => - Task.Run(async () => - { - try - { - ReportStartupProgress(0.15, "MatterControlApplication.Initialize"); - - ApplicationController.LoadTranslationMap(); - - var mainView = await Initialize(systemWindow, (progress0To1, status) => - { - ReportStartupProgress(0.2 + progress0To1 * 0.7, status); - }); - - ReportStartupProgress(0.9, "AddChild->MainView"); - systemWindow.AddChild(mainView, 0); - - ReportStartupProgress(1, ""); - systemWindow.BackgroundColor = Color.Transparent; - overlay.Close(); - } - catch (Exception ex) - { - UiThread.RunOnIdle(() => - { - statusText.Visible = false; - - var errorTextColor = Color.White; - - progressPanel.Margin = 0; - progressPanel.VAnchor = VAnchor.Center | VAnchor.Fit; - progressPanel.BackgroundColor = Color.DarkGray; - progressPanel.Padding = 20; - progressPanel.Border = 1; - progressPanel.BorderColor = Color.Red; - - var theme = new ThemeConfig(); - - progressPanel.AddChild( - new TextWidget("Startup Failure".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: errorTextColor)); - - progressPanel.AddChild( - new TextWidget(ex.Message, pointSize: theme.FontSize9, textColor: errorTextColor)); - - var closeButton = new TextButton("Close", theme) - { - BackgroundColor = theme.SlightShade, - HAnchor = HAnchor.Right, - VAnchor = VAnchor.Absolute - }; - closeButton.Click += (s1, e1) => - { - systemWindow.Close(); - }; - - spinner.SpinLogo = false; - progressBar.Visible = false; - - progressPanel.AddChild(closeButton); - }); - } - - AppContext.IsLoading = false; - }); - } - - ReportStartupProgress(0, "ShowAsSystemWindow"); - - return systemWindow; - } - - private static void SystemWindow_KeyPressed(object sender, KeyPressEventArgs keyEvent) - { - if (sender is SystemWindow systemWindow) - { - var view3D = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); - var printerTabPage = systemWindow.Descendants().Where((v) => v.ActuallyVisibleOnScreen()).FirstOrDefault(); - var offsetDist = 50; - - if (!keyEvent.Handled - && view3D != null) - { - switch (keyEvent.KeyChar) - { - case 'w': - case 'W': - view3D.ResetView(); - keyEvent.Handled = true; - break; - - case ' ': - view3D.Scene.ClearSelection(); - keyEvent.Handled = true; - break; - } - } - } - } - - private static void NudgeItem(View3DWidget view3D, IObject3D item, ArrowDirection arrowDirection, KeyEventArgs keyEvent) - { - - var world = view3D.InteractionLayer.World; - - var vector3 = default(Vector3); - - // TODO: analyze the view and adjust movements to be relative to the current perspective - // - // Naive movements in Identity space - switch (arrowDirection) - { - case ArrowDirection.Left: - vector3 = new Vector3(-view3D.InteractionLayer.SnapGridDistance, 0, 0); - break; - - case ArrowDirection.Right: - vector3 = new Vector3(view3D.InteractionLayer.SnapGridDistance, 0, 0); - break; - - case ArrowDirection.Up: - if (keyEvent.Control) - { - vector3 = new Vector3(0, 0, view3D.InteractionLayer.SnapGridDistance); - } - else - { - vector3 = new Vector3(0, view3D.InteractionLayer.SnapGridDistance, 0); - } - - break; - - case ArrowDirection.Down: - if (keyEvent.Control) - { - vector3 = new Vector3(0, 0, -view3D.InteractionLayer.SnapGridDistance); - } - else - { - vector3 = new Vector3(0, -view3D.InteractionLayer.SnapGridDistance, 0); - } - - break; - } - - var matrix = world.GetXYInViewRotation(item.GetCenter()); - - item.Translate(vector3.Transform(matrix)); - } - - private static void Offset3DView(View3DWidget view3D, Vector2 offset, TrackBallTransformType operation) - { - var center = view3D.TrackballTumbleWidget.LocalBounds.Center; - - view3D.TrackballTumbleWidget.TrackBallController.OnMouseDown(center, Matrix4X4.Identity, operation); - view3D.TrackballTumbleWidget.TrackBallController.OnMouseMove(center + offset); - view3D.TrackballTumbleWidget.TrackBallController.OnMouseUp(); - view3D.TrackballTumbleWidget.Invalidate(); - } - - public static async Task Initialize(SystemWindow systemWindow, Action reporter) - { - var loading = "Loading..."; -#if DEBUG - loading = null; -#endif - reporter?.Invoke(0.01, (loading != null) ? loading : "PlatformInit"); - AppContext.Platform.PlatformInit((status) => - { - reporter?.Invoke(0.01, (loading != null) ? loading : status); - }); - - // TODO: Appears to be unused and should be removed - // set this at startup so that we can tell next time if it got set to true in close - UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1; - - reporter?.Invoke(0.05, (loading != null) ? loading : "ApplicationController"); - var applicationController = ApplicationController.Instance; - - // Accessing any property on ProfileManager will run the static constructor and spin up the ProfileManager instance - reporter?.Invoke(0.2, (loading != null) ? loading : "ProfileManager"); - bool na2 = ProfileManager.Instance.IsGuestProfile; - - await ProfileManager.Instance.Initialize(); - - reporter?.Invoke(0.25, (loading != null) ? loading : "Initialize printer"); - - reporter?.Invoke(0.3, (loading != null) ? loading : "Plugins"); - ApplicationController.Plugins.InitializePlugins(systemWindow); - - reporter?.Invoke(0.4, (loading != null) ? loading : "MainView"); - applicationController.MainView = new MainViewWidget(applicationController.Theme); - - reporter?.Invoke(0.91, (loading != null) ? loading : "OnLoadActions"); - applicationController.OnLoadActions(); - - // Wired up to MainView.Load with the intent to fire startup actions and tasks in order with reporting - async void initialWindowLoad(object s, EventArgs e) - { - try - { - PrinterSettings.SliceEngines["MatterSlice"] = new EngineMappingsMatterSlice(); - - // Initial load builds UI elements, then constructs workspace tabs as they're encountered in RestoreUserTabs() - await applicationController.RestoreUserTabs(); - - // Batch startup actions - await applicationController.Tasks.Execute( - "Finishing Startup".Localize(), - null, - (progress, cancellationToken) => - { - var status = new ProgressStatus(); - - int itemCount = ApplicationController.StartupActions.Count; - - double i = 1; - - foreach (var action in ApplicationController.StartupActions.OrderByDescending(t => t.Priority)) - { - status.Status = action.Title; - progress.Report(status); - - action.Action?.Invoke(); - status.Progress0To1 = i++ / itemCount; - progress.Report(status); - } - - return Task.CompletedTask; - }); - - // Batch execute startup tasks - foreach (var task in ApplicationController.StartupTasks.OrderByDescending(t => t.Priority)) - { - await applicationController.Tasks.Execute(task.Title, null, task.Action); - } - - - if (UserSettings.Instance.get(UserSettingsKey.ShownWelcomeMessage) != "false") - { - UiThread.RunOnIdle(() => - { - DialogWindow.Show(); - }); - } - } - catch - { - } - - // Unhook after execution - applicationController.MainView.Load -= initialWindowLoad; - } - - // Hook after first draw - applicationController.MainView.Load += initialWindowLoad; - - return applicationController.MainView; - } - - private static void ReportStartupProgress(double progress0To1, string section) - { - UiThread.RunOnIdle(() => - { - statusText.Text = section; - progressBar.RatioComplete = progress0To1; - progressPanel.Invalidate(); - - Console.WriteLine($"Time to '{lastSection}': {timer.ElapsedMilliseconds}"); - timer.Restart(); - - lastSection = section; - }); - } - } - - public class ContentStoreConverter : JsonConverter - { - public override bool CanWrite => false; - - public override IContentStore ReadJson(JsonReader reader, Type objectType, IContentStore existingValue, bool hasExistingValue, JsonSerializer serializer) - { - var token = JToken.Load(reader); - - return null; - } - - public override void WriteJson(JsonWriter writer, IContentStore value, JsonSerializer serializer) - { - } - } -} +} \ No newline at end of file diff --git a/MatterControlLib/ApplicationView/ApplicationTopBarCreatedEventArgs.cs b/MatterControlLib/ApplicationView/ApplicationTopBarCreatedEventArgs.cs new file mode 100644 index 000000000..bd5d39fc7 --- /dev/null +++ b/MatterControlLib/ApplicationView/ApplicationTopBarCreatedEventArgs.cs @@ -0,0 +1,50 @@ +/* +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; +using System.Runtime.CompilerServices; +using MatterHackers.Agg.UI; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class ApplicationTopBarCreatedEventArgs : EventArgs + { + public GuiWidget Source { get; } + + public ApplicationTopBarCreatedEventArgs(GuiWidget source) + { + this.Source = source; + } + } +} diff --git a/MatterControlLib/ApplicationView/BedConfig.cs b/MatterControlLib/ApplicationView/Config/BedConfig.cs similarity index 96% rename from MatterControlLib/ApplicationView/BedConfig.cs rename to MatterControlLib/ApplicationView/Config/BedConfig.cs index f24aa54bf..2ce8a5a5d 100644 --- a/MatterControlLib/ApplicationView/BedConfig.cs +++ b/MatterControlLib/ApplicationView/Config/BedConfig.cs @@ -28,30 +28,29 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; +using System.Threading; using System.Threading.Tasks; using MatterControl.Printing; +using MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.DataConverters3D; +using MatterHackers.GCodeVisualizer; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MeshVisualizer; +using MatterHackers.PolygonMesh; +using MatterHackers.VectorMath; using Newtonsoft.Json; namespace MatterHackers.MatterControl { - using System.Collections.Generic; - using System.Linq; - using System.Threading; - using MatterHackers.Agg; - using MatterHackers.DataConverters3D; - using MatterHackers.GCodeVisualizer; - using MatterHackers.Localizations; - using MatterHackers.MatterControl.DataStorage; - using MatterHackers.MatterControl.Library; - using MatterHackers.MatterControl.PartPreviewWindow; - using MatterHackers.MeshVisualizer; - using MatterHackers.PolygonMesh; - using MatterHackers.VectorMath; - public class BedConfig : ISceneContext { public event EventHandler ActiveLayerChanged; @@ -127,7 +126,7 @@ namespace MatterHackers.MatterControl /// /// Load content from the given EditContext into the current one /// - /// + /// The context to load into. /// public async Task LoadIntoCurrent(EditContext editContext) { @@ -353,6 +352,7 @@ namespace MatterHackers.MatterControl } private GCodeFile loadedGCode; + public GCodeFile LoadedGCode { get => loadedGCode; @@ -506,7 +506,7 @@ namespace MatterHackers.MatterControl public string ContentType { get; private set; } /// - /// Return the axis aligned bounding box of the bed + /// Gets the axis aligned bounding box of the bed /// public AxisAlignedBoundingBox Aabb { @@ -607,7 +607,8 @@ namespace MatterHackers.MatterControl new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity), new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity), new Vector4(multiplier, multiplier, multiplier, multiplier), - cancellationToken, progressReporter); + cancellationToken, + progressReporter); this.GCodeRenderer = new GCodeRenderer(loadedGCode) { diff --git a/MatterControlLib/ApplicationView/ExtensionsConfig.cs b/MatterControlLib/ApplicationView/Config/ExtensionsConfig.cs similarity index 89% rename from MatterControlLib/ApplicationView/ExtensionsConfig.cs rename to MatterControlLib/ApplicationView/Config/ExtensionsConfig.cs index da418ba35..101eb347e 100644 --- a/MatterControlLib/ApplicationView/ExtensionsConfig.cs +++ b/MatterControlLib/ApplicationView/Config/ExtensionsConfig.cs @@ -30,6 +30,10 @@ either expressed or implied, of the FreeBSD Project. using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using MatterHackers.DataConverters3D; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MeshVisualizer; [assembly: InternalsVisibleTo("MatterControl.Tests")] [assembly: InternalsVisibleTo("MatterControl.AutomationTests")] @@ -37,24 +41,18 @@ using System.Runtime.CompilerServices; namespace MatterHackers.MatterControl { - using MatterHackers.DataConverters3D; - using MatterHackers.MatterControl.Library; - using MatterHackers.MatterControl.PartPreviewWindow; - using MatterHackers.MeshVisualizer; - using Newtonsoft.Json.Linq; - public class ExtensionsConfig { private List _iaVolumeProviders = new List(); private LibraryConfig libraryConfig; - //private List _IObject3DEditorProviders = new List() - //{ - // new IntersectionEditor(), - // new SubtractEditor(), - // new SubtractAndReplace() - //}; + // private List _IObject3DEditorProviders = new List() + // { + // new IntersectionEditor(), + // new SubtractEditor(), + // new SubtractAndReplace() + // }; public ExtensionsConfig(LibraryConfig libraryConfig) { @@ -83,6 +81,7 @@ namespace MatterHackers.MatterControl { _iaVolumeProviders.Add(volumeProvider); } + public void Register(IObject3DEditor object3DEditor) { this.MapTypesToEditor(object3DEditor); diff --git a/MatterControlLib/ApplicationView/PrinterConfig.cs b/MatterControlLib/ApplicationView/Config/PrinterConfig.cs similarity index 100% rename from MatterControlLib/ApplicationView/PrinterConfig.cs rename to MatterControlLib/ApplicationView/Config/PrinterConfig.cs diff --git a/MatterControlLib/ApplicationView/Config/RunningTasksConfig.cs b/MatterControlLib/ApplicationView/Config/RunningTasksConfig.cs new file mode 100644 index 000000000..8250c9b5e --- /dev/null +++ b/MatterControlLib/ApplicationView/Config/RunningTasksConfig.cs @@ -0,0 +1,134 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class RunningTasksConfig + { + public event EventHandler TasksChanged; + + private ObservableCollection executingTasks = new ObservableCollection(); + + public IEnumerable RunningTasks => executingTasks.ToList(); + + public RunningTasksConfig() + { + executingTasks.CollectionChanged += (s, e) => + { + UiThread.RunOnIdle(() => this.TasksChanged?.Invoke(this, null)); + }; + } + + public Task Execute(string taskTitle, object owner, Func, CancellationToken, Task> func, RunningTaskOptions taskActions = null) + { + var tokenSource = new CancellationTokenSource(); + + var taskDetails = new RunningTaskDetails(tokenSource) + { + Options = taskActions, + Title = taskTitle, + Owner = owner, + }; + + executingTasks.Add(taskDetails); + + return Task.Run(async () => + { + try + { + await func?.Invoke(taskDetails, tokenSource.Token); + } + catch + { + } + + UiThread.RunOnIdle(() => + { + executingTasks.Remove(taskDetails); + }); + }); + } + } +} diff --git a/MatterControlLib/ApplicationView/ThumbnailsConfig.cs b/MatterControlLib/ApplicationView/Config/ThumbnailsConfig.cs similarity index 100% rename from MatterControlLib/ApplicationView/ThumbnailsConfig.cs rename to MatterControlLib/ApplicationView/Config/ThumbnailsConfig.cs diff --git a/MatterControlLib/ApplicationView/View3DConfig.cs b/MatterControlLib/ApplicationView/Config/View3DConfig.cs similarity index 100% rename from MatterControlLib/ApplicationView/View3DConfig.cs rename to MatterControlLib/ApplicationView/Config/View3DConfig.cs diff --git a/MatterControlLib/ApplicationView/ContentStoreConverter.cs b/MatterControlLib/ApplicationView/ContentStoreConverter.cs new file mode 100644 index 000000000..f554a8336 --- /dev/null +++ b/MatterControlLib/ApplicationView/ContentStoreConverter.cs @@ -0,0 +1,103 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class ContentStoreConverter : JsonConverter + { + public override bool CanWrite => false; + + public override IContentStore ReadJson(JsonReader reader, Type objectType, IContentStore existingValue, bool hasExistingValue, JsonSerializer serializer) + { + var token = JToken.Load(reader); + + return null; + } + + public override void WriteJson(JsonWriter writer, IContentStore value, JsonSerializer serializer) + { + } + } +} diff --git a/MatterControlLib/ApplicationView/DragDropData.cs b/MatterControlLib/ApplicationView/DragDropData.cs new file mode 100644 index 000000000..085a40b7d --- /dev/null +++ b/MatterControlLib/ApplicationView/DragDropData.cs @@ -0,0 +1,94 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class DragDropData + { + public View3DWidget View3DWidget { get; set; } + + public ISceneContext SceneContext { get; set; } + } +} diff --git a/MatterControlLib/ApplicationView/MiniTouchScreen.cs b/MatterControlLib/ApplicationView/MiniTouchScreen.cs new file mode 100644 index 000000000..e8e6f328c --- /dev/null +++ b/MatterControlLib/ApplicationView/MiniTouchScreen.cs @@ -0,0 +1,102 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class MiniTouchScreen + { + public bool Enabled + { + get + { + return !string.IsNullOrEmpty(Make); + } + } + + public string Make { get; set; } + + public string Model { get; set; } + } +} diff --git a/MatterControlLib/ApplicationView/RunningTasks/RunningTaskDetails.cs b/MatterControlLib/ApplicationView/RunningTasks/RunningTaskDetails.cs new file mode 100644 index 000000000..881b81cce --- /dev/null +++ b/MatterControlLib/ApplicationView/RunningTasks/RunningTaskDetails.cs @@ -0,0 +1,152 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class RunningTaskDetails : IProgress + { + public event EventHandler ProgressChanged; + + public Func DetailsItemAction { get; set; } + + private CancellationTokenSource tokenSource; + + private bool? _isExpanded = null; + + public RunningTaskDetails(CancellationTokenSource tokenSource) + { + this.tokenSource = tokenSource; + } + + public string Title { get; set; } + + public object Owner { get; set; } + + public RunningTaskOptions Options { get; internal set; } + + public bool IsExpanded + { + get + { + if (_isExpanded == null) + { + if (this.Options is RunningTaskOptions options + && !string.IsNullOrWhiteSpace(options.ExpansionSerializationKey)) + { + string dbValue = UserSettings.Instance.get(options.ExpansionSerializationKey); + _isExpanded = dbValue != "0"; + } + else + { + _isExpanded = false; + } + } + + return _isExpanded ?? false; + } + + set + { + _isExpanded = value; + + if (this.Options?.ExpansionSerializationKey is string expansionKey + && !string.IsNullOrWhiteSpace(expansionKey)) + { + UserSettings.Instance.set(expansionKey, (_isExpanded ?? false) ? "1" : "0"); + } + } + } + + public void Report(ProgressStatus progressStatus) + { + this.ProgressChanged?.Invoke(this, progressStatus); + } + + public void CancelTask() + { + this.tokenSource.Cancel(); + } + } +} diff --git a/MatterControlLib/ApplicationView/RunningTasks/RunningTaskOptions.cs b/MatterControlLib/ApplicationView/RunningTasks/RunningTaskOptions.cs new file mode 100644 index 000000000..58a8b01e3 --- /dev/null +++ b/MatterControlLib/ApplicationView/RunningTasks/RunningTaskOptions.cs @@ -0,0 +1,122 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class RunningTaskOptions + { + /// + /// Gets or sets the Rich progress widget to be shown when expanded + /// + public Func RichProgressWidget { get; set; } + + /// + /// Gets or sets the database key used to round trip expansion state + /// + public string ExpansionSerializationKey { get; set; } + + /// + /// Gets or sets the state of the pause resume button + /// + public Func IsPaused { get; set; } + + public Action PauseAction { get; set; } + + public Action ResumeAction { get; set; } + + public Action StopAction { get; set; } + + public string StopToolTip { get; set; } = "Cancel".Localize(); + + public string ResumeToolTip { get; set; } = "Resume".Localize(); + + public string PauseToolTip { get; set; } = "Pause".Localize(); + + /// + /// Gets or sets a value indicating whether indicates if the task should suppress pause/resume/stop operations + /// + public bool ReadOnlyReporting { get; set; } = false; + } +} diff --git a/MatterControlLib/ApplicationView/WorkspacesChangedEventArgs.cs b/MatterControlLib/ApplicationView/WorkspacesChangedEventArgs.cs new file mode 100644 index 000000000..8f1a76e83 --- /dev/null +++ b/MatterControlLib/ApplicationView/WorkspacesChangedEventArgs.cs @@ -0,0 +1,107 @@ +/* +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; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using global::MatterControl.Printing; +using Markdig.Agg; +using Markdig.Renderers.Agg; +using MatterHackers.Agg; +using MatterHackers.Agg.Font; +using MatterHackers.Agg.Image; +using MatterHackers.Agg.Platform; +using MatterHackers.Agg.UI; +using MatterHackers.Agg.VertexSource; +using MatterHackers.DataConverters3D; +using MatterHackers.DataConverters3D.UndoCommands; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.CustomWidgets; +using MatterHackers.MatterControl.DataStorage; +using MatterHackers.MatterControl.DesignTools; +using MatterHackers.MatterControl.DesignTools.Operations; +using MatterHackers.MatterControl.Extensibility; +using MatterHackers.MatterControl.Library; +using MatterHackers.MatterControl.PartPreviewWindow; +using MatterHackers.MatterControl.PartPreviewWindow.View3D; +using MatterHackers.MatterControl.Plugins; +using MatterHackers.MatterControl.PrinterCommunication; +using MatterHackers.MatterControl.PrinterControls.PrinterConnections; +using MatterHackers.MatterControl.PrintQueue; +using MatterHackers.MatterControl.SettingsManagement; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.MatterControl.Tour; +using MatterHackers.PolygonMesh; +using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; +using MatterHackers.VectorMath.TrackBall; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; + +[assembly: InternalsVisibleTo("MatterControl.Tests")] +[assembly: InternalsVisibleTo("MatterControl.AutomationTests")] +[assembly: InternalsVisibleTo("CloudServices.Tests")] + +namespace MatterHackers.MatterControl +{ + + public class WorkspacesChangedEventArgs : EventArgs + { + public WorkspacesChangedEventArgs(PartWorkspace workspace, OperationType operation) + { + this.Operation = operation; + this.Workspace = workspace; + } + + public OperationType Operation { get; } + + public PartWorkspace Workspace { get; } + + public enum OperationType + { + Add, + Remove, + Restore + } + } +} diff --git a/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs index c149178d0..aa3b937c3 100644 --- a/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/RotateControls/RotateCornerControl.cs @@ -265,7 +265,7 @@ namespace MatterHackers.Plugins.EditorTools return bestZCornerPosition; } - public override void OnMouseDown(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { InteractionContext.Scene.DrawSelection = false; @@ -310,7 +310,7 @@ namespace MatterHackers.Plugins.EditorTools base.OnMouseDown(mouseEvent3D); } - public override void OnMouseMove(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseMove(Mouse3DEventArgs mouseEvent3D) { IObject3D selectedItem = RootSelection; if (selectedItem != null) @@ -415,7 +415,7 @@ namespace MatterHackers.Plugins.EditorTools base.OnMouseMove(mouseEvent3D); } - public override void OnMouseUp(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { InteractionContext.Scene.DrawSelection = true; // if we rotated it diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs index 89a94fbab..1919ad855 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleCornerControl.cs @@ -226,7 +226,7 @@ namespace MatterHackers.Plugins.EditorTools return SetBottomControlHeight(originalSelectedBounds, cornerPosition); } - public override void OnMouseDown(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { var selectedItem = RootSelection; ActiveSelectedItem = selectedItem; @@ -251,7 +251,7 @@ namespace MatterHackers.Plugins.EditorTools base.OnMouseDown(mouseEvent3D); } - public override void OnMouseMove(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseMove(Mouse3DEventArgs mouseEvent3D) { var selectedItem = RootSelection; ActiveSelectedItem = selectedItem; @@ -339,7 +339,7 @@ namespace MatterHackers.Plugins.EditorTools base.OnMouseMove(mouseEvent3D); } - public override void OnMouseUp(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { if (HadClickOnControl) { diff --git a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs index 0d4aa38ef..f458d35aa 100644 --- a/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs +++ b/MatterControlLib/DesignTools/EditorTools/ScaleControls/ScaleTopControl.cs @@ -210,7 +210,7 @@ namespace MatterHackers.Plugins.EditorTools return new Vector3(originalSelectedBounds.Center.X, originalSelectedBounds.Center.Y, originalSelectedBounds.MaxXYZ.Z); } - public override void OnMouseDown(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { if (mouseEvent3D.info != null && InteractionContext.Scene.SelectedItem != null) { @@ -233,7 +233,7 @@ namespace MatterHackers.Plugins.EditorTools base.OnMouseDown(mouseEvent3D); } - public override void OnMouseMove(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseMove(Mouse3DEventArgs mouseEvent3D) { var selectedItem = RootSelection; @@ -295,7 +295,7 @@ namespace MatterHackers.Plugins.EditorTools base.OnMouseMove(mouseEvent3D); } - public override void OnMouseUp(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { InteractionContext.Scene.AddTransformSnapshot(transformOnMouseDown); base.OnMouseUp(mouseEvent3D); diff --git a/MatterControlLib/Library/Export/GCodeExport.cs b/MatterControlLib/Library/Export/GCodeExport.cs index 57394f86b..0c7bfcf59 100644 --- a/MatterControlLib/Library/Export/GCodeExport.cs +++ b/MatterControlLib/Library/Export/GCodeExport.cs @@ -49,9 +49,17 @@ namespace MatterHackers.MatterControl.Library.Export { public class GCodeExport : IExportPlugin, IExportWithOptions { - public enum SpiralVaseOptions { USE_SETTINGS, FORCE_ON, FORCE_OFF } + public enum SpiralVaseOptions + { + USE_SETTINGS, + FORCE_ON, + FORCE_OFF + } + private SpiralVaseOptions spiralVaseOverride = SpiralVaseOptions.USE_SETTINGS; - protected PrinterConfig printer { get; set; } + + protected PrinterConfig Printer { get; set; } + private bool printerSetupRequired; public virtual string ButtonText => "Machine File (G-Code)".Localize(); @@ -64,15 +72,15 @@ namespace MatterHackers.MatterControl.Library.Export public void Initialize(PrinterConfig printer) { - this.printer = printer; + this.Printer = printer; printerSetupRequired = PrinterCalibrationWizard.SetupRequired(printer, requiresLoadedFilament: false); } public virtual bool Enabled { - get => printer != null - && printer.Settings.PrinterSelected - && !printer.Settings.GetValue("enable_sailfish_communication") + get => Printer != null + && Printer.Settings.PrinterSelected + && !Printer.Settings.GetValue("enable_sailfish_communication") && !printerSetupRequired; } @@ -80,11 +88,11 @@ namespace MatterHackers.MatterControl.Library.Export { get { - if (printer == null) + if (Printer == null) { return "Create a printer to export G-Code".Localize(); } - else if (!printer.Settings.PrinterSelected) + else if (!Printer.Settings.PrinterSelected) { return "No Printer Selected".Localize(); } @@ -110,7 +118,7 @@ namespace MatterHackers.MatterControl.Library.Export var spiralVaseCheckbox = new CheckBox("Spiral Vase".Localize(), theme.TextColor, 10) { - Checked = printer.Settings.GetValue(SettingsKey.spiral_vase), + Checked = Printer.Settings.GetValue(SettingsKey.spiral_vase), Cursor = Cursors.Hand, }; spiralVaseCheckbox.CheckedStateChanged += (s, e) => @@ -127,7 +135,7 @@ namespace MatterHackers.MatterControl.Library.Export container.AddChild(spiralVaseCheckbox); // If print leveling is enabled then add in a check box 'Apply Leveling During Export' and default checked. - if (printer.Settings.GetValue(SettingsKey.print_leveling_enabled)) + if (Printer.Settings.GetValue(SettingsKey.print_leveling_enabled)) { var levelingCheckbox = new CheckBox("Apply leveling to G-Code during export".Localize(), theme.TextColor, 10) { @@ -158,17 +166,17 @@ namespace MatterHackers.MatterControl.Library.Export using (var gcodeStream = await assetStream.GetStream(progress: null)) { this.ApplyStreamPipelineAndExport( - new GCodeFileStream(new GCodeFileStreamed(gcodeStream.Stream), printer), + new GCodeFileStream(new GCodeFileStreamed(gcodeStream.Stream), Printer), outputPath); return null; } } - else if (firstItem.AssetPath == printer.Bed.EditContext.SourceFilePath) + else if (firstItem.AssetPath == Printer.Bed.EditContext.SourceFilePath) { // If item is bedplate, save any pending changes before starting the print - await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), printer, printer.Bed.SaveChanges); - loadedItem = printer.Bed.Scene; + await ApplicationController.Instance.Tasks.Execute("Saving".Localize(), Printer, Printer.Bed.SaveChanges); + loadedItem = Printer.Bed.Scene; CenterOnBed = false; } else if (firstItem is ILibraryObject3D object3DItem) @@ -213,20 +221,20 @@ namespace MatterHackers.MatterControl.Library.Export var aabb = loadedItem.GetAxisAlignedBoundingBox(); // Move to bed center - var bedCenter = printer.Bed.BedCenter; + var bedCenter = Printer.Bed.BedCenter; loadedItem.Matrix *= Matrix4X4.CreateTranslation(-aabb.Center.X, -aabb.Center.Y, -aabb.MinXYZ.Z) * Matrix4X4.CreateTranslation(bedCenter.X, bedCenter.Y, 0); } // Slice try { - bool oldSpiralVaseSetting = printer.Settings.GetValue(SettingsKey.spiral_vase); + bool oldSpiralVaseSetting = Printer.Settings.GetValue(SettingsKey.spiral_vase); if (spiralVaseOverride != SpiralVaseOptions.USE_SETTINGS) { - printer.Settings.SetValue(SettingsKey.spiral_vase, spiralVaseOverride == SpiralVaseOptions.FORCE_ON ? "1" : "0"); + Printer.Settings.SetValue(SettingsKey.spiral_vase, spiralVaseOverride == SpiralVaseOptions.FORCE_ON ? "1" : "0"); } - errors = printer.ValidateSettings(validatePrintBed: false); + errors = Printer.ValidateSettings(validatePrintBed: false); if (errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error)) { @@ -236,21 +244,21 @@ namespace MatterHackers.MatterControl.Library.Export // This mush be calculated after the settings have been set (spiral vase) // or it uses the wrong slice settings. // TODO: Prior code bypassed GCodeOverridePath mechanisms in EditContext. Consolidating into a single pathway - gcodePath = printer.Bed.EditContext.GCodeFilePath(printer); + gcodePath = Printer.Bed.EditContext.GCodeFilePath(Printer); await ApplicationController.Instance.Tasks.Execute( "Slicing Item".Localize() + " " + loadedItem.Name, - printer, + Printer, (reporter, cancellationToken2) => { - return Slicer.SliceItem(loadedItem, gcodePath, printer, reporter, cancellationToken2); + return Slicer.SliceItem(loadedItem, gcodePath, Printer, reporter, cancellationToken2); }); - printer.Settings.SetValue(SettingsKey.spiral_vase, oldSpiralVaseSetting ? "1" : "0"); + Printer.Settings.SetValue(SettingsKey.spiral_vase, oldSpiralVaseSetting ? "1" : "0"); } finally { - printer.Settings.SetValue(SettingsKey.spiral_vase, "0"); + Printer.Settings.SetValue(SettingsKey.spiral_vase, "0"); } } @@ -333,7 +341,7 @@ namespace MatterHackers.MatterControl.Library.Export { try { - var finalStream = GetExportStream(printer, gCodeFileStream, this.ApplyLeveling); + var finalStream = GetExportStream(Printer, gCodeFileStream, this.ApplyLeveling); // Run each line from the source gcode through the loaded pipeline and dump to the output location using (var file = new StreamWriter(outputPath)) @@ -363,7 +371,7 @@ namespace MatterHackers.MatterControl.Library.Export { try { - var settings = printer.Settings; + var settings = Printer.Settings; var maxAcceleration = settings.GetValue(SettingsKey.max_acceleration); var maxVelocity = settings.GetValue(SettingsKey.max_velocity); var jerkVelocity = settings.GetValue(SettingsKey.jerk_velocity); @@ -378,7 +386,7 @@ namespace MatterHackers.MatterControl.Library.Export new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity), new Vector4(multiplier, multiplier, multiplier, multiplier), CancellationToken.None), - printer), + Printer), outputPath); } catch (Exception e) diff --git a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs index 1f05d54a6..3702f8c75 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Gui3D/MoveInZControl.cs @@ -187,7 +187,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow return Vector3.Zero; } - public override void OnMouseDown(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { var selectedItem = RootSelection; @@ -210,7 +210,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow base.OnMouseDown(mouseEvent3D); } - public override void OnMouseMove(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseMove(Mouse3DEventArgs mouseEvent3D) { var selectedItem = RootSelection; ActiveSelectedItem = selectedItem; @@ -257,7 +257,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow base.OnMouseMove(mouseEvent3D); } - public override void OnMouseUp(MouseEvent3DArgs mouseEvent3D) + public override void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { InteractionContext.Scene.AddTransformSnapshot(transformOnMouseDown); base.OnMouseUp(mouseEvent3D); diff --git a/MatterControlLib/PartPreviewWindow/View3D/Interaction/InteractionVolume.cs b/MatterControlLib/PartPreviewWindow/View3D/Interaction/InteractionVolume.cs index 57a4454c8..e66d2a0fe 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Interaction/InteractionVolume.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Interaction/InteractionVolume.cs @@ -153,7 +153,7 @@ namespace MatterHackers.MeshVisualizer { } - public virtual void OnMouseDown(MouseEvent3DArgs mouseEvent3D) + public virtual void OnMouseDown(Mouse3DEventArgs mouseEvent3D) { if (mouseEvent3D.MouseEvent2D.Button == MouseButtons.Left) { @@ -162,11 +162,11 @@ namespace MatterHackers.MeshVisualizer } } - public virtual void OnMouseMove(MouseEvent3DArgs mouseEvent3D) + public virtual void OnMouseMove(Mouse3DEventArgs mouseEvent3D) { } - public virtual void OnMouseUp(MouseEvent3DArgs mouseEvent3D) + public virtual void OnMouseUp(Mouse3DEventArgs mouseEvent3D) { MouseDownOnControl = false; } diff --git a/MatterControlLib/PartPreviewWindow/View3D/Interaction/MouseEvent3DArgs.cs b/MatterControlLib/PartPreviewWindow/View3D/Interaction/Mouse3DEventArgs.cs similarity index 94% rename from MatterControlLib/PartPreviewWindow/View3D/Interaction/MouseEvent3DArgs.cs rename to MatterControlLib/PartPreviewWindow/View3D/Interaction/Mouse3DEventArgs.cs index 494d4b3a5..de9a315f2 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/Interaction/MouseEvent3DArgs.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/Interaction/Mouse3DEventArgs.cs @@ -34,14 +34,14 @@ using MatterHackers.VectorMath; namespace MatterHackers.MeshVisualizer { - public class MouseEvent3DArgs : EventArgs + public class Mouse3DEventArgs : EventArgs { public IntersectInfo info; public MouseEventArgs MouseEvent2D; public Ray MouseRay { get; } - public MouseEvent3DArgs(MouseEventArgs mouseEvent2D, Ray mouseRay, IntersectInfo info) + public Mouse3DEventArgs(MouseEventArgs mouseEvent2D, Ray mouseRay, IntersectInfo info) { this.info = info; this.MouseEvent2D = mouseEvent2D; diff --git a/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs b/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs index 0cec779a2..320a5a055 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/InteractionLayer.cs @@ -263,7 +263,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow && !SuppressUiVolumes && FindInteractionVolumeHit(ray, out mouseDownIAVolume, out IntersectInfo info)) { - mouseDownIAVolume.OnMouseDown(new MouseEvent3DArgs(mouseEvent, ray, info)); + mouseDownIAVolume.OnMouseDown(new Mouse3DEventArgs(mouseEvent, ray, info)); SelectedInteractionVolume = mouseDownIAVolume; } else @@ -284,7 +284,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Ray ray = this.World.GetRayForLocalBounds(mouseEvent.Position); IntersectInfo info = null; - var mouseEvent3D = new MouseEvent3DArgs(mouseEvent, ray, info); + var mouseEvent3D = new Mouse3DEventArgs(mouseEvent, ray, info); if (MouseDownOnInteractionVolume && mouseDownIAVolume != null) { @@ -327,7 +327,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Ray ray = this.World.GetRayForLocalBounds(mouseEvent.Position); bool anyInteractionVolumeHit = FindInteractionVolumeHit(ray, out InteractionVolume iaVolume, out IntersectInfo info); - var mouseEvent3D = new MouseEvent3DArgs(mouseEvent, ray, info); + var mouseEvent3D = new Mouse3DEventArgs(mouseEvent, ray, info); if (MouseDownOnInteractionVolume && mouseDownIAVolume != null) { diff --git a/MatterControlLib/PrinterCommunication/Drivers/X3G/X3GExport.cs b/MatterControlLib/PrinterCommunication/Drivers/X3G/X3GExport.cs index 4072099a4..378eb6d67 100644 --- a/MatterControlLib/PrinterCommunication/Drivers/X3G/X3GExport.cs +++ b/MatterControlLib/PrinterCommunication/Drivers/X3G/X3GExport.cs @@ -54,17 +54,17 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver public override bool Enabled { - get => printer != null - && printer.Settings.PrinterSelected - && printer.Settings.GetValue("enable_sailfish_communication"); + get => Printer != null + && Printer.Settings.PrinterSelected + && Printer.Settings.GetValue("enable_sailfish_communication"); } public override string DisabledReason { get { - if (printer == null - || printer.Settings.PrinterSelected) + if (Printer == null + || Printer.Settings.PrinterSelected) { return ""; } @@ -93,7 +93,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver var binaryFileStream = new FileStream(outputPath, FileMode.OpenOrCreate); var outputFile = new BinaryWriter(binaryFileStream); - var x3gConverter = new X3GWriter(new X3GPrinterDetails(), printer.Settings); + var x3gConverter = new X3GWriter(new X3GPrinterDetails(), Printer.Settings); var x3gLines = new List(); byte[] emptyByteArray = { 0 }; @@ -101,7 +101,7 @@ namespace MatterHackers.MatterControl.Plugins.X3GDriver //Makes sure steps per mm and bed offset is set string splitString = "\\n"; - string connectGCodeLines = printer.Settings.GetValue(SettingsKey.connect_gcode); + string connectGCodeLines = Printer.Settings.GetValue(SettingsKey.connect_gcode); foreach (string connectLine in connectGCodeLines.Split(splitString.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { bool sendToPrinter; diff --git a/Submodules/MatterSlice b/Submodules/MatterSlice index cea3f4943..f1a7f8815 160000 --- a/Submodules/MatterSlice +++ b/Submodules/MatterSlice @@ -1 +1 @@ -Subproject commit cea3f49435922befeb58f1963d9751d2fe84e3ca +Subproject commit f1a7f881525f56b915e6bb0957c68e0735203223