Merge pull request #5296 from larsbrubaker/main
Wait for Save to conclude before exiting
This commit is contained in:
commit
570207c961
10 changed files with 137 additions and 123 deletions
|
|
@ -729,7 +729,7 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
});
|
||||
|
||||
this.EditContext?.Save(this.Scene);
|
||||
await this.EditContext?.Save(this.Scene);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<PrintLevelingWizard.ProbePosition> probePositions;
|
||||
public class ConductiveProbeFeedback : WizardPage
|
||||
{
|
||||
private readonly List<PrintLevelingWizard.ProbePosition> 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<PrintLevelingWizard.ProbePosition> 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<PrintLevelingWizard.ProbePosition> 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<double>(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<double>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ILibraryItem, IObject3D> saveAction;
|
||||
private Func<ILibraryItem, IObject3D, Task> saveAction;
|
||||
|
||||
public DynamicContentStore(Action<ILibraryItem, IObject3D> saveAction)
|
||||
public DynamicContentStore(Func<ILibraryItem, IObject3D, Task> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) =>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<ILibraryItem> items);
|
||||
|
||||
public abstract void Save(ILibraryItem item, IObject3D content);
|
||||
public abstract Task Save(ILibraryItem item, IObject3D content);
|
||||
|
||||
public virtual void Move(IEnumerable<ILibraryItem> items, ILibraryWritableContainer sourceContainer)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue