From aa8591ffe594e3374db9966778b28ef323267240 Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sun, 20 Feb 2022 07:59:28 -0800 Subject: [PATCH] Show loading / restoring progress Fix null when canceling open system file --- .../ApplicationView/ApplicationController.cs | 104 +++++++++++------- .../ApplicationView/BrandMenuButton.cs | 10 +- .../ApplicationView/Config/BedConfig.cs | 19 ++-- .../ApplicationView/ISceneContext.cs | 6 +- .../SetupWizards/XyCalibrationWizard.cs | 2 +- .../CustomWidgets/CalibrationObjectPrinter.cs | 3 +- .../Library/Widgets/LibraryWidget.cs | 30 +++-- .../Widgets/ListView/LibraryListView.cs | 20 +++- .../PartPreviewWindow/MainViewWidget.cs | 4 +- .../PartPreviewWindow/View3D/View3DWidget.cs | 4 +- .../PartPreviewWindow/ViewToolBarControls.cs | 2 +- StaticData/Translations/Master.txt | 18 +++ Submodules/agg-sharp | 2 +- 13 files changed, 149 insertions(+), 75 deletions(-) diff --git a/MatterControlLib/ApplicationView/ApplicationController.cs b/MatterControlLib/ApplicationView/ApplicationController.cs index 1aee65f97..0fa9d924b 100644 --- a/MatterControlLib/ApplicationView/ApplicationController.cs +++ b/MatterControlLib/ApplicationView/ApplicationController.cs @@ -726,7 +726,10 @@ namespace MatterHackers.MatterControl new OpenFileDialogParams(filter, multiSelect: true), (openParams) => { - openFiles?.Invoke(openParams.FileNames); + if (openParams != null && openParams.FileNames != null) + { + openFiles?.Invoke(openParams.FileNames); + } }); }, .1); } @@ -1637,7 +1640,8 @@ namespace MatterHackers.MatterControl { ContentStore = history, SourceItem = history.NewBedPlate(workspace.Printer.Bed) - }); + }, + null); this.OpenWorkspace(workspace); @@ -1699,7 +1703,7 @@ namespace MatterHackers.MatterControl var history = this.Library.PlatingHistory; - this.Workspaces.Clear(); + Workspaces.Clear(); if (File.Exists(ProfileManager.Instance.OpenTabsPath)) { @@ -1713,55 +1717,71 @@ namespace MatterHackers.MatterControl var loadedPrinters = new HashSet(); - foreach (var persistedWorkspace in persistedWorkspaces) - { - try + await Tasks.Execute( + "Restoring".Localize() + "...", + null, + async (reporter, cancellationTokenSource) => { - // Load the actual workspace if content file exists - if (File.Exists(persistedWorkspace.ContentPath)) + var progressStatus = new ProgressStatus(); + for (int i=0; i + { + var ratioPerWorkspace = 1.0 / persistedWorkspaces.Count; + var completed = ratioPerWorkspace * i; + progressStatus.Progress0To1 = completed + progress * ratioPerWorkspace; + progressStatus.Status = message; + reporter.Report(progressStatus); + }); + + this.RestoreWorkspace(workspace); } } - else + catch { - // Add workspace for part - workspace = new PartWorkspace(new BedConfig(history)); + // Suppress workspace load exceptions and continue to the next workspace } - - // Load the previous content - await workspace.SceneContext.LoadContent(new EditContext() - { - ContentStore = history, - SourceItem = new FileSystemFileItem(persistedWorkspace.ContentPath) - }); - - this.RestoreWorkspace(workspace); } - } - catch - { - // Suppress workspace load exceptions and continue to the next workspace - } - } + }); } catch { diff --git a/MatterControlLib/ApplicationView/BrandMenuButton.cs b/MatterControlLib/ApplicationView/BrandMenuButton.cs index 9ac1dc13b..9fd10783f 100644 --- a/MatterControlLib/ApplicationView/BrandMenuButton.cs +++ b/MatterControlLib/ApplicationView/BrandMenuButton.cs @@ -93,8 +93,14 @@ namespace MatterHackers.MatterControl PopupMenu.MenuItem menuItem; - menuItem = popupMenu.CreateMenuItem("Open File", StaticData.Instance.LoadIcon("fa-folder-open_16.png", 16, 16).SetToColor(menuTheme.TextColor)); - menuItem.Click += (s, e) => ApplicationController.OpenFileWithSystemDialog((fileNames) => ApplicationController.Instance.MainView.OpenFile(fileNames.FirstOrDefault())); + menuItem = popupMenu.CreateMenuItem("Open System File", StaticData.Instance.LoadIcon("fa-folder-open_16.png", 16, 16).SetToColor(menuTheme.TextColor)); + menuItem.Click += (s, e) => ApplicationController.OpenFileWithSystemDialog((fileNames) => + { + if (fileNames != null && fileNames.Any()) + { + ApplicationController.Instance.MainView.OpenFile(fileNames.FirstOrDefault()); + } + }); popupMenu.CreateSeparator(); diff --git a/MatterControlLib/ApplicationView/Config/BedConfig.cs b/MatterControlLib/ApplicationView/Config/BedConfig.cs index 1f95c89e7..99f9f05e6 100644 --- a/MatterControlLib/ApplicationView/Config/BedConfig.cs +++ b/MatterControlLib/ApplicationView/Config/BedConfig.cs @@ -97,17 +97,18 @@ namespace MatterHackers.MatterControl this.SceneLoaded?.Invoke(this, null); } - public Task LoadLibraryContent(ILibraryItem libraryItem) + public Task LoadLibraryContent(ILibraryItem libraryItem, Action progressReporter) { return this.LoadContent( new EditContext() { ContentStore = ApplicationController.Instance.Library.PlatingHistory, SourceItem = libraryItem - }); + }, + progressReporter); } - public async Task LoadContent(EditContext editContext) + public async Task LoadContent(EditContext editContext, Action progressReporter) { // Make sure we don't have a selection this.Scene.SelectedItem = null; @@ -120,7 +121,7 @@ namespace MatterHackers.MatterControl this.ContentType = contentInfo.ContentType; } - await this.LoadIntoCurrent(editContext); + await this.LoadIntoCurrent(editContext, progressReporter); } /// @@ -128,7 +129,7 @@ namespace MatterHackers.MatterControl /// /// The context to load into. /// - public async Task LoadIntoCurrent(EditContext editContext) + public async Task LoadIntoCurrent(EditContext editContext, Action progressReporter) { // Load if (editContext.SourceItem is ILibraryAssetStream contentStream @@ -145,7 +146,7 @@ namespace MatterHackers.MatterControl else { // Load last item or fall back to empty if unsuccessful - var content = await editContext.SourceItem.CreateContent(null) ?? new Object3D(); + var content = await editContext.SourceItem.CreateContent(progressReporter) ?? new Object3D(); loadedGCode = null; this.GCodeRenderer = null; @@ -258,7 +259,8 @@ namespace MatterHackers.MatterControl { SourceItem = new FileSystemFileItem(firstFilePath), ContentStore = null // No content store for GCode - }); + }, + null); return; } @@ -313,7 +315,8 @@ namespace MatterHackers.MatterControl SourceItem = libraryItem, // No content store for GCode ContentStore = null - }); + }, + null); // Slice and print await ApplicationController.Instance.PrintPart( diff --git a/MatterControlLib/ApplicationView/ISceneContext.cs b/MatterControlLib/ApplicationView/ISceneContext.cs index 21bb8cbc4..40df81426 100644 --- a/MatterControlLib/ApplicationView/ISceneContext.cs +++ b/MatterControlLib/ApplicationView/ISceneContext.cs @@ -72,15 +72,15 @@ namespace MatterHackers.MatterControl void ClearPlate(); - Task LoadContent(EditContext editContext); + Task LoadContent(EditContext editContext, Action progressReporter); void LoadEmptyContent(EditContext editContext); Task LoadGCodeContent(Stream stream); - Task LoadIntoCurrent(EditContext editContext); + Task LoadIntoCurrent(EditContext editContext, Action progressReporter); - Task LoadLibraryContent(ILibraryItem libraryItem); + Task LoadLibraryContent(ILibraryItem libraryItem, Action progressReporter); Task SaveChanges(IProgress progress, CancellationTokenSource cancellationToken); diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs index ebd1177e8..aefb68c8f 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/SetupWizards/XyCalibrationWizard.cs @@ -130,7 +130,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling if (originalEditContext != null && printer.Bed.EditContext != originalEditContext) { - await printer.Bed.LoadContent(originalEditContext); + await printer.Bed.LoadContent(originalEditContext, null); } base.Dispose(); diff --git a/MatterControlLib/CustomWidgets/CalibrationObjectPrinter.cs b/MatterControlLib/CustomWidgets/CalibrationObjectPrinter.cs index fdf765a70..f4d0869af 100644 --- a/MatterControlLib/CustomWidgets/CalibrationObjectPrinter.cs +++ b/MatterControlLib/CustomWidgets/CalibrationObjectPrinter.cs @@ -82,7 +82,8 @@ namespace MatterHackers.MatterControl { SourceItem = new FileSystemFileItem(gcodePath), ContentStore = null // No content store for GCode - }); + }, + null); await printer.Connection.StartPrint(finalGCodePath, printingMode: PrinterConnection.PrintingModes.Calibration); ApplicationController.Instance.MonitorPrintTask(printer); diff --git a/MatterControlLib/Library/Widgets/LibraryWidget.cs b/MatterControlLib/Library/Widgets/LibraryWidget.cs index 2b57b62d4..41a433cf4 100644 --- a/MatterControlLib/Library/Widgets/LibraryWidget.cs +++ b/MatterControlLib/Library/Widgets/LibraryWidget.cs @@ -785,7 +785,7 @@ namespace MatterHackers.MatterControl.PrintLibrary { Title = "Add to Bed".Localize(), Icon = StaticData.Instance.LoadIcon("bed_add.png", 16, 16).SetToColor(theme.TextColor), - Action = (selectedLibraryItems, listView) => + Action = async (selectedLibraryItems, listView) => { var activeContext = ApplicationController.Instance.DragDropData; var printer = activeContext.View3DWidget.Printer; @@ -794,14 +794,28 @@ namespace MatterHackers.MatterControl.PrintLibrary selectedLibraryItems.FirstOrDefault() is ILibraryAssetStream assetStream && assetStream.ContentType == "gcode") { - // Change loaded scene to new context - printer.Bed.LoadContent( - new EditContext() + await ApplicationController.Instance.Tasks.Execute( + "Loading".Localize() + "...", + null, + async (reporter, cancellationTokenSource) => { - SourceItem = assetStream, - // No content store for GCode - ContentStore = null - }).ConfigureAwait(false); + var progressStatus = new ProgressStatus(); + + // Change loaded scene to new context + await printer.Bed.LoadContent( + new EditContext() + { + SourceItem = assetStream, + // No content store for GCode + ContentStore = null + }, + (progress, message) => + { + progressStatus.Progress0To1 = progress; + progressStatus.Status = message; + reporter.Report(progressStatus); + }).ConfigureAwait(false); + }); } else { diff --git a/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs b/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs index dd17f0ecc..42eb1810f 100644 --- a/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs +++ b/MatterControlLib/Library/Widgets/ListView/LibraryListView.cs @@ -543,11 +543,23 @@ namespace MatterHackers.MatterControl.CustomWidgets mainViewWidget.TabControl.ActiveTab = partTab; // Load content after UI widgets to support progress notification during acquire/load - await workspace.SceneContext.LoadContent( - new EditContext() + await ApplicationController.Instance.Tasks.Execute( + "Loading".Localize() + "...", + null, + async (reporter, cancellationTokenSource) => { - ContentStore = writableContainer, - SourceItem = firstItem + var progressStatus = new ProgressStatus(); + var editContext = new EditContext() + { + ContentStore = writableContainer, + SourceItem = firstItem + }; + await workspace.SceneContext.LoadContent(editContext, (progress, message) => + { + progressStatus.Progress0To1 = progress; + progressStatus.Status = message; + reporter.Report(progressStatus); + }); }); } else diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index 73a794cf9..db2d800f2 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -490,7 +490,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { ContentStore = history, SourceItem = new FileSystemFileItem(filePath) - }); + }, null); ApplicationController.Instance.OpenWorkspace(workspace, WorkspacesChangedEventArgs.OperationType.Add); } @@ -866,7 +866,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow var workspace = new PartWorkspace(new BedConfig(history)); - await workspace.SceneContext.LoadContent(new EditContext()); + await workspace.SceneContext.LoadContent(new EditContext(), null); ApplicationController.Instance.Workspaces.Add(workspace); diff --git a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs index 314f3c3e2..155950910 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/View3DWidget.cs @@ -1024,7 +1024,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow printer.Bed.ClearPlate(); // Load current scene into new printer scene - await printer.Bed.LoadIntoCurrent(sceneContext.EditContext); + await printer.Bed.LoadIntoCurrent(sceneContext.EditContext, null); bool allInBounds = true; foreach (var item in printer.Bed.Scene.VisibleMeshes()) @@ -1281,7 +1281,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow SourceItem = this.SceneReplacement, // No content store for GCode ContentStore = null - }).ConfigureAwait(false); + }, null).ConfigureAwait(false); this.SceneReplacement = null; } diff --git a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs index 2b1278275..e7c0ec1c2 100644 --- a/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs +++ b/MatterControlLib/PartPreviewWindow/ViewToolBarControls.cs @@ -529,7 +529,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { await ApplicationController.Instance.Tasks.Execute("Saving changes".Localize() + "...", sceneContext.Printer, sceneContext.SaveChanges); - await sceneContext.LoadLibraryContent(item); + await sceneContext.LoadLibraryContent(item, null); if (sceneContext.Printer != null) { diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index e1ae998ba..020b11dbd 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -1675,6 +1675,9 @@ Translated:Fan Speed English:Fastest Translated:Fastest +English:Feature Detector +Translated:Feature Detector + English:Features Translated:Features @@ -2080,6 +2083,9 @@ Translated:Hide English:High Precision Translated:High Precision +English:Histogram +Translated:Histogram + English:History Translated:History @@ -2587,6 +2593,9 @@ Translated:Macros English:Maintain Proportions Translated:Maintain Proportions +English:Maintain Ratio +Translated:Maintain Ratio + English:Maintain Surface Translated:Maintain Surface @@ -3727,6 +3736,12 @@ Translated:Raise extruder English:Randomized Translated:Randomized +English:Range End +Translated:Range End + +English:Range Start +Translated:Range Start + English:Ratio Translated:Ratio @@ -3928,6 +3943,9 @@ Translated:Restore Settings English:Restore Settings... Translated:Restore Settings... +English:Restoring +Translated:Restoring + English:Resume Translated:Resume diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 31e47ce85..37a06c821 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 31e47ce851d4e9cb78ed8f6d9bf187db1f67db8a +Subproject commit 37a06c821f9ca9c8c3312082360b92cf7b631aed