Show loading / restoring progress

Fix null when canceling open system file
This commit is contained in:
LarsBrubaker 2022-02-20 07:59:28 -08:00
parent d931157145
commit aa8591ffe5
13 changed files with 149 additions and 75 deletions

View file

@ -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<string>();
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<persistedWorkspaces.Count; i++)
{
string printerID = persistedWorkspace.PrinterID;
PartWorkspace workspace = null;
if (!string.IsNullOrEmpty(printerID)
&& ProfileManager.Instance[printerID] != null)
var persistedWorkspace = persistedWorkspaces[i];
try
{
// Only create one workspace per printer
if (!loadedPrinters.Contains(printerID))
// Load the actual workspace if content file exists
if (File.Exists(persistedWorkspace.ContentPath))
{
// Add workspace for printer
workspace = new PartWorkspace(await this.LoadPrinter(persistedWorkspace.PrinterID));
string printerID = persistedWorkspace.PrinterID;
loadedPrinters.Add(printerID);
}
else
{
// Ignore additional workspaces for the same printer once one is loaded
continue;
PartWorkspace workspace = null;
if (!string.IsNullOrEmpty(printerID)
&& ProfileManager.Instance[printerID] != null)
{
// Only create one workspace per printer
if (!loadedPrinters.Contains(printerID))
{
// Add workspace for printer
workspace = new PartWorkspace(await this.LoadPrinter(persistedWorkspace.PrinterID));
loadedPrinters.Add(printerID);
}
else
{
// Ignore additional workspaces for the same printer once one is loaded
continue;
}
}
else
{
// Add workspace for part
workspace = new PartWorkspace(new BedConfig(history));
}
// Load the previous content
await workspace.SceneContext.LoadContent(new EditContext()
{
ContentStore = history,
SourceItem = new FileSystemFileItem(persistedWorkspace.ContentPath)
},
(progress, message) =>
{
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
{

View file

@ -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();

View file

@ -97,17 +97,18 @@ namespace MatterHackers.MatterControl
this.SceneLoaded?.Invoke(this, null);
}
public Task LoadLibraryContent(ILibraryItem libraryItem)
public Task LoadLibraryContent(ILibraryItem libraryItem, Action<double, string> 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<double, string> 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);
}
/// <summary>
@ -128,7 +129,7 @@ namespace MatterHackers.MatterControl
/// </summary>
/// <param name="editContext">The context to load into.</param>
/// <returns></returns>
public async Task LoadIntoCurrent(EditContext editContext)
public async Task LoadIntoCurrent(EditContext editContext, Action<double, string> 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(

View file

@ -72,15 +72,15 @@ namespace MatterHackers.MatterControl
void ClearPlate();
Task LoadContent(EditContext editContext);
Task LoadContent(EditContext editContext, Action<double, string> progressReporter);
void LoadEmptyContent(EditContext editContext);
Task LoadGCodeContent(Stream stream);
Task LoadIntoCurrent(EditContext editContext);
Task LoadIntoCurrent(EditContext editContext, Action<double, string> progressReporter);
Task LoadLibraryContent(ILibraryItem libraryItem);
Task LoadLibraryContent(ILibraryItem libraryItem, Action<double, string> progressReporter);
Task SaveChanges(IProgress<ProgressStatus> progress, CancellationTokenSource cancellationToken);

View file

@ -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();

View file

@ -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);

View file

@ -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
{

View file

@ -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

View file

@ -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);

View file

@ -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;
}

View file

@ -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)
{

View file

@ -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

@ -1 +1 @@
Subproject commit 31e47ce851d4e9cb78ed8f6d9bf187db1f67db8a
Subproject commit 37a06c821f9ca9c8c3312082360b92cf7b631aed