Merge pull request #3795 from larsbrubaker/master
Refactoring MacrosChanged to event
This commit is contained in:
commit
c0408733c1
6 changed files with 44 additions and 19 deletions
|
|
@ -91,10 +91,16 @@ namespace MatterHackers.MatterControl.PrinterControls
|
|||
printer.Settings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
|
||||
};
|
||||
|
||||
printer.Settings.PrintLevelingEnabledChanged.RegisterEvent((sender, e) =>
|
||||
void Settings_PrintLevelingEnabledChanged(object sender, EventArgs e)
|
||||
{
|
||||
printLevelingSwitch.Checked = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled);
|
||||
}, ref unregisterEvents);
|
||||
}
|
||||
|
||||
printer.Settings.PrintLevelingEnabledChanged += Settings_PrintLevelingEnabledChanged;
|
||||
this.Closed += (s,e) =>
|
||||
{
|
||||
printer.Settings.PrintLevelingEnabledChanged -= Settings_PrintLevelingEnabledChanged;
|
||||
};
|
||||
|
||||
settingsRow.AddChild(printLevelingSwitch);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,10 +50,7 @@ namespace MatterHackers.MatterControl.PrinterControls
|
|||
this.theme = theme;
|
||||
this.Rebuild();
|
||||
|
||||
printer.Settings.MacrosChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() => Rebuild());
|
||||
}, ref unregisterEvents);
|
||||
printer.Settings.MacrosChanged += Settings_MacrosChanged;
|
||||
|
||||
ApplicationController.Instance.ActiveProfileModified.RegisterEvent((s, e) =>
|
||||
{
|
||||
|
|
@ -61,9 +58,15 @@ namespace MatterHackers.MatterControl.PrinterControls
|
|||
}, ref unregisterEvents);
|
||||
}
|
||||
|
||||
private void Settings_MacrosChanged(object sender, EventArgs e)
|
||||
{
|
||||
UiThread.RunOnIdle(() => Rebuild());
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
unregisterEvents?.Invoke(this, null);
|
||||
printer.Settings.MacrosChanged -= Settings_MacrosChanged;
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
pullDownContainer.AddChild(this.GetPulldownContainer());
|
||||
this.AddChild(pullDownContainer);
|
||||
|
||||
PrinterSettings.MaterialPresetChanged += ActiveSliceSettings_MaterialPresetChanged;
|
||||
printer.Settings.MaterialPresetChanged += ActiveSliceSettings_MaterialPresetChanged;
|
||||
PrinterSettings.SettingChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
if (e is StringEventArgs stringEvent
|
||||
|
|
@ -222,7 +222,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
PrinterSettings.MaterialPresetChanged -= ActiveSliceSettings_MaterialPresetChanged;
|
||||
printer.Settings.MaterialPresetChanged -= ActiveSliceSettings_MaterialPresetChanged;
|
||||
unregisterEvents?.Invoke(this, null);
|
||||
|
||||
base.OnClosed(e);
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
// TODO: Change to instance based, revise listeners and register to expect specific printer settings
|
||||
public static RootedObjectEventHandler SettingChanged = new RootedObjectEventHandler();
|
||||
|
||||
public static event EventHandler MaterialPresetChanged;
|
||||
public event EventHandler MaterialPresetChanged;
|
||||
|
||||
internal static void OnMaterialPresetChanged()
|
||||
public void OnMaterialPresetChanged()
|
||||
{
|
||||
MaterialPresetChanged?.Invoke(null, null);
|
||||
}
|
||||
|
|
@ -74,10 +74,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
SettingChanged.CallEvents(null, new StringEventArgs(slicerConfigName));
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public RootedObjectEventHandler PrintLevelingEnabledChanged = new RootedObjectEventHandler();
|
||||
public event EventHandler PrintLevelingEnabledChanged;
|
||||
|
||||
public RootedObjectEventHandler MacrosChanged = new RootedObjectEventHandler();
|
||||
public event EventHandler MacrosChanged;
|
||||
|
||||
public static PrinterSettings Empty { get; }
|
||||
|
||||
|
|
@ -140,7 +139,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
internal void NotifyMacrosChanged()
|
||||
{
|
||||
this.MacrosChanged.CallEvents(this, null);
|
||||
this.MacrosChanged?.Invoke(this, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -369,7 +368,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
MaterialLayer = GetMaterialLayer(materialKey);
|
||||
|
||||
PrinterSettings.OnMaterialPresetChanged();
|
||||
this.OnMaterialPresetChanged();
|
||||
}
|
||||
|
||||
Save();
|
||||
|
|
@ -527,6 +526,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
internal void OnPrintLevelingEnabledChanged(object s, EventArgs e)
|
||||
{
|
||||
PrintLevelingEnabledChanged?.Invoke(s, e);
|
||||
}
|
||||
|
||||
public static PrinterSettings RestoreFromOemProfile(PrinterInfo profile)
|
||||
{
|
||||
PrinterSettings oemProfile = null;
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
|
||||
printerSettings.SetValue(SettingsKey.print_leveling_enabled, doLeveling ? "1" : "0");
|
||||
|
||||
printerSettings.PrintLevelingEnabledChanged?.CallEvents(this, null);
|
||||
printerSettings.OnPrintLevelingEnabledChanged(this, null);
|
||||
}
|
||||
|
||||
public Vector2 ExtruderOffset(int extruderIndex)
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.GuiAutomation;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MatterControl.VersionManagement;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
[TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)]
|
||||
public class ReSliceTests
|
||||
{
|
||||
[Test, Category("Emulator"), Ignore("WorkInProgress")]
|
||||
[Test, Category("Emulator")]
|
||||
public async Task ReSliceHasCorrectEPositions()
|
||||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
|
|
@ -51,6 +52,9 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
|
||||
using (var emulator = testRunner.LaunchAndConnectToPrinterEmulator())
|
||||
{
|
||||
var view3D = testRunner.GetWidgetByName("View3DWidget", out _) as View3DWidget;
|
||||
var scene = view3D.InteractionLayer.Scene;
|
||||
|
||||
testRunner.OpenPrintPopupMenu();
|
||||
|
||||
// Add a pause on layer(in the center)
|
||||
|
|
@ -63,7 +67,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
double lastEPostion = 0;
|
||||
emulator.EPositionChanged += (e, s) =>
|
||||
{
|
||||
Assert.GreaterOrEqual(emulator.CurrentExtruder.EPosition, lastEPostion - 0, "We should never move back more than 5 mm");
|
||||
Assert.GreaterOrEqual(emulator.CurrentExtruder.EPosition, lastEPostion - 5, "We should never move back more than 5 mm");
|
||||
lastEPostion = emulator.CurrentExtruder.EPosition;
|
||||
};
|
||||
|
||||
|
|
@ -84,6 +88,11 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
testRunner.ClickByName("Bed Options Menu");
|
||||
testRunner.ClickByName("Clear Bed Menu Item");
|
||||
|
||||
testRunner.Delay(100);
|
||||
|
||||
// ensure there is nothing on the bed
|
||||
Assert.AreEqual(0, scene.Children.Count);
|
||||
|
||||
// Add a cylinder
|
||||
testRunner.ClickByName("Row Item cylinder_5x20");
|
||||
testRunner.ClickByName("Print Library Overflow Menu");
|
||||
|
|
@ -106,6 +115,9 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
testRunner.ClickByName("Bed Options Menu");
|
||||
testRunner.ClickByName("Clear Bed Menu Item");
|
||||
|
||||
// ensure there is nothing on the bed
|
||||
Assert.AreEqual(0, scene.Children.Count);
|
||||
|
||||
// add the cube
|
||||
testRunner.ClickByName("Row Item cube_20x20x20");
|
||||
testRunner.ClickByName("Print Library Overflow Menu");
|
||||
|
|
@ -124,7 +136,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}, maxTimeToRun: 90, queueItemFolderToAdd: QueueTemplate.ReSliceParts);
|
||||
}, maxTimeToRun: 190, queueItemFolderToAdd: QueueTemplate.ReSliceParts);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue