diff --git a/MatterControlLib/ApplicationView/Config/BedConfig.cs b/MatterControlLib/ApplicationView/Config/BedConfig.cs index 0ca7fb4a7..437837bc0 100644 --- a/MatterControlLib/ApplicationView/Config/BedConfig.cs +++ b/MatterControlLib/ApplicationView/Config/BedConfig.cs @@ -729,7 +729,7 @@ namespace MatterHackers.MatterControl } }); - this.EditContext?.Save(this.Scene); + await this.EditContext?.Save(this.Scene); } } diff --git a/MatterControlLib/ApplicationView/EditContext.cs b/MatterControlLib/ApplicationView/EditContext.cs index a4fc9f914..183276bbb 100644 --- a/MatterControlLib/ApplicationView/EditContext.cs +++ b/MatterControlLib/ApplicationView/EditContext.cs @@ -120,7 +120,7 @@ namespace MatterHackers.MatterControl } } - public void Save(IObject3D scene) + public async Task Save(IObject3D scene) { if (!this.FreezeGCode) { @@ -134,7 +134,7 @@ namespace MatterHackers.MatterControl using (new SelectionMaintainer(interactiveScene)) { // Call save on the provider - this.ContentStore?.Save(this.SourceItem, scene); + await this.ContentStore?.Save(this.SourceItem, scene); } interactiveScene.MarkSavePoint(); @@ -142,7 +142,7 @@ namespace MatterHackers.MatterControl else { // Call save on the provider - this.ContentStore?.Save(this.SourceItem, scene); + await this.ContentStore?.Save(this.SourceItem, scene); } } } diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/AligningZAxisPageInstructions.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/AligningZAxisPageInstructions.cs index c3cb771d1..6ba82288d 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/AligningZAxisPageInstructions.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/AligningZAxisPageInstructions.cs @@ -29,8 +29,6 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.MatterControl.PrinterCommunication; -using MatterHackers.MatterControl.SlicerConfiguration; using System; namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling @@ -38,6 +36,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling public class AligningZAxisPageInstructions : WizardPage { private bool calibrationComplete; + private bool g32HasBeenSent; public AligningZAxisPageInstructions(ISetupWizard setupWizard, string instructionsText) : base(setupWizard, "Aligning Z Axis".Localize(), instructionsText) @@ -50,12 +49,15 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // Unregister listeners printer.Connection.LineReceived -= Connection_LineRecieved; + printer.Connection.LineSent -= Connection_LineSent; base.OnClosed(e); } public override void OnLoad(EventArgs args) { + printer.Connection.LineSent += Connection_LineSent; + // Send the G34 Z Stepper Auto Align (https://reprap.org/wiki/G-code#G34:_Z_Stepper_Auto-Align) // 7 iterations .1 accuracy for early exit printer.Connection.QueueLine("G34 I7 T.1"); @@ -79,7 +81,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling private void Connection_LineRecieved(object sender, string reciviedString) { - if (reciviedString == "ok") + if (g32HasBeenSent && reciviedString == "ok") { calibrationComplete = true; printer.Connection.LineReceived -= Connection_LineRecieved; @@ -91,5 +93,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling UiThread.RunOnIdle(() => NextButton.InvokeClick()); } } + + private void Connection_LineSent(object sender, string sentString) + { + if (sentString.Contains("G34")) + { + g32HasBeenSent = true; + printer.Connection.LineSent -= Connection_LineSent; + } + } } } \ No newline at end of file diff --git a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/ConductiveProbeFeedback.cs b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/ConductiveProbeFeedback.cs index aac6accd3..d4658efa9 100644 --- a/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/ConductiveProbeFeedback.cs +++ b/MatterControlLib/ConfigurationPage/PrintLeveling/WizardPages/ConductiveProbeFeedback.cs @@ -27,131 +27,127 @@ 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.Linq; -using MatterControl.Printing; using MatterHackers.Agg.UI; -using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; +using System; +using System.Collections.Generic; namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { - public class ConductiveProbeFeedback : WizardPage - { - private readonly List probePositions; + public class ConductiveProbeFeedback : WizardPage + { + private readonly List probePositions; - private Vector3 nozzleCurrentPosition; + private Vector3 feedRates; + private double moveDelta = .5; + private Vector3 nozzleCurrentPosition; - public ConductiveProbeFeedback(ISetupWizard setupWizard, Vector3 nozzleStartPosition, string headerText, string details, List probePositions) - : base(setupWizard, headerText, details) - { - this.nozzleCurrentPosition = nozzleStartPosition; - this.probePositions = probePositions; + private State state = State.WaitingForEndstopStatusStart; - var spacer = new GuiWidget(15, 15); - contentRow.AddChild(spacer); + public ConductiveProbeFeedback(ISetupWizard setupWizard, Vector3 nozzleStartPosition, string headerText, string details, List probePositions) + : base(setupWizard, headerText, details) + { + this.nozzleCurrentPosition = nozzleStartPosition; + this.probePositions = probePositions; - feedRates = printer.Settings.Helpers.ManualMovementSpeeds(); - } + var spacer = new GuiWidget(15, 15); + contentRow.AddChild(spacer); - double moveDelta = .5; + feedRates = printer.Settings.Helpers.ManualMovementSpeeds(); + } - enum State - { - WaitingForEndstopStatusStart, - WaitingForEndstopStatusOk, - } + private enum State + { + WaitingForEndstopStatusStart, + WaitingForEndstopStatusOk, + } - State state = State.WaitingForEndstopStatusStart; - private Vector3 feedRates; + public bool MovedBelowMinZ { get; private set; } - public bool MovedBelowMinZ { get; private set; } + public override void OnClosed(EventArgs e) + { + printer.Connection.LineReceived -= PrinterLineRecieved; + base.OnClosed(e); + } - private void PrinterLineRecieved(object sender, string line) - { - // looking for 'conductive: TRIGGERED' in an M119 command - if (line != null) - { - switch (state) - { - case State.WaitingForEndstopStatusStart: - if (line.StartsWith("conductive:")) - { - if (line.Contains("TRIGGERED")) - { - if (moveDelta > .02) - { - nozzleCurrentPosition.Z += moveDelta * 3; - moveDelta *= .5; - state = State.WaitingForEndstopStatusOk; - } - else - { - probePositions[0].Position = nozzleCurrentPosition; + public override void OnLoad(EventArgs args) + { + // always make sure we don't have print leveling turned on + printer.Connection.AllowLeveling = false; - // move on to the next page of the wizard - UiThread.RunOnIdle(() => NextButton.InvokeClick()); - } - } - else // did not find endstop yet - { - nozzleCurrentPosition.Z -= moveDelta; - state = State.WaitingForEndstopStatusOk; - } - } - break; + NextButton.Enabled = false; - case State.WaitingForEndstopStatusOk: - // found the ok of the M119 command - // move down more - if (printer.Connection.CurrentDestination.Z < printer.Settings.GetValue(SettingsKey.conductive_probe_min_z)) - { - // we have gone down too far - // abort with error - this.MovedBelowMinZ = true; - // move on to the next page of the wizard - UiThread.RunOnIdle(() => NextButton.InvokeClick()); - } - else if (line.StartsWith("ok")) - { - state = State.WaitingForEndstopStatusStart; - // send the next set of commands - printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X); - printer.Connection.QueueLine("G4 P1"); - printer.Connection.QueueLine("M119"); - } - break; - } - } - } + // do a last minute check that the printer is ready to do this action + if (printer.Connection.IsConnected + && !(printer.Connection.Printing + || printer.Connection.Paused)) + { + printer.Connection.LineReceived += PrinterLineRecieved; + printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X); + printer.Connection.QueueLine("G4 P1"); + printer.Connection.QueueLine("M119"); + } - public override void OnLoad(EventArgs args) - { - // always make sure we don't have print leveling turned on - printer.Connection.AllowLeveling = false; + base.OnLoad(args); + } - NextButton.Enabled = false; + private void PrinterLineRecieved(object sender, string line) + { + // looking for 'conductive: TRIGGERED' in an M119 command + if (line != null) + { + switch (state) + { + case State.WaitingForEndstopStatusStart: + if (line.StartsWith("conductive:")) + { + if (line.Contains("TRIGGERED")) + { + if (moveDelta > .02) + { + nozzleCurrentPosition.Z += moveDelta * 3; + moveDelta *= .5; + state = State.WaitingForEndstopStatusOk; + } + else + { + probePositions[0].Position = nozzleCurrentPosition; - // do a last minute check that the printer is ready to do this action - if (printer.Connection.IsConnected - && !(printer.Connection.Printing - || printer.Connection.Paused)) - { - printer.Connection.LineReceived += PrinterLineRecieved; - printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X); - printer.Connection.QueueLine("G4 P1"); - printer.Connection.QueueLine("M119"); - } + // move on to the next page of the wizard + UiThread.RunOnIdle(() => NextButton.InvokeClick()); + } + } + else // did not find endstop yet + { + nozzleCurrentPosition.Z -= moveDelta; + state = State.WaitingForEndstopStatusOk; + } + } + break; - base.OnLoad(args); - } - - public override void OnClosed(EventArgs e) - { - printer.Connection.LineReceived -= PrinterLineRecieved; - base.OnClosed(e); - } - } + case State.WaitingForEndstopStatusOk: + // found the ok of the M119 command + // move down more + if (printer.Connection.CurrentDestination.Z < printer.Settings.GetValue(SettingsKey.conductive_probe_min_z)) + { + // we have gone down too far + // abort with error + this.MovedBelowMinZ = true; + // move on to the next page of the wizard + UiThread.RunOnIdle(() => NextButton.InvokeClick()); + } + else if (line.StartsWith("ok")) + { + state = State.WaitingForEndstopStatusStart; + // send the next set of commands + printer.Connection.MoveAbsolute(nozzleCurrentPosition, feedRates.X); + printer.Connection.QueueLine("G4 P1"); + printer.Connection.QueueLine("M119"); + } + break; + } + } + } + } } \ No newline at end of file diff --git a/MatterControlLib/Library/DynamicContentStore.cs b/MatterControlLib/Library/DynamicContentStore.cs index c8e216e2e..347cd92a9 100644 --- a/MatterControlLib/Library/DynamicContentStore.cs +++ b/MatterControlLib/Library/DynamicContentStore.cs @@ -28,15 +28,16 @@ either expressed or implied, of the FreeBSD Project. */ using System; +using System.Threading.Tasks; using MatterHackers.DataConverters3D; namespace MatterHackers.MatterControl.Library { public class DynamicContentStore : IContentStore { - private Action saveAction; + private Func saveAction; - public DynamicContentStore(Action saveAction) + public DynamicContentStore(Func saveAction) { this.saveAction = saveAction; } @@ -45,9 +46,9 @@ namespace MatterHackers.MatterControl.Library { } - public void Save(ILibraryItem item, IObject3D content) + public Task Save(ILibraryItem item, IObject3D content) { - saveAction.Invoke(item, content); + return saveAction.Invoke(item, content); } } } \ No newline at end of file diff --git a/MatterControlLib/Library/Interfaces/IContentStore.cs b/MatterControlLib/Library/Interfaces/IContentStore.cs index ab484186b..ffbd1c87a 100644 --- a/MatterControlLib/Library/Interfaces/IContentStore.cs +++ b/MatterControlLib/Library/Interfaces/IContentStore.cs @@ -29,11 +29,12 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.DataConverters3D; using System; +using System.Threading.Tasks; namespace MatterHackers.MatterControl.Library { public interface IContentStore : IDisposable { - void Save(ILibraryItem item, IObject3D content); + Task Save(ILibraryItem item, IObject3D content); } } diff --git a/MatterControlLib/Library/Providers/FileSystem/FileSystemContainer.cs b/MatterControlLib/Library/Providers/FileSystem/FileSystemContainer.cs index f4771ae91..c7e1aa499 100644 --- a/MatterControlLib/Library/Providers/FileSystem/FileSystemContainer.cs +++ b/MatterControlLib/Library/Providers/FileSystem/FileSystemContainer.cs @@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.Library } } - public override void Save(ILibraryItem item, IObject3D content) + public override async Task Save(ILibraryItem item, IObject3D content) { if (item is FileSystemFileItem fileItem) { @@ -96,7 +96,7 @@ namespace MatterHackers.MatterControl.Library } else { - ApplicationController.Instance.Tasks.Execute( + await ApplicationController.Instance.Tasks.Execute( "Saving Changes".Localize(), null, async (reporter, cancellationTokenSource) => diff --git a/MatterControlLib/Library/Providers/Sqlite/SqliteLibraryContainer.cs b/MatterControlLib/Library/Providers/Sqlite/SqliteLibraryContainer.cs index f8104687f..a37055544 100644 --- a/MatterControlLib/Library/Providers/Sqlite/SqliteLibraryContainer.cs +++ b/MatterControlLib/Library/Providers/Sqlite/SqliteLibraryContainer.cs @@ -190,7 +190,7 @@ namespace MatterHackers.MatterControl.Library this.ReloadContent(); } - public override void Save(ILibraryItem item, IObject3D content) + public override Task Save(ILibraryItem item, IObject3D content) { if (item is FileSystemFileItem fileItem) { @@ -200,6 +200,8 @@ namespace MatterHackers.MatterControl.Library this.OnItemContentChanged(new LibraryItemChangedEventArgs(fileItem)); } + + return null; } public override void SetThumbnail(ILibraryItem item, int width, int height, ImageBuffer imageBuffer) diff --git a/MatterControlLib/Library/Providers/WritableContainer.cs b/MatterControlLib/Library/Providers/WritableContainer.cs index c5a9502e2..05ad5db6a 100644 --- a/MatterControlLib/Library/Providers/WritableContainer.cs +++ b/MatterControlLib/Library/Providers/WritableContainer.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using MatterHackers.Agg.Image; using MatterHackers.DataConverters3D; @@ -49,7 +50,7 @@ namespace MatterHackers.MatterControl.Library public abstract void Remove(IEnumerable items); - public abstract void Save(ILibraryItem item, IObject3D content); + public abstract Task Save(ILibraryItem item, IObject3D content); public virtual void Move(IEnumerable items, ILibraryWritableContainer sourceContainer) { diff --git a/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs b/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs index 4d30a33c4..6b9d8206d 100644 --- a/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs +++ b/MatterControlLib/PartPreviewWindow/SelectedObjectPanel.cs @@ -534,13 +534,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow editorPanel.AddChild(editorWidget); } - public void Save(ILibraryItem item, IObject3D content) + public Task Save(ILibraryItem item, IObject3D content) { this.item.Parent.Children.Modify(children => { children.Remove(this.item); children.Add(content); }); + + return null; } public override void OnClosed(EventArgs e)