From dbd1eb56ce42dd770b4effcc8cefd4163adc34e6 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Thu, 20 Jan 2022 14:52:03 -0800 Subject: [PATCH] Initial startup is better --- .../ApplicationView/ApplicationController.cs | 79 +++++++++++-------- .../ApplicationView/PartWorkspace.cs | 21 ++++- MatterControlLib/DialogPages/StartupPage.cs | 25 +----- .../Library/Widgets/AddPrinterWidget.cs | 14 +++- .../Widgets/ListView/LibraryListView.cs | 7 +- .../PartPreviewWindow/MainViewWidget.cs | 43 +++++----- MatterControlLib/PartPreviewWindow/Tabs.cs | 9 +-- .../PartPreviewWindow/View3D/SceneActions.cs | 6 ++ .../SetupStepMakeModelName.cs | 2 +- MatterControlLib/RootSystemWindow.cs | 2 - .../Settings/ProfileManager.cs | 2 +- StaticData/Translations/Master.txt | 30 +++++++ .../MatterControl/OemProfileTests.cs | 21 +++++ 13 files changed, 162 insertions(+), 99 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 35dd99ac5..d2b46914c 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -29,6 +29,7 @@ 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; @@ -297,12 +298,15 @@ namespace MatterHackers.MatterControl } } - public async Task PersistUserTabs() + private async Task PersistUserWorkspaceTabs(bool saveSceneChanges) { - // Persist all pending changes in all workspaces to disk - foreach (var workspace in this.Workspaces.ToArray()) + if (saveSceneChanges) { - await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges); + // Persist all pending changes in all workspaces to disk + foreach (var workspace in this.Workspaces.ToArray()) + { + await this.Tasks.Execute("Saving".Localize() + $" \"{workspace.Name}\" ...", workspace, workspace.SceneContext.SaveChanges); + } } // Project workspace definitions to serializable structure @@ -326,16 +330,15 @@ namespace MatterHackers.MatterControl lock (workspaces) { - // Persist workspace definitions to disk - File.WriteAllText( - ProfileManager.Instance.OpenTabsPath, - JsonConvert.SerializeObject( + var content = JsonConvert.SerializeObject( workspaces, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore - })); + }); + // Persist workspace definitions to disk + File.WriteAllText(ProfileManager.Instance.OpenTabsPath, content); } } @@ -455,7 +458,7 @@ namespace MatterHackers.MatterControl { UiThread.RunOnIdle(async () => { - await ApplicationController.Instance.PersistUserTabs(); + await ApplicationController.Instance.PersistUserWorkspaceTabs(true); }); } } @@ -732,13 +735,12 @@ namespace MatterHackers.MatterControl return actions.ToDictionary(a => a.ID); } - public void OpenIntoNewTab(IEnumerable selectedLibraryItems) + public async Task OpenIntoNewTab(IEnumerable selectedLibraryItems) { - this.MainView.CreatePartTab(true).ContinueWith(task => - { - var workspace = this.Workspaces.Last(); - workspace.SceneContext.AddToPlate(selectedLibraryItems); - }); + await this.MainView.CreateNewPartTab(false); + + var workspace = this.Workspaces.Last(); + workspace.SceneContext.AddToPlate(selectedLibraryItems); } internal void BlinkTab(ITab tab) @@ -956,8 +958,18 @@ namespace MatterHackers.MatterControl }); } - public ApplicationController() + private ApplicationController() { + Workspaces = new ObservableCollection(); + + Workspaces.CollectionChanged += (s, e) => + { + if (!restoringWorkspaces) + { + UiThread.RunOnIdle(async () => await PersistUserWorkspaceTabs(false)); + } + }; + this.Thumbnails = new ThumbnailsConfig(); ProfileManager.UserChanged += (s, e) => @@ -1549,7 +1561,7 @@ namespace MatterHackers.MatterControl return printer; } - public async Task OpenEmptyPrinter(string printerID) + public async Task OpenEmptyPrinter(string printerID, bool addPhilToBed = false) { if (!string.IsNullOrEmpty(printerID) && ProfileManager.Instance[printerID] != null) @@ -1566,13 +1578,13 @@ namespace MatterHackers.MatterControl SourceItem = history.NewPlatingItem(workspace.SceneContext.Scene) }); - if (workspace.Printer != null) - { - workspace.Name = workspace.Printer.Settings.GetValue(SettingsKey.printer_name); - } - this.OpenWorkspace(workspace); + if (addPhilToBed) + { + workspace.SceneContext.AddPhilToBed(); + } + return printer; } @@ -1624,6 +1636,8 @@ namespace MatterHackers.MatterControl return; } + restoringWorkspaces = true; + loadedUserTabs = ProfileManager.Instance.UserName; var history = this.Library.PlatingHistory; @@ -1683,15 +1697,6 @@ namespace MatterHackers.MatterControl SourceItem = new FileSystemFileItem(persistedWorkspace.ContentPath) }); - if (workspace.Printer != null) - { - workspace.Name = workspace.Printer.Settings.GetValue(SettingsKey.printer_name); - } - else - { - workspace.Name = workspace?.SceneContext.EditContext?.SourceItem?.Name ?? "Unknown"; - } - this.RestoreWorkspace(workspace); } } @@ -1709,13 +1714,16 @@ namespace MatterHackers.MatterControl // If the use does not have a workspace open and has not setup any hardware, show the startup screen if (this.Workspaces.Count == 0 - && !ProfileManager.Instance.ActiveProfiles.Any()) + && !ProfileManager.Instance.ActiveProfiles.Any() + && SystemWindow.AllOpenSystemWindows.Count() < 2) { UiThread.RunOnIdle(() => { DialogWindow.Show(); }); } + + restoringWorkspaces = false; } /// @@ -1772,7 +1780,7 @@ namespace MatterHackers.MatterControl public Action ShareLibraryItem { get; set; } - public List Workspaces { get; } = new List(); + public ObservableCollection Workspaces { get; } public AppViewState ViewState { get; } = new AppViewState(); @@ -2094,8 +2102,9 @@ namespace MatterHackers.MatterControl } private static PluginManager pluginManager = null; + private bool restoringWorkspaces; - public static PluginManager Plugins + public static PluginManager Plugins { get { diff --git a/MatterControlLib/ApplicationView/PartWorkspace.cs b/MatterControlLib/ApplicationView/PartWorkspace.cs index 601d21c64..9d007610d 100644 --- a/MatterControlLib/ApplicationView/PartWorkspace.cs +++ b/MatterControlLib/ApplicationView/PartWorkspace.cs @@ -76,10 +76,27 @@ namespace MatterHackers.MatterControl }; this.SceneContext = sceneContext; - Name = sceneContext.EditContext?.SourceItem?.Name ?? "Unknown"; } - public string Name { get; set; } + public string Name + { + get + { + var name = SceneContext.EditContext?.SourceItem?.Name; + if (!string.IsNullOrEmpty(name)) + { + return name; + } + + name = Printer?.Settings?.GetValue(SettingsKey.printer_name); + if (!string.IsNullOrEmpty(name)) + { + return name; + } + + return "Unknown"; + } + } [JsonIgnore] public ISceneContext SceneContext { get; } diff --git a/MatterControlLib/DialogPages/StartupPage.cs b/MatterControlLib/DialogPages/StartupPage.cs index 3d744d428..0415fa374 100644 --- a/MatterControlLib/DialogPages/StartupPage.cs +++ b/MatterControlLib/DialogPages/StartupPage.cs @@ -155,34 +155,11 @@ namespace MatterHackers.MatterControl }, "Start New Design".Localize())); lastButton.Click += (s, e) => UiThread.RunOnIdle(() => { - LoadEmptyScene(); + ApplicationController.Instance.MainView.CreateNewPartTab(true); this.DialogWindow.Close(); }); contentRow.AddChild(buttonRow); } - - void LoadEmptyScene() - { - var history = ApplicationController.Instance.Library.PlatingHistory; - - var workspace = new PartWorkspace(new BedConfig(history)) - { - Name = "New Design".Localize() - }; - - // Load it up - workspace.SceneContext.LoadEmptyContent( - new EditContext() - { - ContentStore = history, - SourceItem = history.NewPlatingItem(workspace.SceneContext.Scene) - }); - - ApplicationController.Instance.MainTabKey = workspace.Name; - - // Open but no need to save - ApplicationController.Instance.OpenWorkspace(workspace, WorkspacesChangedEventArgs.OperationType.Restore); - } } } \ No newline at end of file diff --git a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs index 30c0a181d..7af9dd4f8 100644 --- a/MatterControlLib/Library/Widgets/AddPrinterWidget.cs +++ b/MatterControlLib/Library/Widgets/AddPrinterWidget.cs @@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl.PrintLibrary private Action nextButtonEnabled; private FlowLayoutWidget printerInfo; - public AddPrinterWidget(ThemeConfig theme, Action nextButtonEnabled, bool filterToPulse) + public AddPrinterWidget(GuiWidget nextButton, ThemeConfig theme, Action nextButtonEnabled, bool filterToPulse) : base(theme) { this.nextButtonEnabled = nextButtonEnabled; @@ -61,6 +61,18 @@ namespace MatterHackers.MatterControl.PrintLibrary treeView.AfterSelect += this.TreeView_AfterSelect; + treeView.NodeMouseDoubleClick += (s, e) => + { + if (e is MouseEventArgs mouseEvent + && mouseEvent.Button == MouseButtons.Left + && mouseEvent.Clicks == 2 + && treeView?.SelectedNode is TreeNode treeNode) + { + nextButton.InvokeClick(); + } + }; + + UiThread.RunOnIdle(() => { foreach (var oem in OemSettings.Instance.OemProfiles.OrderBy(o => o.Key)) diff --git a/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs b/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs index e699d7865..ffaf46c5c 100644 --- a/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs +++ b/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs @@ -531,14 +531,11 @@ namespace MatterHackers.MatterControl.CustomWidgets } } - var workspace = new PartWorkspace(new BedConfig(ApplicationController.Instance.Library.PlatingHistory)) - { - Name = firstItem.Name, - }; + var workspace = new PartWorkspace(new BedConfig(ApplicationController.Instance.Library.PlatingHistory)); ApplicationController.Instance.Workspaces.Add(workspace); - var partTab = await mainViewWidget.CreatePartTab(workspace, true); + var partTab = mainViewWidget.CreatePartTab(workspace, true); mainViewWidget.TabControl.ActiveTab = partTab; // Load content after UI widgets to support progress notification during acquire/load diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index 9aaec166c..a4b1636db 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -32,6 +32,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; +using System.Threading; using System.Threading.Tasks; using MatterControlLib; using MatterHackers.Agg; @@ -217,7 +218,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow tabControl.PlusClicked += (s, e) => UiThread.RunOnIdle(() => { - this.CreatePartTab(true).ConfigureAwait(false); + CreateNewPartTab(true); }); // Force the ActionArea to be as high as ButtonHeight @@ -360,7 +361,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } else { - newTab = await this.CreatePartTab(workspace, false); + newTab = this.CreatePartTab(workspace, false); } if (newTab.Key == ApplicationController.Instance.MainTabKey) @@ -441,10 +442,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { var history = ApplicationController.Instance.Library.PlatingHistory; - var workspace = new PartWorkspace(new BedConfig(history)) - { - Name = Path.GetFileName(filePath), - }; + var workspace = new PartWorkspace(new BedConfig(history)); ApplicationController.Instance.Workspaces.Add(workspace); @@ -465,7 +463,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow ApplicationController.Instance.Workspaces.Add(workspace); - var newTab = await CreatePartTab(workspace, true); + var newTab = CreatePartTab(workspace, true); tabControl.ActiveTab = newTab; } @@ -564,7 +562,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { // Create printer or part tab bool isPrinter = activePrinter?.Settings.PrinterSelected == true; - ChromeTab newTab = isPrinter ? CreatePrinterTab(workspace, theme) : await CreatePartTab(workspace, false); + ChromeTab newTab = isPrinter ? CreatePrinterTab(workspace, theme) : CreatePartTab(workspace, false); if (e.Operation == WorkspacesChangedEventArgs.OperationType.Add) { @@ -830,14 +828,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow popupMenu.ShowMenu(printerTab, mouseEvent); } - public async Task CreatePartTab(bool saveLayout) + public async Task CreateNewPartTab(bool addPhilToBed) { var history = ApplicationController.Instance.Library.PlatingHistory; - var workspace = new PartWorkspace(new BedConfig(history)) - { - Name = "New Design".Localize() + (partCount == 0 ? "" : $" ({partCount})"), - }; + var workspace = new PartWorkspace(new BedConfig(history)); await workspace.SceneContext.LoadContent( new EditContext() @@ -848,13 +843,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow ApplicationController.Instance.Workspaces.Add(workspace); - var newTab = await CreatePartTab(workspace, saveLayout); + var newTab = CreatePartTab(workspace, true); tabControl.ActiveTab = newTab; - return newTab; + if (addPhilToBed) + { + workspace.SceneContext.AddPhilToBed(); + } + + UiThread.RunOnIdle(async () => + { + // Save any pending changes before starting print operation + await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, workspace.SceneContext.SaveChanges); + }); + + ApplicationController.Instance.MainTabKey = workspace.Name; } - public async Task CreatePartTab(PartWorkspace workspace, bool saveLayout) + public ChromeTab CreatePartTab(PartWorkspace workspace, bool saveLayout) { var partTab = new ChromeTab( workspace.Name, @@ -894,11 +900,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow partTab.CloseClicked += Tab_CloseClicked; partTab.Closed += Widget_Closed; - if (saveLayout) - { - await ApplicationController.Instance.PersistUserTabs(); - } - return partTab; } diff --git a/MatterControlLib/PartPreviewWindow/Tabs.cs b/MatterControlLib/PartPreviewWindow/Tabs.cs index a004b5f7d..2d3d71a51 100644 --- a/MatterControlLib/PartPreviewWindow/Tabs.cs +++ b/MatterControlLib/PartPreviewWindow/Tabs.cs @@ -322,8 +322,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow ApplicationController.Instance.Workspaces.RemoveAt(savedIndex); ApplicationController.Instance.Workspaces.Insert(savedIndex + 1, moving); - await ApplicationController.Instance.PersistUserTabs(); - TabBar.ActionArea.PerformLayout(); ActiveTab = tab; @@ -350,8 +348,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow ApplicationController.Instance.Workspaces.RemoveAt(savedIndex); ApplicationController.Instance.Workspaces.Insert(savedIndex - 1, moving); - await ApplicationController.Instance.PersistUserTabs(); - TabBar.ActionArea.PerformLayout(); ActiveTab = tab; @@ -373,7 +369,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow public GuiWidget TabContent { get; protected set; } - public string Key { get; } + public string Key { get; set; } private bool hasClose = false; @@ -585,8 +581,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow private static int tabInsetDistance = 14 / 2; - - internal ChromeTab NextTab + internal ChromeTab NextTab { get { diff --git a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs index b8abb287a..bfd07a243 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/SceneActions.cs @@ -202,6 +202,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } } + public static void AddPhilToBed(this ISceneContext sceneContext) + { + var philStl = StaticData.Instance.MapPath(@"OEMSettings\SampleParts\Phil A Ment.stl"); + sceneContext.AddToPlate(new string[] { philStl }); + } + public static void Paste(this ISceneContext sceneContext) { var scene = sceneContext.Scene; diff --git a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs index 8ae6b3216..96abbafd1 100644 --- a/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs +++ b/MatterControlLib/PrinterControls/PrinterConnections/SetupStepMakeModelName.cs @@ -55,7 +55,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections contentRow.BackgroundColor = theme.SectionBackgroundColor; nextButton = theme.CreateDialogButton("Next".Localize()); - printerPanel = new AddPrinterWidget(theme, (enabled) => + printerPanel = new AddPrinterWidget(nextButton, theme, (enabled) => { nextButton.Enabled = enabled; }, filterToPulse) diff --git a/MatterControlLib/RootSystemWindow.cs b/MatterControlLib/RootSystemWindow.cs index fb2d65286..9a8d78800 100644 --- a/MatterControlLib/RootSystemWindow.cs +++ b/MatterControlLib/RootSystemWindow.cs @@ -300,8 +300,6 @@ namespace MatterHackers.MatterControl { var application = ApplicationController.Instance; - await application.PersistUserTabs(); - application.ApplicationExiting = true; // Make sure we tell the Application Controller to shut down. This will release the slicing thread if running. diff --git a/MatterControlLib/SlicerConfiguration/Settings/ProfileManager.cs b/MatterControlLib/SlicerConfiguration/Settings/ProfileManager.cs index 3c41b1b57..dda129a7c 100644 --- a/MatterControlLib/SlicerConfiguration/Settings/ProfileManager.cs +++ b/MatterControlLib/SlicerConfiguration/Settings/ProfileManager.cs @@ -846,7 +846,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration printerSettings.Save(userDrivenChange: false); // Set as active profile - return await ApplicationController.Instance.OpenEmptyPrinter(guid); + return await ApplicationController.Instance.OpenEmptyPrinter(guid, true); } public static async Task LoadOemSettingsAsync(PublicDevice publicDevice, string make, string model) diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index 55199900e..5ad76509d 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -34,6 +34,9 @@ Translated:{0} should be greater than 0. English:{0} should be greater than or equal to 1/2 the {1}. Translated:{0} should be greater than or equal to 1/2 the {1}. +English:<< Back +Translated:<< Back + English:° Translated:° @@ -100,6 +103,9 @@ Translated:A U.S. or Canadian mobile phone number English:A valid email address Translated:A valid email address +English:Abort Calibration +Translated:Abort Calibration + English:Abort Print Translated:Abort Print @@ -271,6 +277,9 @@ Translated:Attempting to connect English:Attempting to connect again may address the issue. Translated:Attempting to connect again may address the issue. +English:Attempting to connect to {0} +Translated:Attempting to connect to {0} + English:Auto Connect Translated:Auto Connect @@ -625,6 +634,9 @@ Translated:Connection Failed English:Connection succeeded Translated:Connection succeeded +English:Connection succeeded (port {0}). +Translated:Connection succeeded (port {0}). + English:Continue Translated:Continue @@ -1171,6 +1183,9 @@ Translated:Find and create supports where needed English:Find Slice Translated:Find Slice +English:Finish +Translated:Finish + English:Finished Print: {0} Translated:Finished Print: {0} @@ -1501,6 +1516,9 @@ Translated:Image English:Image Converter Translated:Image Converter +English:Image Missing +Translated:Image Missing + English:Image to Path Translated:Image to Path @@ -2395,6 +2413,9 @@ Translated:Please wait. Retrieving share code... English:Please wait. Signing in... Translated:Please wait. Signing in... +English:Plug in printer USB cable and turn printer on +Translated:Plug in printer USB cable and turn printer on + English:Plugins Translated:Plugins @@ -2662,6 +2683,9 @@ Translated:Recover Print English:recovered once Translated:recovered once +English:Recovered printer profile +Translated:Recovered printer profile + English:rectangular Translated:rectangular @@ -2965,6 +2989,9 @@ Translated:Select cell to edit English:Select Parts Translated:Select Parts +English:Select Printer +Translated:Select Printer + English:Select Range Translated:Select Range @@ -3673,6 +3700,9 @@ Translated:The printer requires print leveling to run correctly. English:The printer should now be 'homing'. Translated:The printer should now be 'homing'. +English:The profile you are attempting to load has been corrupted. We loaded your last usable {0} {1} profile from your recent profile history instead. +Translated:The profile you are attempting to load has been corrupted. We loaded your last usable {0} {1} profile from your recent profile history instead. + English:The ratio between the requested extrusion and the sensors measured extrusion that will trigger an error. Translated:The ratio between the requested extrusion and the sensors measured extrusion that will trigger an error. diff --git a/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs b/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs index f8886b32b..35a677acc 100644 --- a/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs +++ b/Tests/MatterControl.Tests/MatterControl/OemProfileTests.cs @@ -53,6 +53,8 @@ namespace MatterControl.Tests.MatterControl void ChangeSettings(PrinterSettings printerSettings) { + var printerModel = printerSettings.GetValue(SettingsKey.model); + // general printerSettings.SetValue(SettingsKey.fill_density, "30%"); printerSettings.SetValue(SettingsKey.avoid_crossing_perimeters, "1"); @@ -75,6 +77,25 @@ namespace MatterControl.Tests.MatterControl printerSettings.SetValue(SettingsKey.retract_lift, ".4"); printerSettings.SetValue(SettingsKey.min_extrusion_before_retract, "0"); printerSettings.SetValue(SettingsKey.retract_before_travel_avoid, "20"); + + if (string.IsNullOrEmpty(printerSettings.GetValue(SettingsKey.read_regex))) + { + if (printerModel.Contains('E')) + { + printerSettings.SetValue(SettingsKey.read_regex, "\"^(filament)\", \"ros_\""); + } + } + else + { + int ja = 0; + } + + // If the board is 32 bit we cannot update the firmware. + if (printerModel.Contains('M') || printerModel.Contains('S')) + { + // make sure it does not show a firmware updater + printerSettings.SetValue(SettingsKey.include_firmware_updater, "None"); + } } foreach (var printer in allPrinters)