Make PrinterConnection.PrinterSettings private, use PrinterConfig

This commit is contained in:
John Lewin 2017-09-15 12:08:00 -07:00
parent 294dd4a812
commit e1f3dec6b1
28 changed files with 540 additions and 550 deletions

View file

@ -59,18 +59,19 @@ namespace MatterHackers.MatterControl.ActionBar
private EventHandler unregisterEvents;
PrinterConnection printerConnection;
private PrinterConfig printer;
public PrintActionRow(PrinterConnection printerConnection, TextImageButtonFactory buttonFactory, GuiWidget parentWidget, BorderDouble defaultMargin)
public PrintActionRow(PrinterConfig printer, TextImageButtonFactory buttonFactory, GuiWidget parentWidget, BorderDouble defaultMargin)
{
this.printerConnection = printerConnection;
this.printer = printer;
this.HAnchor = HAnchor.Stretch;
AddChildElements(buttonFactory, parentWidget, defaultMargin);
// Add Handlers
ApplicationController.Instance.ActivePrintItemChanged.RegisterEvent(onStateChanged, ref unregisterEvents);
printerConnection.CommunicationStateChanged.RegisterEvent(onStateChanged, ref unregisterEvents);
printer.Connection.CommunicationStateChanged.RegisterEvent(onStateChanged, ref unregisterEvents);
ProfileManager.ProfilesListChanged.RegisterEvent(onStateChanged, ref unregisterEvents);
}
@ -99,14 +100,14 @@ namespace MatterHackers.MatterControl.ActionBar
resetConnectionButton = buttonFactory.Generate("Reset".Localize().ToUpper(), AggContext.StaticData.LoadIcon("e_stop.png", 14, 14));
resetConnectionButton.ToolTipText = "Reboots the firmware on the controller".Localize();
resetConnectionButton.Margin = defaultMargin;
resetConnectionButton.Click += (s, e) => UiThread.RunOnIdle(printerConnection.RebootBoard);
resetConnectionButton.Click += (s, e) => UiThread.RunOnIdle(printer.Connection.RebootBoard);
pauseButton = buttonFactory.Generate("Pause".Localize().ToUpper());
pauseButton.ToolTipText = "Pause the current print".Localize();
pauseButton.Margin = defaultMargin;
pauseButton.Click += (s, e) =>
{
UiThread.RunOnIdle(printerConnection.RequestPause);
UiThread.RunOnIdle(printer.Connection.RequestPause);
pauseButton.Enabled = false;
};
parentWidget.AddChild(pauseButton);
@ -137,9 +138,9 @@ namespace MatterHackers.MatterControl.ActionBar
resumeButton.Name = "Resume Button";
resumeButton.Click += (s, e) =>
{
if (printerConnection.PrinterIsPaused)
if (printer.Connection.PrinterIsPaused)
{
printerConnection.Resume();
printer.Connection.Resume();
}
pauseButton.Enabled = true;
};
@ -169,7 +170,7 @@ namespace MatterHackers.MatterControl.ActionBar
SetButtonStates();
printerConnection.PrinterSettings.PrintLevelingEnabledChanged.RegisterEvent((s, e) => SetButtonStates(), ref unregisterEvents);
printer.Settings.PrintLevelingEnabledChanged.RegisterEvent((s, e) => SetButtonStates(), ref unregisterEvents);
}
protected void DisableActiveButtons()
@ -192,8 +193,8 @@ namespace MatterHackers.MatterControl.ActionBar
protected void SetButtonStates()
{
this.activePrintButtons.Clear();
if (!printerConnection.PrinterIsConnected
&& printerConnection.CommunicationState != CommunicationStates.AttemptingToConnect)
if (!printer.Connection.PrinterIsConnected
&& printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect)
{
if (!ProfileManager.Instance.ActiveProfiles.Any())
{
@ -206,7 +207,7 @@ namespace MatterHackers.MatterControl.ActionBar
}
else
{
switch (printerConnection.CommunicationState)
switch (printer.Connection.CommunicationState)
{
case CommunicationStates.AttemptingToConnect:
this.activePrintButtons.Add(cancelConnectButton);
@ -214,8 +215,8 @@ namespace MatterHackers.MatterControl.ActionBar
break;
case CommunicationStates.Connected:
PrintLevelingData levelingData = printerConnection.PrinterSettings.Helpers.GetPrintLevelingData();
if (levelingData != null && printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
if (levelingData != null && printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
&& !levelingData.HasBeenRunAndEnabled())
{
this.activePrintButtons.Add(finishSetupButton);
@ -235,7 +236,7 @@ namespace MatterHackers.MatterControl.ActionBar
case CommunicationStates.PrintingFromSd:
case CommunicationStates.Printing:
if (!printerConnection.PrintWasCanceled)
if (!printer.Connection.PrintWasCanceled)
{
this.activePrintButtons.Add(pauseButton);
this.activePrintButtons.Add(cancelButton);
@ -265,8 +266,8 @@ namespace MatterHackers.MatterControl.ActionBar
}
}
if (printerConnection.PrinterIsConnected
&& printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.show_reset_connection))
if (printer.Connection.PrinterIsConnected
&& printer.Settings.GetValue<bool>(SettingsKey.show_reset_connection))
{
this.activePrintButtons.Add(resetConnectionButton);
ShowActiveButtons();

View file

@ -45,17 +45,17 @@ namespace MatterHackers.MatterControl.ActionBar
private readonly string resetConnectionText = "Reset\nConnection".Localize().ToUpper();
private EventHandler unregisterEvents;
public ResetButton(PrinterConnection printerConnection, TextImageButtonFactory buttonFactory)
public ResetButton(PrinterConfig printer, TextImageButtonFactory buttonFactory)
{
this.HAnchor = HAnchor.Stretch | HAnchor.Fit;
this.VAnchor = VAnchor.Fit;
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
Button resetConnectionButton = buttonFactory.Generate(resetConnectionText, "e_stop4.png");
resetConnectionButton.Visible = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.show_reset_connection);
resetConnectionButton.Visible = printer.Settings.GetValue<bool>(SettingsKey.show_reset_connection);
resetConnectionButton.Click += (s, e) =>
{
UiThread.RunOnIdle(printerConnection.RebootBoard);
UiThread.RunOnIdle(printer.Connection.RebootBoard);
};
this.AddChild(resetConnectionButton);
@ -64,7 +64,7 @@ namespace MatterHackers.MatterControl.ActionBar
var stringEvent = e as StringEventArgs;
if (stringEvent?.Data == SettingsKey.show_reset_connection)
{
resetConnectionButton.Visible = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.show_reset_connection);
resetConnectionButton.Visible = printer.Settings.GetValue<bool>(SettingsKey.show_reset_connection);
}
}, ref unregisterEvents);
}
@ -175,11 +175,11 @@ namespace MatterHackers.MatterControl.ActionBar
private Button disconnectButton;
private EventHandler unregisterEvents;
PrinterConnection printerConnection;
private PrinterConfig printer;
public PrinterConnectButton(PrinterConnection printerConnection, TextImageButtonFactory buttonFactory, BorderDouble margin)
public PrinterConnectButton(PrinterConfig printer, TextImageButtonFactory buttonFactory, BorderDouble margin)
{
this.printerConnection = printerConnection;
this.printer = printer;
this.HAnchor = HAnchor.Left | HAnchor.Fit;
this.VAnchor = VAnchor.Fit;
this.Margin = 0;
@ -192,7 +192,7 @@ namespace MatterHackers.MatterControl.ActionBar
{
if (connectButton.Enabled)
{
if (printerConnection.PrinterSettings.PrinterSelected)
if (printer.Settings.PrinterSelected)
{
UserRequestedConnectToActivePrinter();
}
@ -206,15 +206,15 @@ namespace MatterHackers.MatterControl.ActionBar
disconnectButton.ToolTipText = "Disconnect from current printer".Localize();
disconnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
{
if (printerConnection.PrinterIsPrinting)
if (printer.Connection.PrinterIsPrinting)
{
StyledMessageBox.ShowMessageBox(
(bool disconnectCancel) =>
{
if (disconnectCancel)
{
printerConnection.Stop(false);
printerConnection.Disable();
printer.Connection.Stop(false);
printer.Connection.Disable();
}
},
disconnectAndCancelMessage,
@ -225,7 +225,7 @@ namespace MatterHackers.MatterControl.ActionBar
}
else
{
printerConnection.Disable();
printer.Connection.Disable();
}
});
this.AddChild(disconnectButton);
@ -241,8 +241,8 @@ namespace MatterHackers.MatterControl.ActionBar
// Bind connect button states to active printer state
this.SetVisibleStates(null, null);
printerConnection.EnableChanged.RegisterEvent(SetVisibleStates, ref unregisterEvents);
printerConnection.CommunicationStateChanged.RegisterEvent(SetVisibleStates, ref unregisterEvents);
printer.Connection.EnableChanged.RegisterEvent(SetVisibleStates, ref unregisterEvents);
printer.Connection.CommunicationStateChanged.RegisterEvent(SetVisibleStates, ref unregisterEvents);
}
public override void OnClosed(ClosedEventArgs e)
@ -253,10 +253,10 @@ namespace MatterHackers.MatterControl.ActionBar
public void UserRequestedConnectToActivePrinter()
{
if (printerConnection.PrinterSettings.PrinterSelected)
if (printer.Settings.PrinterSelected)
{
#if __ANDROID__
if (!printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.enable_network_printing)
if (!printer.Settings.GetValue<bool>(SettingsKey.enable_network_printing)
&& !FrostedSerialPort.HasPermissionToDevice())
{
// Opens the USB device permissions dialog which will call back into our UsbDevice broadcast receiver to connect
@ -265,8 +265,8 @@ namespace MatterHackers.MatterControl.ActionBar
else
#endif
{
printerConnection.HaltConnectionThread();
printerConnection.ConnectToActivePrinter(true);
printer.Connection.HaltConnectionThread();
printer.Connection.ConnectToActivePrinter(true);
}
}
}
@ -280,7 +280,7 @@ namespace MatterHackers.MatterControl.ActionBar
{
UiThread.RunOnIdle(() =>
{
if (printerConnection.PrinterIsConnected)
if (printer.Connection.PrinterIsConnected)
{
disconnectButton.Visible = true;
connectButton.Visible = false;
@ -291,10 +291,10 @@ namespace MatterHackers.MatterControl.ActionBar
connectButton.Visible = true;
}
var communicationState = printerConnection.CommunicationState;
var communicationState = printer.Connection.CommunicationState;
// Ensure connect buttons are locked while long running processes are executing to prevent duplicate calls into said actions
connectButton.Enabled = printerConnection.PrinterSettings.PrinterSelected
connectButton.Enabled = printer.Settings.PrinterSelected
&& communicationState != CommunicationStates.AttemptingToConnect;
disconnectButton.Enabled = communicationState != CommunicationStates.Disconnecting;

View file

@ -50,14 +50,14 @@ namespace MatterHackers.MatterControl.ActionBar
};
protected EventHandler unregisterEvents;
protected PrinterConnection printerConnection;
protected PrinterConfig printer;
protected virtual int ActualTemperature { get; }
protected virtual int TargetTemperature { get; }
public TemperatureWidgetBase(PrinterConnection printerConnection, string textValue)
public TemperatureWidgetBase(PrinterConfig printer, string textValue)
{
this.printerConnection = printerConnection;
this.printer = printer;
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Fit | VAnchor.Center;
this.Cursor = Cursors.Hand;

View file

@ -48,8 +48,8 @@ namespace MatterHackers.MatterControl.ActionBar
private string waitingForBedToHeatMessage = "The bed is currently heating and its target temperature cannot be changed until it reaches {0}°C.\n\nYou can set the starting bed temperature in SETTINGS -> Filament -> Temperatures.\n\n{1}".Localize();
private string waitingForBedToHeatTitle = "Waiting For Bed To Heat".Localize();
public TemperatureWidgetBed(PrinterConnection printerConnection)
: base(printerConnection, "150.3°")
public TemperatureWidgetBed(PrinterConfig printer)
: base(printer, "150.3°")
{
this.DisplayCurrentTemperature();
this.ToolTipText = "Current bed temperature".Localize();
@ -64,11 +64,11 @@ namespace MatterHackers.MatterControl.ActionBar
this.PopupContent = this.GetPopupContent();
printerConnection.BedTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents);
printer.Connection.BedTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents);
}
protected override int ActualTemperature => (int)printerConnection.ActualBedTemperature;
protected override int TargetTemperature => (int)printerConnection.TargetBedTemperature;
protected override int ActualTemperature => (int)printer.Connection.ActualBedTemperature;
protected override int TargetTemperature => (int)printer.Connection.TargetBedTemperature;
public override void OnClosed(ClosedEventArgs e)
{
@ -105,7 +105,7 @@ namespace MatterHackers.MatterControl.ActionBar
Checked = false,
ToggleAction = (itemChecked) =>
{
var goalTemp = itemChecked ? printerConnection.PrinterSettings.GetValue<double>(SettingsKey.bed_temperature) : 0;
var goalTemp = itemChecked ? printer.Settings.GetValue<double>(SettingsKey.bed_temperature) : 0;
if (itemChecked)
{
@ -123,7 +123,7 @@ namespace MatterHackers.MatterControl.ActionBar
heatToggle.Name = "Toggle Heater";
// put in the temp control
settingsTemperature = new EditableNumberDisplay(printerConnection.PrinterSettings.GetValue<double>(SettingsKey.bed_temperature), "000")
settingsTemperature = new EditableNumberDisplay(printer.Settings.GetValue<double>(SettingsKey.bed_temperature), "000")
{
TextColor = RGBA_Bytes.Black,
BorderColor = RGBA_Bytes.Black,
@ -184,24 +184,24 @@ namespace MatterHackers.MatterControl.ActionBar
protected override void SetTargetTemperature(double targetTemp)
{
double goalTemp = (int)(targetTemp + .5);
if (printerConnection.PrinterIsPrinting
&& printerConnection.DetailedPrintingState == DetailedPrintingState.HeatingBed
&& goalTemp != printerConnection.TargetBedTemperature)
if (printer.Connection.PrinterIsPrinting
&& printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingBed
&& goalTemp != printer.Connection.TargetBedTemperature)
{
string message = string.Format(waitingForBedToHeatMessage, printerConnection.TargetBedTemperature, sliceSettingsNote);
string message = string.Format(waitingForBedToHeatMessage, printer.Connection.TargetBedTemperature, sliceSettingsNote);
StyledMessageBox.ShowMessageBox(null, message, waitingForBedToHeatTitle);
}
else
{
printerConnection.TargetBedTemperature = (int)(targetTemp + .5);
printer.Connection.TargetBedTemperature = (int)(targetTemp + .5);
}
}
private void ActiveSliceSettings_MaterialPresetChanged(object sender, EventArgs e)
{
if (settingsTemperature != null && printerConnection.PrinterSettings != null)
if (settingsTemperature != null && printer.Settings != null)
{
settingsTemperature.Text = printerConnection.PrinterSettings.GetValue(SettingsKey.bed_temperature);
settingsTemperature.Text = printer.Settings.GetValue(SettingsKey.bed_temperature);
}
}
}

View file

@ -42,14 +42,14 @@ namespace MatterHackers.MatterControl.ActionBar
internal class ControlContentExtruder : FlowLayoutWidget
{
private int moveAmount = 1;
private PrinterConnection printerConnection;
private PrinterConfig printer;
internal ControlContentExtruder(PrinterConnection printerConnection, int extruderIndex, TextImageButtonFactory buttonFactory)
internal ControlContentExtruder(PrinterConfig printer, int extruderIndex, TextImageButtonFactory buttonFactory)
: base(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch;
this.printerConnection = printerConnection;
this.printer = printer;
// add in any macros for this extruder
var macroButtons = GetExtruderMacros(extruderIndex, buttonFactory);
@ -72,7 +72,7 @@ namespace MatterHackers.MatterControl.ActionBar
retractButton.Margin = new BorderDouble(8, 0);
retractButton.Click += (s, e) =>
{
printerConnection.MoveExtruderRelative(moveAmount * -1, printerConnection.PrinterSettings.EFeedRate(extruderIndex), extruderIndex);
printer.Connection.MoveExtruderRelative(moveAmount * -1, printer.Settings.EFeedRate(extruderIndex), extruderIndex);
};
buttonContainer.AddChild(retractButton);
@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.ActionBar
extrudeButton.Margin = 0;
extrudeButton.Click += (s, e) =>
{
printerConnection.MoveExtruderRelative(moveAmount, printerConnection.PrinterSettings.EFeedRate(extruderIndex), extruderIndex);
printer.Connection.MoveExtruderRelative(moveAmount, printer.Settings.EFeedRate(extruderIndex), extruderIndex);
};
buttonContainer.AddChild(extrudeButton);
@ -147,7 +147,7 @@ namespace MatterHackers.MatterControl.ActionBar
MacroUiLocation extruderUiMacros;
if (Enum.TryParse($"Extruder_{extruderIndex + 1}", out extruderUiMacros))
{
var macros = printerConnection.PrinterSettings.GetMacros(extruderUiMacros);
var macros = printer.Settings.GetMacros(extruderUiMacros);
if (macros.Any())
{
var row = new FlowLayoutWidget();
@ -155,7 +155,7 @@ namespace MatterHackers.MatterControl.ActionBar
{
Button macroButton = buttonFactory.Generate(GCodeMacro.FixMacroName(macro.Name));
macroButton.Margin = new BorderDouble(left: 5);
macroButton.Click += (s, e) => macro.Run(printerConnection);
macroButton.Click += (s, e) => macro.Run(printer.Connection);
row.AddChild(macroButton);
}
@ -176,8 +176,8 @@ namespace MatterHackers.MatterControl.ActionBar
private string sliceSettingsNote = "Note: Slice Settings are applied before the print actually starts. Changes while printing will not effect the active print.".Localize();
private string waitingForExtruderToHeatMessage = "The extruder is currently heating and its target temperature cannot be changed until it reaches {0}°C.\n\nYou can set the starting extruder temperature in 'Slice Settings' -> 'Filament'.\n\n{1}".Localize();
public TemperatureWidgetHotend(PrinterConnection printerConnection, int hotendIndex, TextImageButtonFactory buttonFactory)
: base(printerConnection, "150.3°")
public TemperatureWidgetHotend(PrinterConfig printer, int hotendIndex, TextImageButtonFactory buttonFactory)
: base(printer, "150.3°")
{
this.Name = $"Hotend {hotendIndex}";
this.hotendIndex = hotendIndex;
@ -187,11 +187,11 @@ namespace MatterHackers.MatterControl.ActionBar
this.PopupContent = this.GetPopupContent();
printerConnection.HotendTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents);
printer.Connection.HotendTemperatureRead.RegisterEvent((s, e) => DisplayCurrentTemperature(), ref unregisterEvents);
}
protected override int ActualTemperature => (int)printerConnection.GetActualHotendTemperature(hotendIndex);
protected override int TargetTemperature => (int)printerConnection.GetTargetHotendTemperature(hotendIndex);
protected override int ActualTemperature => (int)printer.Connection.GetActualHotendTemperature(hotendIndex);
protected override int TargetTemperature => (int)printer.Connection.GetTargetHotendTemperature(hotendIndex);
public override void OnClosed(ClosedEventArgs e)
{
@ -234,7 +234,7 @@ namespace MatterHackers.MatterControl.ActionBar
else
{
// Turn off extruder
printerConnection.SetTargetHotendTemperature(hotendIndex, 0);
printer.Connection.SetTargetHotendTemperature(hotendIndex, 0);
}
}
},
@ -244,7 +244,7 @@ namespace MatterHackers.MatterControl.ActionBar
heatToggle.Name = "Toggle Heater";
// put in the temp control
settingsTemperature = new EditableNumberDisplay(printerConnection.PrinterSettings.GetValue<double>(SettingsKey.temperature), "000")
settingsTemperature = new EditableNumberDisplay(printer.Settings.GetValue<double>(SettingsKey.temperature), "000")
{
TextColor = RGBA_Bytes.Black,
BorderColor = RGBA_Bytes.Black,
@ -308,7 +308,7 @@ namespace MatterHackers.MatterControl.ActionBar
// delay this for an update so the slice setting can get updated first
UiThread.RunOnIdle(() =>
{
settingsTemperature.Value = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.temperature);
settingsTemperature.Value = printer.Settings.GetValue<double>(SettingsKey.temperature);
});
};
@ -333,8 +333,8 @@ namespace MatterHackers.MatterControl.ActionBar
container.AddChild(new SettingsItem("Material".Localize(), presetsSelector, enforceGutter: false));
// put in the actual extruder controls
bool shareTemp = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.extruders_share_temperature);
int extruderCount = printerConnection.PrinterSettings.GetValue<int>(SettingsKey.extruder_count);
bool shareTemp = printer.Settings.GetValue<bool>(SettingsKey.extruders_share_temperature);
int extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
if (shareTemp && extruderCount > 1)
{
for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
@ -350,12 +350,12 @@ namespace MatterHackers.MatterControl.ActionBar
TextColor = RGBA_Bytes.Black,
HAnchor = HAnchor.Left,
});
container.AddChild(new ControlContentExtruder(printerConnection, extruderIndex, buttonFactory));
container.AddChild(new ControlContentExtruder(printer, extruderIndex, buttonFactory));
}
}
else
{
container.AddChild(new ControlContentExtruder(printerConnection, hotendIndex, buttonFactory));
container.AddChild(new ControlContentExtruder(printer, hotendIndex, buttonFactory));
}
ActiveSliceSettings.MaterialPresetChanged += ActiveSliceSettings_MaterialPresetChanged;
@ -366,24 +366,24 @@ namespace MatterHackers.MatterControl.ActionBar
protected override void SetTargetTemperature(double targetTemp)
{
double goalTemp = (int)(targetTemp + .5);
if (printerConnection.PrinterIsPrinting
&& printerConnection.DetailedPrintingState == DetailedPrintingState.HeatingExtruder
&& goalTemp != printerConnection.GetTargetHotendTemperature(hotendIndex))
if (printer.Connection.PrinterIsPrinting
&& printer.Connection.DetailedPrintingState == DetailedPrintingState.HeatingExtruder
&& goalTemp != printer.Connection.GetTargetHotendTemperature(hotendIndex))
{
string message = string.Format(waitingForExtruderToHeatMessage, printerConnection.GetTargetHotendTemperature(hotendIndex), sliceSettingsNote);
string message = string.Format(waitingForExtruderToHeatMessage, printer.Connection.GetTargetHotendTemperature(hotendIndex), sliceSettingsNote);
StyledMessageBox.ShowMessageBox(null, message, "Waiting For Extruder To Heat".Localize());
}
else
{
printerConnection.SetTargetHotendTemperature(hotendIndex, (int)(targetTemp + .5));
printer.Connection.SetTargetHotendTemperature(hotendIndex, (int)(targetTemp + .5));
}
}
private void ActiveSliceSettings_MaterialPresetChanged(object sender, EventArgs e)
{
if (settingsTemperature != null && printerConnection.PrinterSettings != null)
if (settingsTemperature != null && printer.Settings != null)
{
settingsTemperature.Text = printerConnection.PrinterSettings.GetValue(SettingsKey.temperature);
settingsTemperature.Text = printer.Settings.GetValue(SettingsKey.temperature);
}
}
}

View file

@ -278,6 +278,7 @@ namespace MatterHackers.MatterControl
public BedConfig Bed { get; }
public PrinterViewState ViewState { get; } = new PrinterViewState();
public PrinterSettings Settings { get; private set; } = ActiveSliceSettings.Instance;
public PrinterConnection Connection { get; private set; } = PrinterConnection.Instance;
private EventHandler unregisterEvents;
@ -710,13 +711,15 @@ namespace MatterHackers.MatterControl
PrinterConnection.Instance.CommunicationStateChanged.RegisterEvent((s, e) =>
{
PrinterConnection printerConnection = s as PrinterConnection;
var printerConnection = s as PrinterConnection;
switch (printerConnection.CommunicationState)
{
case CommunicationStates.Printing:
if (UserSettings.Instance.IsTouchScreen)
{
UiThread.RunOnIdle(() => PrintingWindow.Show(printerConnection));
// TODO: In general this basic hook won't work with multi-tenancy
UiThread.RunOnIdle(() => PrintingWindow.Show(ApplicationController.Instance.Printer)); // HACK: We need to show the instance that's printing not the static instance
}
break;
@ -734,7 +737,7 @@ namespace MatterHackers.MatterControl
PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();
if (levelingData?.HasBeenRunAndEnabled() != true)
{
UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(PrinterConnection.Instance));
UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(ApplicationController.Instance.Printer));// HACK: We need to show the instance that's printing not the static instance
}
}
}, ref unregisterEvents);
@ -1366,7 +1369,7 @@ namespace MatterHackers.MatterControl
PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();
if (levelingData?.HasBeenRunAndEnabled() != true)
{
LevelWizardBase.ShowPrintLevelWizard(PrinterConnection.Instance);
LevelWizardBase.ShowPrintLevelWizard(ApplicationController.Instance.Printer);// HACK: We need to show the instance that's printing not the static instance
return;
}
}

View file

@ -24,11 +24,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage
private Button runPrintLevelingButton;
private TextImageButtonFactory buttonFactory;
PrinterConnection printerConnection;
private PrinterConfig printer;
public CalibrationSettingsWidget(PrinterConnection printerConnection, TextImageButtonFactory buttonFactory, int headingPointSize)
public CalibrationSettingsWidget(PrinterConfig printer, TextImageButtonFactory buttonFactory, int headingPointSize)
{
this.printerConnection = printerConnection;
this.printer = printer;
var mainContainer = new AltGroupBox(new TextWidget("Calibration".Localize(), pointSize: headingPointSize, textColor: ActiveTheme.Instance.SecondaryAccentColor))
{
Margin = new BorderDouble(0),
@ -48,15 +49,15 @@ namespace MatterHackers.MatterControl.ConfigurationPage
this.buttonFactory = buttonFactory;
if (!printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_hardware_leveling))
if (!printer.Settings.GetValue<bool>(SettingsKey.has_hardware_leveling))
{
container.AddChild(GetAutoLevelControl());
}
container.AddChild(CreateSeparatorLine());
printerConnection.CommunicationStateChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
printerConnection.EnableChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
printer.Connection.CommunicationStateChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
printer.Connection.EnableChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
SetVisibleControls();
}
@ -102,7 +103,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
{
if (editLevelingSettingsWindow == null)
{
editLevelingSettingsWindow = new EditLevelingSettingsWindow(printerConnection.PrinterSettings);
editLevelingSettingsWindow = new EditLevelingSettingsWindow(printer.Settings);
editLevelingSettingsWindow.Closed += (sender2, e2) =>
{
editLevelingSettingsWindow = null;
@ -125,26 +126,26 @@ namespace MatterHackers.MatterControl.ConfigurationPage
runPrintLevelingButton.VAnchor = VAnchor.Center;
runPrintLevelingButton.Click += (sender, e) =>
{
UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(printerConnection, LevelWizardBase.RuningState.UserRequestedCalibration));
UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(printer, LevelWizardBase.RuningState.UserRequestedCalibration));
};
buttonRow.AddChild(runPrintLevelingButton);
// put in the switch
CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.print_leveling_enabled));
CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled));
printLevelingSwitch.VAnchor = VAnchor.Center;
printLevelingSwitch.Margin = new BorderDouble(left: 16);
printLevelingSwitch.CheckedStateChanged += (sender, e) =>
{
printerConnection.PrinterSettings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
printer.Settings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
};
printerConnection.PrinterSettings.PrintLevelingEnabledChanged.RegisterEvent((sender, e) =>
printer.Settings.PrintLevelingEnabledChanged.RegisterEvent((sender, e) =>
{
printLevelingSwitch.Checked = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.print_leveling_enabled);
printLevelingSwitch.Checked = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled);
}, ref unregisterEvents);
// only show the switch if leveling can be turned off (it can't if it is required).
if (!printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.print_leveling_required_to_print))
if (!printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print))
{
buttonRow.AddChild(printLevelingSwitch);
}
@ -166,9 +167,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage
private void SetVisibleControls()
{
if (!printerConnection.PrinterSettings.PrinterSelected
|| printerConnection.CommunicationState == CommunicationStates.Printing
|| printerConnection.PrinterIsPaused)
if (!printer.Settings.PrinterSelected
|| printer.Connection.CommunicationState == CommunicationStates.Printing
|| printer.Connection.PrinterIsPaused)
{
this.SetEnableLevel(DisableableWidget.EnableLevel.Disabled);
runPrintLevelingButton.Enabled = true; // setting this true when the element is disabled makes the colors stay correct
@ -176,7 +177,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
else
{
this.SetEnableLevel(DisableableWidget.EnableLevel.Enabled);
runPrintLevelingButton.Enabled = printerConnection.PrinterIsConnected;
runPrintLevelingButton.Enabled = printer.Connection.PrinterIsConnected;
}
}
}

View file

@ -30,8 +30,6 @@ either expressed or implied, of the FreeBSD Project.
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl
{
@ -40,9 +38,13 @@ namespace MatterHackers.MatterControl
double extraTextScaling = 1;
protected FlowLayoutWidget topToBottomControls;
public InstructionsPage(string pageDescription, string instructionsText)
protected PrinterConfig printer { get; }
public InstructionsPage(PrinterConfig printer, string pageDescription, string instructionsText)
: base(pageDescription)
{
this.printer = printer;
if (UserSettings.Instance.IsTouchScreen)
{
extraTextScaling = 1.33333;

View file

@ -44,8 +44,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
static readonly int numberOfRadialSamples = 12;
public LevelWizard13PointRadial(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState)
: base(printerConnection, runningState, 500, 370, (numberOfRadialSamples + 1) * 3, numberOfRadialSamples)
public LevelWizard13PointRadial(PrinterConfig printer, LevelWizardBase.RuningState runningState)
: base(printer, runningState, 500, 370, (numberOfRadialSamples + 1) * 3, numberOfRadialSamples)
{
}
@ -65,8 +65,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override Vector2 GetPrintLevelPositionToSample(int index, double radius)
{
PrintLevelingData levelingData = printerConnection.PrinterSettings.Helpers.GetPrintLevelingData();
return GetLevelingFunctions(printerConnection.PrinterSettings, numberOfRadialSamples, levelingData, printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.print_center))
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
return GetLevelingFunctions(printer.Settings, numberOfRadialSamples, levelingData, printer.Settings.GetValue<Vector2>(SettingsKey.print_center))
.GetPrintLevelPositionToSample(index, radius);
}

View file

@ -41,10 +41,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
private LevelingStrings levelingStrings;
public LevelWizard3Point(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState)
: base(printerConnection, 500, 370, 9)
public LevelWizard3Point(PrinterConfig printer, LevelWizardBase.RuningState runningState)
: base(printer, 500, 370, 9)
{
levelingStrings = new LevelingStrings(printerConnection.PrinterSettings);
levelingStrings = new LevelingStrings(printer.Settings);
string printLevelWizardTitle = "MatterControl".Localize();
string printLevelWizardTitleFull = "Print Leveling Wizard".Localize();
Title = string.Format("{0} - {1}", printLevelWizardTitle, printLevelWizardTitleFull);
@ -59,22 +59,22 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
if (runningState == LevelWizardBase.RuningState.InitialStartupCalibration)
{
string requiredPageInstructions = "{0}\n\n{1}".FormatWith(levelingStrings.requiredPageInstructions1, levelingStrings.requiredPageInstructions2);
printLevelWizard.AddPage(new FirstPageInstructions(levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
}
printLevelWizard.AddPage(new FirstPageInstructions(levelingStrings.OverviewText, levelingStrings.WelcomeText(3, 3)));
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.OverviewText, levelingStrings.WelcomeText(3, 3)));
// To make sure the bed is at the correct temp, put in a filament selection page.
bool hasHeatedBed = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed);
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
if (hasHeatedBed)
{
string filamentSelectionPage = "{0}\n\n{1}".FormatWith(levelingStrings.materialPageInstructions1, levelingStrings.materialPageInstructions2);
printLevelWizard.AddPage(new SelectMaterialPage(printerConnection, levelingStrings.materialStepText, filamentSelectionPage));
printLevelWizard.AddPage(new SelectMaterialPage(printer, levelingStrings.materialStepText, filamentSelectionPage));
}
printLevelWizard.AddPage(new HomePrinterPage(printerConnection, printLevelWizard, levelingStrings.homingPageStepText, levelingStrings.homingPageInstructions));
printLevelWizard.AddPage(new HomePrinterPage(printer, printLevelWizard, levelingStrings.homingPageStepText, levelingStrings.homingPageInstructions));
if (hasHeatedBed)
{
printLevelWizard.AddPage(new WaitForTempPage(printerConnection, printLevelWizard, levelingStrings));
printLevelWizard.AddPage(new WaitForTempPage(printer, printLevelWizard, levelingStrings));
}
string positionLabel = "Position".Localize();
@ -83,26 +83,26 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
string medPrecisionLabel = "Medium Precision".Localize();
string highPrecisionLabel = "High Precision".Localize();
double startProbeHeight = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.print_leveling_probe_start);
double startProbeHeight = printer.Settings.GetValue<double>(SettingsKey.print_leveling_probe_start);
for (int i = 0; i < 3; i++)
{
Vector2 probePosition = LevelWizardBase.GetPrintLevelPositionToSample(printerConnection.PrinterSettings, i);
Vector2 probePosition = LevelWizardBase.GetPrintLevelPositionToSample(printer.Settings, i);
if (printerConnection.PrinterSettings.Helpers.UseZProbe())
if (printer.Settings.Helpers.UseZProbe())
{
var stepString = string.Format("{0} {1} {2} {3}:", levelingStrings.stepTextBeg, i + 1, levelingStrings.stepTextEnd, 3);
printLevelWizard.AddPage(new AutoProbeFeedback(printerConnection, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", stepString, positionLabel, i + 1, autoCalibrateLabel), probePositions, i));
printLevelWizard.AddPage(new AutoProbeFeedback(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", stepString, positionLabel, i + 1, autoCalibrateLabel), probePositions, i));
}
else
{
printLevelWizard.AddPage(new GetCoarseBedHeight(printerConnection, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, lowPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetFineBedHeight(printerConnection, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, medPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetUltraFineBedHeight(printerConnection, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, highPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetCoarseBedHeight(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, lowPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, medPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetUltraFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, highPrecisionLabel), probePositions, i));
}
}
printLevelWizard.AddPage(new LastPagelInstructions(printerConnection, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions));
printLevelWizard.AddPage(new LastPagelInstructions(printer, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions));
}
public static string ApplyLeveling(PrinterSettings printerSettings, string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode)

View file

@ -43,8 +43,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
private static readonly int numberOfRadialSamples = 6;
public LevelWizard7PointRadial(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState)
: base(printerConnection, runningState, 500, 370, 21, numberOfRadialSamples)
public LevelWizard7PointRadial(PrinterConfig printer, LevelWizardBase.RuningState runningState)
: base(printer, runningState, 500, 370, 21, numberOfRadialSamples)
{
}
@ -83,8 +83,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override Vector2 GetPrintLevelPositionToSample(int index, double radius)
{
PrintLevelingData levelingData = printerConnection.PrinterSettings.Helpers.GetPrintLevelingData();
return GetLevelingFunctions(printerConnection.PrinterSettings, numberOfRadialSamples, levelingData, printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.print_center))
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
return GetLevelingFunctions(printer.Settings, numberOfRadialSamples, levelingData, printer.Settings.GetValue<Vector2>(SettingsKey.print_center))
.GetPrintLevelPositionToSample(index, radius);
}
}
@ -94,11 +94,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private static RadialLevlingFunctions currentLevelingFunctions = null;
private LevelingStrings levelingStrings;
public LevelWizardRadialBase(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState, int width, int height, int totalSteps, int numberOfRadialSamples)
: base(printerConnection, width, height, totalSteps)
public LevelWizardRadialBase(PrinterConfig printer, LevelWizardBase.RuningState runningState, int width, int height, int totalSteps, int numberOfRadialSamples)
: base(printer, width, height, totalSteps)
{
levelingStrings = new LevelingStrings(printerConnection.PrinterSettings);
this.printerConnection = printerConnection;
levelingStrings = new LevelingStrings(printer.Settings);
string printLevelWizardTitle = "MatterControl";
string printLevelWizardTitleFull = "Print Leveling Wizard".Localize();
Title = string.Format("{0} - {1}", printLevelWizardTitle, printLevelWizardTitleFull);
@ -114,22 +113,22 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
if (runningState == LevelWizardBase.RuningState.InitialStartupCalibration)
{
string requiredPageInstructions = "{0}\n\n{1}".FormatWith(levelingStrings.requiredPageInstructions1, levelingStrings.requiredPageInstructions2);
printLevelWizard.AddPage(new FirstPageInstructions(levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
}
printLevelWizard.AddPage(new FirstPageInstructions(levelingStrings.OverviewText, levelingStrings.WelcomeText(numberOfRadialSamples + 1, 5)));
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.OverviewText, levelingStrings.WelcomeText(numberOfRadialSamples + 1, 5)));
// To make sure the bed is at the correct temp, put in a filament selection page.
bool hasHeatedBed = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed);
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
if (hasHeatedBed)
{
string filamentSelectionPage = "{0}\n\n{1}".FormatWith(levelingStrings.materialPageInstructions1, levelingStrings.materialPageInstructions2);
printLevelWizard.AddPage(new SelectMaterialPage(printerConnection, levelingStrings.materialStepText, filamentSelectionPage));
printLevelWizard.AddPage(new SelectMaterialPage(printer, levelingStrings.materialStepText, filamentSelectionPage));
}
printLevelWizard.AddPage(new HomePrinterPage(printerConnection, printLevelWizard, levelingStrings.homingPageStepText, levelingStrings.homingPageInstructions));
printLevelWizard.AddPage(new HomePrinterPage(printer, printLevelWizard, levelingStrings.homingPageStepText, levelingStrings.homingPageInstructions));
if (hasHeatedBed)
{
printLevelWizard.AddPage(new WaitForTempPage(printerConnection, printLevelWizard, levelingStrings));
printLevelWizard.AddPage(new WaitForTempPage(printer, printLevelWizard, levelingStrings));
}
string positionLabel = "Position".Localize();
@ -138,27 +137,27 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
string medPrecisionLabel = "Medium Precision".Localize();
string highPrecisionLabel = "High Precision".Localize();
double bedRadius = Math.Min(printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.bed_size).x, printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.bed_size).y) / 2;
double bedRadius = Math.Min(printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).x, printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).y) / 2;
double startProbeHeight = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.print_leveling_probe_start);
double startProbeHeight = printer.Settings.GetValue<double>(SettingsKey.print_leveling_probe_start);
for (int i = 0; i < numberOfRadialSamples + 1; i++)
{
Vector2 probePosition = GetPrintLevelPositionToSample(i, bedRadius);
if (printerConnection.PrinterSettings.Helpers.UseZProbe())
if (printer.Settings.Helpers.UseZProbe())
{
var stepString = string.Format("{0} {1} {2} {3}:", levelingStrings.stepTextBeg, i + 1, levelingStrings.stepTextEnd, numberOfRadialSamples + 1);
printLevelWizard.AddPage(new AutoProbeFeedback(printerConnection, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", stepString, positionLabel, i + 1, autoCalibrateLabel), probePositions, i));
printLevelWizard.AddPage(new AutoProbeFeedback(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", stepString, positionLabel, i + 1, autoCalibrateLabel), probePositions, i));
}
else
{
printLevelWizard.AddPage(new GetCoarseBedHeight(printerConnection, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, lowPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetFineBedHeight(printerConnection, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, medPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetUltraFineBedHeight(printerConnection, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, highPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetCoarseBedHeight(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, lowPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, medPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetUltraFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, highPrecisionLabel), probePositions, i));
}
}
printLevelWizard.AddPage(new LastPagelInstructions(printerConnection, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions));
printLevelWizard.AddPage(new LastPagelInstructions(printer, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions));
}
public static RadialLevlingFunctions GetLevelingFunctions(PrinterSettings printerSettings, int numberOfRadialSamples, PrintLevelingData levelingData, Vector2 bedCenter)

View file

@ -53,13 +53,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
protected WizardControl printLevelWizard;
protected int totalSteps { get; private set; }
protected PrinterConnection printerConnection;
protected PrinterConfig printer;
public LevelWizardBase(PrinterConnection printerConnection, int width, int height, int totalSteps)
public LevelWizardBase(PrinterConfig printer, int width, int height, int totalSteps)
: base(width, height)
{
levelingStrings = new LevelingStrings(printerConnection.PrinterSettings);
this.printerConnection = printerConnection;
levelingStrings = new LevelingStrings(printer.Settings);
this.printer = printer;
AlwaysOnTopOfMain = true;
this.totalSteps = totalSteps;
}
@ -155,36 +155,36 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private static SystemWindow printLevelWizardWindow;
public static void ShowPrintLevelWizard(PrinterConnection printerConnection)
public static void ShowPrintLevelWizard(PrinterConfig printer)
{
LevelWizardBase.RuningState runningState = LevelWizardBase.RuningState.UserRequestedCalibration;
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.print_leveling_required_to_print))
if (printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print))
{
// run in the first run state
runningState = LevelWizardBase.RuningState.InitialStartupCalibration;
}
ShowPrintLevelWizard(printerConnection, runningState);
ShowPrintLevelWizard(printer, runningState);
}
public static void ShowPrintLevelWizard(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState)
public static void ShowPrintLevelWizard(PrinterConfig printer, LevelWizardBase.RuningState runningState)
{
if (printLevelWizardWindow == null)
{
printLevelWizardWindow = LevelWizardBase.CreateAndShowWizard(printerConnection, runningState);
printLevelWizardWindow = LevelWizardBase.CreateAndShowWizard(printer, runningState);
printLevelWizardWindow.Closed += (sender, e) =>
{
printLevelWizardWindow = null;
// make sure we raise the probe on close
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_z_probe)
&& printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.use_z_probe)
&& printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_z_servo))
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe)
&& printer.Settings.GetValue<bool>(SettingsKey.has_z_servo))
{
// make sure the servo is retracted
var servoRetract = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.z_servo_retracted_angle);
printerConnection.SendLineToPrinterNow($"M280 P0 S{servoRetract}");
var servoRetract = printer.Settings.GetValue<double>(SettingsKey.z_servo_retracted_angle);
printer.Connection.SendLineToPrinterNow($"M280 P0 S{servoRetract}");
}
};
}
@ -194,14 +194,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
}
}
private static LevelWizardBase CreateAndShowWizard(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState)
private static LevelWizardBase CreateAndShowWizard(PrinterConfig printer, LevelWizardBase.RuningState runningState)
{
// turn off print leveling
printerConnection.PrinterSettings.Helpers.DoPrintLeveling(false);
printer.Settings.Helpers.DoPrintLeveling(false);
// clear any data that we are going to be acquiring (sampled positions, after z home offset)
PrintLevelingData levelingData = printerConnection.PrinterSettings.Helpers.GetPrintLevelingData();
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
levelingData.SampledPositions.Clear();
printerConnection.PrinterSettings.SetValue(SettingsKey.baby_step_z_offset, "0");
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, "0");
ApplicationController.Instance.ReloadAdvancedControlsPanel();
@ -209,19 +209,19 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
switch (levelingData.CurrentPrinterLevelingSystem)
{
case PrintLevelingData.LevelingSystem.Probe3Points:
printLevelWizardWindow = new LevelWizard3Point(printerConnection, runningState);
printLevelWizardWindow = new LevelWizard3Point(printer, runningState);
break;
case PrintLevelingData.LevelingSystem.Probe7PointRadial:
printLevelWizardWindow = new LevelWizard7PointRadial(printerConnection, runningState);
printLevelWizardWindow = new LevelWizard7PointRadial(printer, runningState);
break;
case PrintLevelingData.LevelingSystem.Probe13PointRadial:
printLevelWizardWindow = new LevelWizard13PointRadial(printerConnection, runningState);
printLevelWizardWindow = new LevelWizard13PointRadial(printer, runningState);
break;
case PrintLevelingData.LevelingSystem.Probe3x3Mesh:
printLevelWizardWindow = new LevelWizard3x3Mesh(printerConnection, runningState);
printLevelWizardWindow = new LevelWizard3x3Mesh(printer, runningState);
break;
default:

View file

@ -43,8 +43,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class LevelWizard3x3Mesh : LevelWizardMeshBase
{
public LevelWizard3x3Mesh(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState)
: base(printerConnection, runningState, 500, 370, 21, 3, 3)
public LevelWizard3x3Mesh(PrinterConfig printer, LevelWizardBase.RuningState runningState)
: base(printer, runningState, 500, 370, 21, 3, 3)
{
}
@ -83,16 +83,16 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override Vector2 GetPrintLevelPositionToSample(int index)
{
var manualPositions = GetManualPositions(printerConnection.PrinterSettings.GetValue(SettingsKey.leveling_manual_positions), 9);
var manualPositions = GetManualPositions(printer.Settings.GetValue(SettingsKey.leveling_manual_positions), 9);
if (manualPositions != null)
{
return manualPositions[index];
}
Vector2 bedSize = printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.bed_size);
Vector2 printCenter = printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.print_center);
Vector2 bedSize = printer.Settings.GetValue<Vector2>(SettingsKey.bed_size);
Vector2 printCenter = printer.Settings.GetValue<Vector2>(SettingsKey.print_center);
if (printerConnection.PrinterSettings.GetValue<BedShape>(SettingsKey.bed_shape) == BedShape.Circular)
if (printer.Settings.GetValue<BedShape>(SettingsKey.bed_shape) == BedShape.Circular)
{
// reduce the bed size by the ratio of the radius (square root of 2) so that the sample positions will fit on a ciclular bed
bedSize *= 1.0 / Math.Sqrt(2);
@ -151,10 +151,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private static MeshLevlingFunctions currentLevelingFunctions = null;
protected LevelingStrings levelingStrings;
public LevelWizardMeshBase(PrinterConnection printerConnection, LevelWizardBase.RuningState runningState, int width, int height, int totalSteps, int gridWidth, int gridHeight)
: base(printerConnection, width, height, totalSteps)
public LevelWizardMeshBase(PrinterConfig printer, LevelWizardBase.RuningState runningState, int width, int height, int totalSteps, int gridWidth, int gridHeight)
: base(printer, width, height, totalSteps)
{
levelingStrings = new LevelingStrings(printerConnection.PrinterSettings);
levelingStrings = new LevelingStrings(printer.Settings);
string printLevelWizardTitle = "MatterControl";
string printLevelWizardTitleFull = "Print Leveling Wizard".Localize();
Title = string.Format("{0} - {1}", printLevelWizardTitle, printLevelWizardTitleFull);
@ -171,24 +171,24 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
if (runningState == LevelWizardBase.RuningState.InitialStartupCalibration)
{
string requiredPageInstructions = "{0}\n\n{1}".FormatWith(levelingStrings.requiredPageInstructions1, levelingStrings.requiredPageInstructions2);
printLevelWizard.AddPage(new FirstPageInstructions(levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
}
printLevelWizard.AddPage(new FirstPageInstructions(levelingStrings.OverviewText, levelingStrings.WelcomeText(probeCount, 5)));
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.OverviewText, levelingStrings.WelcomeText(probeCount, 5)));
var printerSettings = printerConnection.PrinterSettings;
var printerSettings = printer.Settings;
// To make sure the bed is at the correct temp, put in a filament selection page.
bool hasHeatedBed = printerSettings.GetValue<bool>(SettingsKey.has_heated_bed);
if (hasHeatedBed)
{
string filamentSelectionPage = "{0}\n\n{1}".FormatWith(levelingStrings.materialPageInstructions1, levelingStrings.materialPageInstructions2);
printLevelWizard.AddPage(new SelectMaterialPage(printerConnection, levelingStrings.materialStepText, filamentSelectionPage));
printLevelWizard.AddPage(new SelectMaterialPage(printer, levelingStrings.materialStepText, filamentSelectionPage));
}
printLevelWizard.AddPage(new HomePrinterPage(printerConnection, printLevelWizard, levelingStrings.homingPageStepText, levelingStrings.homingPageInstructions));
printLevelWizard.AddPage(new HomePrinterPage(printer, printLevelWizard, levelingStrings.homingPageStepText, levelingStrings.homingPageInstructions));
if (hasHeatedBed)
{
printLevelWizard.AddPage(new WaitForTempPage(printerConnection, printLevelWizard, levelingStrings));
printLevelWizard.AddPage(new WaitForTempPage(printer, printLevelWizard, levelingStrings));
}
string positionLabel = "Position".Localize();
@ -207,17 +207,17 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
if (printerSettings.Helpers.UseZProbe())
{
var stepString = string.Format("{0} {1} {2} {3}:", levelingStrings.stepTextBeg, i + 1, levelingStrings.stepTextEnd, probeCount);
printLevelWizard.AddPage(new AutoProbeFeedback(printerConnection, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", stepString, positionLabel, i + 1, autoCalibrateLabel), probePositions, i));
printLevelWizard.AddPage(new AutoProbeFeedback(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", stepString, positionLabel, i + 1, autoCalibrateLabel), probePositions, i));
}
else
{
printLevelWizard.AddPage(new GetCoarseBedHeight(printerConnection, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, lowPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetFineBedHeight(printerConnection, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, medPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetUltraFineBedHeight(printerConnection, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, highPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetCoarseBedHeight(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, lowPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, medPrecisionLabel), probePositions, i));
printLevelWizard.AddPage(new GetUltraFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, highPrecisionLabel), probePositions, i));
}
}
printLevelWizard.AddPage(new LastPagelInstructions(printerConnection, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions));
printLevelWizard.AddPage(new LastPagelInstructions(printer, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions));
}
public static MeshLevlingFunctions GetLevelingFunctions(PrinterSettings printerSettings, int gridWidth, int gridHeight, PrintLevelingData levelingData)

View file

@ -42,16 +42,16 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class FirstPageInstructions : InstructionsPage
{
public FirstPageInstructions(string pageDescription, string instructionsText)
: base(pageDescription, instructionsText)
public FirstPageInstructions(PrinterConfig printer, string pageDescription, string instructionsText)
: base(printer, pageDescription, instructionsText)
{
}
}
public class SelectMaterialPage : InstructionsPage
{
public SelectMaterialPage(PrinterConnection printerConnection, string pageDescription, string instructionsText)
: base(pageDescription, instructionsText)
public SelectMaterialPage(PrinterConfig printer, string pageDescription, string instructionsText)
: base(printer, pageDescription, instructionsText)
{
int extruderIndex = 0;
var materialSelector = new PresetSelectorWidget(string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, extruderIndex);
@ -67,13 +67,11 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private ProgressBar progressBar;
private TextWidget progressBarText;
private TextWidget doneText;
double startingTemp;
PrinterConnection printerConnection;
private double startingTemp;
public WaitForTempPage(PrinterConnection printerConnection, WizardControl container, LevelingStrings levelingStrings)
: base(levelingStrings.WaitingForTempPageStepText, levelingStrings.WaitingForTempPageInstructions)
public WaitForTempPage(PrinterConfig printer, WizardControl container, LevelingStrings levelingStrings)
: base(printer, levelingStrings.WaitingForTempPageStepText, levelingStrings.WaitingForTempPageInstructions)
{
this.printerConnection = printerConnection;
this.container = container;
var holder = new FlowLayoutWidget()
{
@ -107,20 +105,20 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override void PageIsBecomingActive()
{
startingTemp = printerConnection.ActualBedTemperature;
startingTemp = printer.Connection.ActualBedTemperature;
UiThread.RunOnIdle(ShowTempChangeProgress);
// start heating the bed and show our progress
printerConnection.TargetBedTemperature = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.bed_temperature);
printer.Connection.TargetBedTemperature = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
// hook our parent so we can turn off the bed when we are done with leveling
Parent.Closed += (s, e) =>
{
// Make sure when the wizard closes we turn off the bed heating
printerConnection.TargetBedTemperature = 0;
printer.Connection.TargetBedTemperature = 0;
};
if (printerConnection.PrinterSettings.Helpers.UseZProbe())
if (printer.Settings.Helpers.UseZProbe())
{
container.backButton.Enabled = false;
container.nextButton.Enabled = false;
@ -140,8 +138,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private void ShowTempChangeProgress()
{
progressBar.Visible = true;
double targetTemp = printerConnection.TargetBedTemperature;
double actualTemp = printerConnection.ActualBedTemperature;
double targetTemp = printer.Connection.TargetBedTemperature;
double actualTemp = printer.Connection.ActualBedTemperature;
double totalDelta = targetTemp - startingTemp;
double currentDelta = actualTemp - startingTemp;
double ratioDone = totalDelta != 0 ? (currentDelta / totalDelta) : 1;
@ -160,7 +158,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
container.backButton.Enabled = true;
container.nextButton.Enabled = true;
if (printerConnection.PrinterSettings.Helpers.UseZProbe())
if (printer.Settings.Helpers.UseZProbe())
{
// advance to the next page
UiThread.RunOnIdle(() => container.nextButton.ClickButton(null));
@ -173,34 +171,32 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
protected WizardControl container;
private List<ProbePosition> probePositions;
PrinterConnection printerConnection;
public LastPagelInstructions(PrinterConnection printerConnection, WizardControl container, string pageDescription, string instructionsText, List<ProbePosition> probePositions)
: base(pageDescription, instructionsText)
public LastPagelInstructions(PrinterConfig printer, WizardControl container, string pageDescription, string instructionsText, List<ProbePosition> probePositions)
: base(printer, pageDescription, instructionsText)
{
this.printerConnection = printerConnection;
this.probePositions = probePositions;
this.container = container;
}
public override void PageIsBecomingActive()
{
PrintLevelingData levelingData = printerConnection.PrinterSettings.Helpers.GetPrintLevelingData();
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
levelingData.SampledPositions.Clear();
Vector3 zProbeOffset = new Vector3(0, 0, printerConnection.PrinterSettings.GetValue<double>(SettingsKey.z_probe_z_offset));
Vector3 zProbeOffset = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.z_probe_z_offset));
for (int i = 0; i < probePositions.Count; i++)
{
levelingData.SampledPositions.Add(probePositions[i].position - zProbeOffset);
}
// Invoke setter forcing persistence of leveling data
printerConnection.PrinterSettings.Helpers.SetPrintLevelingData(levelingData, true);
printerConnection.PrinterSettings.Helpers.DoPrintLeveling ( true);
printer.Settings.Helpers.SetPrintLevelingData(levelingData, true);
printer.Settings.Helpers.DoPrintLeveling ( true);
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.z_homes_to_max))
if (printer.Settings.GetValue<bool>(SettingsKey.z_homes_to_max))
{
printerConnection.HomeAxis(PrinterConnection.Axis.XYZ);
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
}
container.backButton.Enabled = false;
@ -214,12 +210,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
protected Vector3 probeStartPosition;
private ProbePosition probePosition;
protected WizardControl container;
PrinterConnection printerConnection;
public GettingThirdPointFor2PointCalibration(PrinterConnection printerConnection, WizardControl container, string pageDescription, Vector3 probeStartPosition, string instructionsText, ProbePosition probePosition)
: base(pageDescription, instructionsText)
public GettingThirdPointFor2PointCalibration(PrinterConfig printer, WizardControl container, string pageDescription, Vector3 probeStartPosition, string instructionsText, ProbePosition probePosition)
: base(printer, pageDescription, instructionsText)
{
this.printerConnection = printerConnection;
this.probeStartPosition = probeStartPosition;
this.probePosition = probePosition;
this.container = container;
@ -237,14 +231,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override void PageIsBecomingActive()
{
// first make sure there is no leftover FinishedProbe event
printerConnection.ReadLine.UnregisterEvent(FinishedProbe, ref unregisterEvents);
printer.Connection.ReadLine.UnregisterEvent(FinishedProbe, ref unregisterEvents);
var feedRates = printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds();
var feedRates = printer.Settings.Helpers.ManualMovementSpeeds();
printerConnection.MoveAbsolute(PrinterConnection.Axis.Z, probeStartPosition.z, feedRates.z);
printerConnection.MoveAbsolute(probeStartPosition, feedRates.x);
printerConnection.SendLineToPrinterNow("G30");
printerConnection.ReadLine.RegisterEvent(FinishedProbe, ref unregisterEvents);
printer.Connection.MoveAbsolute(PrinterConnection.Axis.Z, probeStartPosition.z, feedRates.z);
printer.Connection.MoveAbsolute(probeStartPosition, feedRates.x);
printer.Connection.SendLineToPrinterNow("G30");
printer.Connection.ReadLine.RegisterEvent(FinishedProbe, ref unregisterEvents);
base.PageIsBecomingActive();
@ -259,12 +253,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
if (currentEvent.Data.Contains("endstops hit"))
{
printerConnection.ReadLine.UnregisterEvent(FinishedProbe, ref unregisterEvents);
printer.Connection.ReadLine.UnregisterEvent(FinishedProbe, ref unregisterEvents);
int zStringPos = currentEvent.Data.LastIndexOf("Z:");
string zProbeHeight = currentEvent.Data.Substring(zStringPos + 2);
probePosition.position = new Vector3(probeStartPosition.x, probeStartPosition.y, double.Parse(zProbeHeight));
printerConnection.MoveAbsolute(probeStartPosition, printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds().z);
printerConnection.ReadPosition();
printer.Connection.MoveAbsolute(probeStartPosition, printer.Settings.Helpers.ManualMovementSpeeds().z);
printer.Connection.ReadPosition();
UiThread.RunOnIdle(() => container.nextButton.ClickButton(null));
}
@ -276,12 +270,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
protected WizardControl container;
private EventHandler unregisterEvents;
PrinterConnection printerConnection;
public HomePrinterPage(PrinterConnection printerConnection, WizardControl container, string pageDescription, string instructionsText)
: base(pageDescription, instructionsText)
public HomePrinterPage(PrinterConfig printer, WizardControl container, string pageDescription, string instructionsText)
: base(printer, pageDescription, instructionsText)
{
this.printerConnection = printerConnection;
this.container = container;
}
@ -296,13 +288,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// make sure we don't have anything left over
unregisterEvents?.Invoke(this, null);
printerConnection.PrintingStateChanged.RegisterEvent(CheckHomeFinished, ref unregisterEvents);
printer.Connection.PrintingStateChanged.RegisterEvent(CheckHomeFinished, ref unregisterEvents);
printerConnection.HomeAxis(PrinterConnection.Axis.XYZ);
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
if (printerConnection.PrinterSettings.Helpers.UseZProbe())
if (printer.Settings.Helpers.UseZProbe())
{
container.backButton.Enabled = true;
container.nextButton.Enabled = false;
}
@ -311,13 +302,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private void CheckHomeFinished(object sender, EventArgs e)
{
if(printerConnection.DetailedPrintingState != DetailedPrintingState.HomingAxis)
if(printer.Connection.DetailedPrintingState != DetailedPrintingState.HomingAxis)
{
unregisterEvents?.Invoke(this, null);
container.nextButton.Enabled = true;
container.backButton.Enabled = true;
if (printerConnection.PrinterSettings.Helpers.UseZProbe())
if (printer.Settings.Helpers.UseZProbe())
{
UiThread.RunOnIdle(() => container.nextButton.ClickButton(null));
}
@ -344,16 +335,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
protected JogControls.MoveButton zPlusControl;
protected JogControls.MoveButton zMinusControl;
protected WizardControl container;
protected PrinterConnection printerConnection;
public FindBedHeight(PrinterConnection printerConnection, WizardControl container, string pageDescription, string setZHeightCoarseInstruction1, string setZHeightCoarseInstruction2, double moveDistance, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(pageDescription, setZHeightCoarseInstruction1)
public FindBedHeight(PrinterConfig printer, WizardControl container, string pageDescription, string setZHeightCoarseInstruction1, string setZHeightCoarseInstruction2, double moveDistance, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printer, pageDescription, setZHeightCoarseInstruction1)
{
this.printerConnection = printerConnection;
this.container = container;
this.probePositions = probePositions;
this.moveAmount = moveDistance;
this.lastReportedPosition = printerConnection.LastReportedPosition;
this.lastReportedPosition = printer.Connection.LastReportedPosition;
this.probePositionsBeingEditedIndex = probePositionsBeingEditedIndex;
GuiWidget spacer = new GuiWidget(15, 15);
@ -375,7 +364,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
Action<TextWidget> updateUntilClose = null;
updateUntilClose = (tw) =>
{
Vector3 destinationPosition = printerConnection.CurrentDestination;
Vector3 destinationPosition = printer.Connection.CurrentDestination;
zPosition.Text = "Z: {0:0.00}".FormatWith(destinationPosition.z);
UiThread.RunOnIdle(() => updateUntilClose(zPosition), .3);
};
@ -391,7 +380,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override void PageIsBecomingActive()
{
// always make sure we don't have print leveling turned on
printerConnection.PrinterSettings.Helpers.DoPrintLeveling(false);
printer.Settings.Helpers.DoPrintLeveling(false);
base.PageIsBecomingActive();
this.Parents<SystemWindow>().First().KeyDown += TopWindowKeyDown;
@ -400,13 +389,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override void PageIsBecomingInactive()
{
this.Parents<SystemWindow>().First().KeyDown -= TopWindowKeyDown;
probePositions[probePositionsBeingEditedIndex].position = printerConnection.LastReportedPosition;
probePositions[probePositionsBeingEditedIndex].position = printer.Connection.LastReportedPosition;
base.PageIsBecomingInactive();
}
private FlowLayoutWidget CreateZButtons()
{
FlowLayoutWidget zButtons = JogControls.CreateZButtons(printerConnection, RGBA_Bytes.White, 4, out zPlusControl, out zMinusControl, true);
FlowLayoutWidget zButtons = JogControls.CreateZButtons(printer, RGBA_Bytes.White, 4, out zPlusControl, out zMinusControl, true);
// set these to 0 so the button does not do any movements by default (we will handle the movement on our click callback)
zPlusControl.MoveAmount = 0;
zMinusControl.MoveAmount = 0;
@ -452,14 +441,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private void zMinusControl_Click(object sender, EventArgs mouseEvent)
{
printerConnection.MoveRelative(PrinterConnection.Axis.Z, -moveAmount, printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds().z);
printerConnection.ReadPosition();
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, -moveAmount, printer.Settings.Helpers.ManualMovementSpeeds().z);
printer.Connection.ReadPosition();
}
private void zPlusControl_Click(object sender, EventArgs mouseEvent)
{
printerConnection.MoveRelative(PrinterConnection.Axis.Z, moveAmount, printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds().z);
printerConnection.ReadPosition();
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, moveAmount, printer.Settings.Helpers.ManualMovementSpeeds().z);
printer.Connection.ReadPosition();
}
}
@ -472,18 +461,16 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private EventHandler unregisterEvents;
protected Vector3 probeStartPosition;
protected WizardControl container;
PrinterConnection printerConnection;
public AutoProbeFeedback(PrinterConnection printerConnection, WizardControl container, Vector3 probeStartPosition, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(pageDescription, pageDescription)
public AutoProbeFeedback(PrinterConfig printer, WizardControl container, Vector3 probeStartPosition, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printer, pageDescription, pageDescription)
{
this.printerConnection = printerConnection;
this.container = container;
this.probeStartPosition = probeStartPosition;
this.probePositions = probePositions;
this.lastReportedPosition = printerConnection.LastReportedPosition;
this.lastReportedPosition = printer.Connection.LastReportedPosition;
this.probePositionsBeingEditedIndex = probePositionsBeingEditedIndex;
GuiWidget spacer = new GuiWidget(15, 15);
@ -518,7 +505,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
samples.Add(sampleRead);
int numberOfSamples = printerConnection.PrinterSettings.GetValue<int>(SettingsKey.z_probe_samples);
int numberOfSamples = printer.Settings.GetValue<int>(SettingsKey.z_probe_samples);
if (samples.Count == numberOfSamples)
{
samples.Sort();
@ -547,52 +534,52 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public override void PageIsBecomingActive()
{
// always make sure we don't have print leveling turned on
printerConnection.PrinterSettings.Helpers.DoPrintLeveling(false);
printer.Settings.Helpers.DoPrintLeveling(false);
base.PageIsBecomingActive();
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_z_probe)
&& printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.use_z_probe)
&& printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_z_servo))
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe)
&& printer.Settings.GetValue<bool>(SettingsKey.has_z_servo))
{
// make sure the servo is deployed
var servoDeploy = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.z_servo_depolyed_angle);
printerConnection.SendLineToPrinterNow($"M280 P0 S{servoDeploy}");
var servoDeploy = printer.Settings.GetValue<double>(SettingsKey.z_servo_depolyed_angle);
printer.Connection.SendLineToPrinterNow($"M280 P0 S{servoDeploy}");
}
var feedRates = printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds();
var feedRates = printer.Settings.Helpers.ManualMovementSpeeds();
var adjustedProbePosition = probeStartPosition;
// subtract out the probe offset
var probeOffset = printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.z_probe_xy_offset);
var probeOffset = printer.Settings.GetValue<Vector2>(SettingsKey.z_probe_xy_offset);
adjustedProbePosition -= new Vector3(probeOffset);
printerConnection.MoveAbsolute(PrinterConnection.Axis.Z, probeStartPosition.z, feedRates.z);
printerConnection.MoveAbsolute(adjustedProbePosition, feedRates.x);
printer.Connection.MoveAbsolute(PrinterConnection.Axis.Z, probeStartPosition.z, feedRates.z);
printer.Connection.MoveAbsolute(adjustedProbePosition, feedRates.x);
int numberOfSamples = printerConnection.PrinterSettings.GetValue<int>(SettingsKey.z_probe_samples);
int numberOfSamples = printer.Settings.GetValue<int>(SettingsKey.z_probe_samples);
for (int i = 0; i < numberOfSamples; i++)
{
// probe the current position
printerConnection.SendLineToPrinterNow("G30");
printer.Connection.SendLineToPrinterNow("G30");
// raise the probe after each sample
printerConnection.MoveAbsolute(adjustedProbePosition, feedRates.x);
printer.Connection.MoveAbsolute(adjustedProbePosition, feedRates.x);
}
container.backButton.Enabled = false;
container.nextButton.Enabled = false;
if (printerConnection.PrinterIsConnected
&& !(printerConnection.PrinterIsPrinting
|| printerConnection.PrinterIsPaused))
if (printer.Connection.PrinterIsConnected
&& !(printer.Connection.PrinterIsPrinting
|| printer.Connection.PrinterIsPaused))
{
printerConnection.ReadLine.RegisterEvent(GetZProbeHeight, ref unregisterEvents);
printer.Connection.ReadLine.RegisterEvent(GetZProbeHeight, ref unregisterEvents);
}
}
public override void PageIsBecomingInactive()
{
printerConnection.ReadLine.UnregisterEvent(GetZProbeHeight, ref unregisterEvents);
printer.Connection.ReadLine.UnregisterEvent(GetZProbeHeight, ref unregisterEvents);
base.PageIsBecomingInactive();
}
}
@ -610,8 +597,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
protected Vector3 probeStartPosition;
public GetCoarseBedHeight(PrinterConnection printerConnection, WizardControl container, Vector3 probeStartPosition, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printerConnection, container, pageDescription, setZHeightCoarseInstruction1, setZHeightCoarseInstruction2, 1, probePositions, probePositionsBeingEditedIndex)
public GetCoarseBedHeight(PrinterConfig printer, WizardControl container, Vector3 probeStartPosition, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printer, container, pageDescription, setZHeightCoarseInstruction1, setZHeightCoarseInstruction2, 1, probePositions, probePositionsBeingEditedIndex)
{
this.probeStartPosition = probeStartPosition;
}
@ -620,11 +607,11 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
base.PageIsBecomingActive();
var feedRates = printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds();
var feedRates = printer.Settings.Helpers.ManualMovementSpeeds();
printerConnection.MoveAbsolute(PrinterConnection.Axis.Z, probeStartPosition.z, feedRates.z);
printerConnection.MoveAbsolute(probeStartPosition, feedRates.x);
printerConnection.ReadPosition();
printer.Connection.MoveAbsolute(PrinterConnection.Axis.Z, probeStartPosition.z, feedRates.z);
printer.Connection.MoveAbsolute(probeStartPosition, feedRates.x);
printer.Connection.ReadPosition();
container.backButton.Enabled = false;
container.nextButton.Enabled = false;
@ -655,8 +642,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private static string setZHeightFineInstructionTextThree = "Finally click 'Next' to continue.".Localize();
private static string setZHeightFineInstruction2 = string.Format("\t• {0}\n\t• {1}\n\n{2}", setZHeightFineInstructionTextOne, setZHeightFineInstructionTextTwo, setZHeightFineInstructionTextThree);
public GetFineBedHeight(PrinterConnection printerConnection, WizardControl container, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printerConnection, container, pageDescription, setZHeightFineInstruction1, setZHeightFineInstruction2, .1, probePositions, probePositionsBeingEditedIndex)
public GetFineBedHeight(PrinterConfig printer, WizardControl container, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printer, container, pageDescription, setZHeightFineInstruction1, setZHeightFineInstruction2, .1, probePositions, probePositionsBeingEditedIndex)
{
}
}
@ -668,8 +655,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private static string setHeightFineInstructionTextTwo = "Finally click 'Next' to continue.".Localize();
private static string setZHeightFineInstruction2 = string.Format("\t• {0}\n\n\n{1}", setHeightFineInstructionTextOne, setHeightFineInstructionTextTwo);
public GetUltraFineBedHeight(PrinterConnection printerConnection, WizardControl container, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printerConnection, container, pageDescription, setZHeightFineInstruction1, setZHeightFineInstruction2, .02, probePositions, probePositionsBeingEditedIndex)
public GetUltraFineBedHeight(PrinterConfig printer, WizardControl container, string pageDescription, List<ProbePosition> probePositions, int probePositionsBeingEditedIndex)
: base(printer, container, pageDescription, setZHeightFineInstruction1, setZHeightFineInstruction2, .02, probePositions, probePositionsBeingEditedIndex)
{
}
@ -685,7 +672,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
if (haveDrawn)
{
printerConnection.MoveRelative(PrinterConnection.Axis.Z, 2, printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds().z);
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, 2, printer.Settings.Helpers.ManualMovementSpeeds().z);
}
base.PageIsBecomingInactive();
}

View file

@ -52,10 +52,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
public class BedStatusWidget : TemperatureStatusWidget
{
public BedStatusWidget(PrinterConnection printerConnection, bool smallScreen)
: base(printerConnection, smallScreen ? "Bed".Localize() : "Bed Temperature".Localize())
public BedStatusWidget(PrinterConfig printer, bool smallScreen)
: base(printer, smallScreen ? "Bed".Localize() : "Bed Temperature".Localize())
{
printerConnection.BedTemperatureRead.RegisterEvent((s, e) =>
printer.Connection.BedTemperatureRead.RegisterEvent((s, e) =>
{
UpdateTemperatures();
}, ref unregisterEvents);
@ -63,8 +63,8 @@ namespace MatterHackers.MatterControl.CustomWidgets
public override void UpdateTemperatures()
{
double targetValue = printerConnection.TargetBedTemperature;
double actualValue = Math.Max(0, printerConnection.ActualBedTemperature);
double targetValue = printer.Connection.TargetBedTemperature;
double actualValue = Math.Max(0, printer.Connection.ActualBedTemperature);
progressBar.RatioComplete = targetValue != 0 ? actualValue / targetValue : 1;
@ -77,12 +77,12 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
private int extruderIndex;
public ExtruderStatusWidget(PrinterConnection printerConnection, int extruderIndex)
: base(printerConnection, $"{"Extruder".Localize()} {extruderIndex + 1}")
public ExtruderStatusWidget(PrinterConfig printer, int extruderIndex)
: base(printer, $"{"Extruder".Localize()} {extruderIndex + 1}")
{
this.extruderIndex = extruderIndex;
printerConnection.HotendTemperatureRead.RegisterEvent((s, e) =>
printer.Connection.HotendTemperatureRead.RegisterEvent((s, e) =>
{
UpdateTemperatures();
}, ref unregisterEvents);
@ -90,8 +90,8 @@ namespace MatterHackers.MatterControl.CustomWidgets
public override void UpdateTemperatures()
{
double targetValue = printerConnection.GetTargetHotendTemperature(extruderIndex);
double actualValue = Math.Max(0, printerConnection.GetActualHotendTemperature(extruderIndex));
double targetValue = printer.Connection.GetTargetHotendTemperature(extruderIndex);
double actualValue = Math.Max(0, printer.Connection.GetActualHotendTemperature(extruderIndex));
progressBar.RatioComplete = targetValue != 0 ? actualValue / targetValue : 1;
@ -107,11 +107,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
protected TextWidget targetTemp;
protected EventHandler unregisterEvents;
private int fontSize = 14;
protected PrinterConnection printerConnection;
protected PrinterConfig printer;
public TemperatureStatusWidget(PrinterConnection printerConnection, string dispalyName)
public TemperatureStatusWidget(PrinterConfig printer, string dispalyName)
{
this.printerConnection = printerConnection;
this.printer = printer;
var extruderName = new TextWidget(dispalyName, pointSize: fontSize, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
AutoExpandBoundsToText = true,
@ -186,15 +186,16 @@ namespace MatterHackers.MatterControl.CustomWidgets
private AverageMillisecondTimer millisecondTimer = new AverageMillisecondTimer();
private Stopwatch totalDrawTime = new Stopwatch();
GuiWidget bodyContainer;
private GuiWidget bodyContainer;
private BasicBody basicBody;
PrinterConnection printerConnection;
public PrintingWindow(PrinterConnection printerConnection)
private PrinterConfig printer;
public PrintingWindow(PrinterConfig printer)
: base(1280, 750)
{
this.printerConnection = printerConnection;
this.printer = printer;
}
public override void OnLoad(EventArgs args)
@ -218,7 +219,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
topToBottom.AddChild(CreateDropShadow());
basicBody = new BasicBody(printerConnection);
basicBody = new BasicBody(printer);
bodyContainer = new GuiWidget()
{
VAnchor = VAnchor.Stretch,
@ -254,11 +255,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
UiThread.RunOnIdle(() =>
{
printerConnection.RequestPause();
printer.Connection.RequestPause();
});
};
pauseButton.Enabled = printerConnection.PrinterIsPrinting
&& !printerConnection.PrinterIsPaused;
pauseButton.Enabled = printer.Connection.PrinterIsPrinting
&& !printer.Connection.PrinterIsPaused;
actionBar.AddChild(pauseButton);
@ -269,9 +270,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
UiThread.RunOnIdle(() =>
{
if (printerConnection.PrinterIsPaused)
if (printer.Connection.PrinterIsPaused)
{
printerConnection.Resume();
printer.Connection.Resume();
}
});
};
@ -289,7 +290,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.Close();
}
};
cancelButton.Enabled = printerConnection.PrinterIsPrinting || printerConnection.PrinterIsPaused;
cancelButton.Enabled = printer.Connection.PrinterIsPrinting || printer.Connection.PrinterIsPaused;
actionBar.AddChild(cancelButton);
actionBar.AddChild(CreateVerticalLine());
@ -297,10 +298,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
// put in the reset button
var resetButton = CreateButton("Reset".Localize().ToUpper(), smallScreen, true, AggContext.StaticData.LoadIcon("e_stop4.png", 32, 32));
resetButton.Visible = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.show_reset_connection);
resetButton.Visible = printer.Settings.GetValue<bool>(SettingsKey.show_reset_connection);
resetButton.Click += (s, e) =>
{
UiThread.RunOnIdle(printerConnection.RebootBoard);
UiThread.RunOnIdle(printer.Connection.RebootBoard);
};
actionBar.AddChild(resetButton);
@ -315,7 +316,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
{
bodyContainer.RemoveChild(basicBody);
bodyContainer.AddChild(new ManualPrinterControls(printerConnection)
bodyContainer.AddChild(new ManualPrinterControls(printer)
{
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Stretch
@ -334,12 +335,12 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
};
printerConnection.CommunicationStateChanged.RegisterEvent((s, e) =>
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
{
pauseButton.Enabled = printerConnection.PrinterIsPrinting
&& !printerConnection.PrinterIsPaused;
pauseButton.Enabled = printer.Connection.PrinterIsPrinting
&& !printer.Connection.PrinterIsPaused;
if(printerConnection.PrinterIsPaused)
if(printer.Connection.PrinterIsPaused)
{
resumeButton.Visible = true;
pauseButton.Visible = false;
@ -351,7 +352,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
// Close if not Preparing, Printing or Paused
switch (printerConnection.CommunicationState)
switch (printer.Connection.CommunicationState)
{
case CommunicationStates.PreparingToPrint:
case CommunicationStates.Printing:
@ -364,9 +365,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
}, ref unregisterEvents);
printerConnection.CommunicationStateChanged.RegisterEvent((s, e) =>
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
{
cancelButton.Enabled = printerConnection.PrinterIsPrinting || printerConnection.PrinterIsPaused;
cancelButton.Enabled = printer.Connection.PrinterIsPrinting || printer.Connection.PrinterIsPaused;
}, ref unregisterEvents);
return actionBar;
@ -385,11 +386,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
}
}
public static void Show(PrinterConnection printerConnection)
public static void Show(PrinterConfig printer)
{
if (instance == null)
{
instance = new PrintingWindow(printerConnection);
instance = new PrintingWindow(printer);
instance.ShowAsSystemWindow();
}
else
@ -492,7 +493,8 @@ namespace MatterHackers.MatterControl.CustomWidgets
private ProgressDial progressDial;
private TextWidget timeWidget;
private List<ExtruderStatusWidget> extruderStatusWidgets;
PrinterConnection printerConnection;
private PrinterConfig printer;
private void CheckOnPrinter()
{
@ -501,7 +503,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
GetProgressInfo();
// Here for safety
switch (printerConnection.CommunicationState)
switch (printer.Connection.CommunicationState)
{
case CommunicationStates.PreparingToPrint:
case CommunicationStates.Printing:
@ -519,7 +521,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
private void GetProgressInfo()
{
int secondsPrinted = printerConnection.SecondsPrinted;
int secondsPrinted = printer.Connection.SecondsPrinted;
int hoursPrinted = (int)(secondsPrinted / (60 * 60));
int minutesPrinted = (secondsPrinted / 60 - hoursPrinted * 60);
secondsPrinted = secondsPrinted % 60;
@ -527,9 +529,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
// TODO: Consider if the consistency of a common time format would look and feel better than changing formats based on elapsed duration
timeWidget.Text = (hoursPrinted <= 0) ? $"{minutesPrinted}:{secondsPrinted:00}" : $"{hoursPrinted}:{minutesPrinted:00}:{secondsPrinted:00}";
progressDial.LayerCount = printerConnection.CurrentlyPrintingLayer;
progressDial.LayerCompletedRatio = printerConnection.RatioIntoCurrentLayer;
progressDial.CompletedRatio = printerConnection.PercentComplete / 100;
progressDial.LayerCount = printer.Connection.CurrentlyPrintingLayer;
progressDial.LayerCompletedRatio = printer.Connection.RatioIntoCurrentLayer;
progressDial.CompletedRatio = printer.Connection.PercentComplete / 100;
}
public override void OnLoad(EventArgs args)
@ -629,7 +631,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
timeContainer.AddChild(timeWidget);
int maxTextWidth = 350;
printerName = new TextWidget(printerConnection.PrinterSettings.GetValue(SettingsKey.printer_name), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
printerName = new TextWidget(printer.Settings.GetValue(SettingsKey.printer_name), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
HAnchor = HAnchor.Center,
MinimumSize = new Vector2(maxTextWidth, MinimumSize.y),
@ -653,7 +655,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
// ZControls
{
var widget = new ZAxisControls(printerConnection, smallScreen)
var widget = new ZAxisControls(printer, smallScreen)
{
Margin = new BorderDouble(left: 50),
VAnchor = VAnchor.Center,
@ -670,11 +672,11 @@ namespace MatterHackers.MatterControl.CustomWidgets
};
topToBottom.AddChild(footerBar);
int extruderCount = printerConnection.PrinterSettings.GetValue<int>(SettingsKey.extruder_count);
int extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
extruderStatusWidgets = Enumerable.Range(0, extruderCount).Select((i) => new ExtruderStatusWidget(printerConnection, i)).ToList();
extruderStatusWidgets = Enumerable.Range(0, extruderCount).Select((i) => new ExtruderStatusWidget(printer, i)).ToList();
bool hasHeatedBed = printerConnection.PrinterSettings.GetValue<bool>("has_heated_bed");
bool hasHeatedBed = printer.Settings.GetValue<bool>("has_heated_bed");
if (hasHeatedBed)
{
var extruderColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
@ -688,7 +690,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
extruderColumn.AddChild(widget);
}
footerBar.AddChild(new BedStatusWidget(printerConnection, smallScreen)
footerBar.AddChild(new BedStatusWidget(printer, smallScreen)
{
VAnchor = VAnchor.Center,
});
@ -730,8 +732,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
});
}
public BasicBody(PrinterConnection printerConnection)
public BasicBody(PrinterConfig printer)
{
this.printer = printer;
VAnchor = VAnchor.Stretch;
HAnchor = HAnchor.Stretch;
}
@ -910,7 +913,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
FontSize = 13,
};
public ZAxisControls(PrinterConnection printerConnection, bool smallScreen) :
public ZAxisControls(PrinterConfig printer, bool smallScreen) :
base(FlowDirection.TopToBottom)
{
buttonFactory.Colors.Fill.Normal = ActiveTheme.Instance.PrimaryAccentColor;
@ -925,19 +928,19 @@ namespace MatterHackers.MatterControl.CustomWidgets
Margin = new BorderDouble(bottom: 8)
});
this.AddChild(CreateZMoveButton(printerConnection, .1, smallScreen));
this.AddChild(CreateZMoveButton(printer, .1, smallScreen));
this.AddChild(CreateZMoveButton(printerConnection, .02, smallScreen));
this.AddChild(CreateZMoveButton(printer, .02, smallScreen));
this.AddChild(new ZTuningWidget(printerConnection.PrinterSettings, false)
this.AddChild(new ZTuningWidget(printer.Settings, false)
{
HAnchor = HAnchor.Center | HAnchor.Fit,
Margin = 10
});
this.AddChild(CreateZMoveButton(printerConnection, -.02, smallScreen));
this.AddChild(CreateZMoveButton(printer, -.02, smallScreen));
this.AddChild(CreateZMoveButton(printerConnection, -.1, smallScreen));
this.AddChild(CreateZMoveButton(printer, -.1, smallScreen));
this.AddChild(new TextWidget("Z-", pointSize: smallScreen ? 12 : 15, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
@ -954,9 +957,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
this.VAnchor = VAnchor.Fit | VAnchor.Top;
}
private Button CreateZMoveButton(PrinterConnection printerConnection, double moveAmount, bool smallScreen)
private Button CreateZMoveButton(PrinterConfig printer, double moveAmount, bool smallScreen)
{
var button = buttonFactory.GenerateMoveButton(printerConnection, $"{Math.Abs(moveAmount):0.00} mm", PrinterConnection.Axis.Z, printerConnection.PrinterSettings.ZSpeed());
var button = buttonFactory.GenerateMoveButton(printer, $"{Math.Abs(moveAmount):0.00} mm", PrinterConnection.Axis.Z, printer.Settings.ZSpeed());
button.MoveAmount = moveAmount;
button.HAnchor = HAnchor.MaxFitOrStretch;
button.VAnchor = VAnchor.Fit;

View file

@ -180,7 +180,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
// Must come after we have an instance of View3DWidget an its undo buffer
topToBottom.AddChild(new PrinterActionsBar(printerConnection, modelViewer, this)
topToBottom.AddChild(new PrinterActionsBar(printer, modelViewer, this)
{
Padding = theme.ToolbarPadding
}, 0);
@ -278,8 +278,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
1,
new Vector2[]
{
printerConnection.PrinterSettings.Helpers.ExtruderOffset(0),
printerConnection.PrinterSettings.Helpers.ExtruderOffset(1)
printer.Settings.Helpers.ExtruderOffset(0),
printer.Settings.Helpers.ExtruderOffset(1)
},
this.GetRenderType,
MeshViewerWidget.GetExtruderColor);
@ -480,7 +480,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
popupContainer.AddChild(transparentExtrusion);
// Extrusion checkbox
if (printerConnection.PrinterSettings.GetValue<int>(SettingsKey.extruder_count) > 1)
if (printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1)
{
CheckBox hideExtruderOffsets = new CheckBox("Hide Offsets", textColor: textColor);
hideExtruderOffsets.Checked = gcodeOptions.HideExtruderOffsets;
@ -590,7 +590,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
parent.AddChild(sideBar);
if (printerConnection.PrinterSettings.PrinterSelected)
if (printer.Settings.PrinterSelected)
{
sideBar.AddPage(
"Slice Settings".Localize(),
@ -604,9 +604,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
sideBar.AddPage("Slice Settings".Localize(), new SliceSettingsMissingWidget());
}
sideBar.AddPage("Controls".Localize(), new ManualPrinterControls(printerConnection));
sideBar.AddPage("Controls".Localize(), new ManualPrinterControls(printer));
sideBar.AddPage("Terminal".Localize(), new TerminalWidget(printerConnection)
sideBar.AddPage("Terminal".Localize(), new TerminalWidget(printer.Connection)
{
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Stretch

View file

@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class PrinterActionsBar : FlowLayoutWidget
{
PrinterConnection printerConnection;
private PrinterConfig printer;
private EventHandler unregisterEvents;
private static EePromMarlinWindow openEePromMarlinWidget = null;
private static EePromRepetierWindow openEePromRepetierWidget = null;
@ -83,9 +83,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
public PrinterActionsBar(PrinterConnection printerConnection, View3DWidget modelViewer, PrinterTabPage printerTabPage)
public PrinterActionsBar(PrinterConfig printer, View3DWidget modelViewer, PrinterTabPage printerTabPage)
{
this.printerConnection = printerConnection;
this.printer = printer;
UndoBuffer undoBuffer = modelViewer.Scene.UndoBuffer;
var defaultMargin = ApplicationController.Instance.Theme.ButtonSpacing;
@ -95,9 +95,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Fit;
this.AddChild(new PrinterConnectButton(printerConnection, buttonFactory, 0));
this.AddChild(new PrinterConnectButton(printer, buttonFactory, 0));
this.AddChild(new PrintActionRow(printerConnection, buttonFactory, this, defaultMargin));
this.AddChild(new PrintActionRow(printer, buttonFactory, this, defaultMargin));
var sliceButton = buttonFactory.Generate("Slice".Localize().ToUpper());
sliceButton.ToolTipText = "Slice Parts".Localize();
@ -105,11 +105,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
sliceButton.Margin = defaultMargin;
sliceButton.Click += async (s, e) =>
{
if (printerConnection.PrinterSettings.PrinterSelected)
if (printer.Settings.PrinterSelected)
{
var printItem = ApplicationController.Instance.ActivePrintItem;
if (printerConnection.PrinterSettings.IsValid() && printItem != null)
if (printer.Settings.IsValid() && printItem != null)
{
sliceButton.Enabled = false;
@ -159,28 +159,28 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
AutoExpandBoundsToText = true,
PointSize = 8
};
printerConnection.PrintingStateChanged.RegisterEvent((e, s) =>
printer.Connection.PrintingStateChanged.RegisterEvent((e, s) =>
{
printerConnectionDetail.Text = printerConnection.PrinterConnectionStatus;
printerConnectionDetail.Text = printer.Connection.PrinterConnectionStatus;
}, ref unregisterEvents);
this.AddChild(printerConnectionDetail);
this.AddChild(new HorizontalSpacer());
bool shareTemp = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.extruders_share_temperature);
int extruderCount = shareTemp ? 1 : printerConnection.PrinterSettings.GetValue<int>(SettingsKey.extruder_count);
bool shareTemp = printer.Settings.GetValue<bool>(SettingsKey.extruders_share_temperature);
int extruderCount = shareTemp ? 1 : printer.Settings.GetValue<int>(SettingsKey.extruder_count);
for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++)
{
this.AddChild(new TemperatureWidgetHotend(printerConnection, extruderIndex, ApplicationController.Instance.Theme.MenuButtonFactory)
this.AddChild(new TemperatureWidgetHotend(printer, extruderIndex, ApplicationController.Instance.Theme.MenuButtonFactory)
{
Margin = new BorderDouble(right: 10)
});
}
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed))
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
{
this.AddChild(new TemperatureWidgetBed(printerConnection));
this.AddChild(new TemperatureWidgetBed(printer));
}
overflowDropdown = new OverflowDropdown(allowLightnessInvert: true)
@ -215,8 +215,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private GuiWidget GeneratePrinterOverflowMenu()
{
var printerSettings = printerConnection.PrinterSettings;
var menuActions = new NamedAction[]
{
new NamedAction()
@ -232,12 +230,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
var renameItemPage = new RenameItemPage(
"Rename Printer".Localize() + ":",
printerSettings.GetValue(SettingsKey.printer_name),
printer.Settings.GetValue(SettingsKey.printer_name),
(newName) =>
{
if (!string.IsNullOrEmpty(newName))
{
printerSettings.SetValue(SettingsKey.printer_name, newName);
printer.Settings.SetValue(SettingsKey.printer_name, newName);
}
});
@ -255,7 +253,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
if (doDelete)
{
printerConnection.PrinterSettings.Helpers.SetMarkedForDelete(true);
printer.Settings.Helpers.SetMarkedForDelete(true);
}
},
"Are you sure you want to delete your currently selected printer?".Localize(),
@ -275,7 +273,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
#if false // This is to force the creation of the repetier window for testing when we don't have repetier firmware.
new MatterHackers.MatterControl.EeProm.EePromRepetierWidget();
#else
switch (printerConnection.FirmwareType)
switch (printer.Connection.FirmwareType)
{
case FirmwareTypes.Repetier:
if (openEePromRepetierWidget != null)
@ -284,7 +282,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
else
{
openEePromRepetierWidget = new EePromRepetierWindow(printerConnection);
openEePromRepetierWidget = new EePromRepetierWindow(printer.Connection);
openEePromRepetierWidget.Closed += (RepetierWidget, RepetierEvent) =>
{
openEePromRepetierWidget = null;
@ -299,7 +297,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
else
{
openEePromMarlinWidget = new EePromMarlinWindow(printerConnection);
openEePromMarlinWidget = new EePromMarlinWindow(printer.Connection);
openEePromMarlinWidget.Closed += (marlinWidget, marlinEvent) =>
{
openEePromMarlinWidget = null;
@ -308,7 +306,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
break;
default:
printerConnection.SendLineToPrinterNow("M115");
printer.Connection.SendLineToPrinterNow("M115");
StyledMessageBox.ShowMessageBox(null, noEepromMappingMessage, noEepromMappingTitle, StyledMessageBox.MessageType.OK);
break;
}

View file

@ -52,14 +52,14 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private List<double> startingExtruderTemps = new List<double>();
private Stopwatch timeHaveBeenWaiting = new Stopwatch();
private bool waitingForUserInput = false;
private PrinterConnection printerConnection;
private PrinterConfig printer;
QueuedCommandsStream queuedCommandsStream;
public MacroProcessingStream(QueuedCommandsStream queuedCommandsStream, PrinterConnection printerConnection)
public MacroProcessingStream(QueuedCommandsStream queuedCommandsStream, PrinterConfig printer)
: base(queuedCommandsStream)
{
this.queuedCommandsStream = queuedCommandsStream;
this.printerConnection = printerConnection;
this.printer = printer;
}
public void Cancel()
@ -148,15 +148,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
if (!runningMacro)
{
runningMacro = true;
int extruderCount = printerConnection.PrinterSettings.GetValue<int>(SettingsKey.extruder_count);
int extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
for (int i = 0; i < extruderCount; i++)
{
startingExtruderTemps.Add(printerConnection.GetTargetHotendTemperature(i));
startingExtruderTemps.Add(printer.Connection.GetTargetHotendTemperature(i));
}
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed))
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
{
startingBedTemp = printerConnection.TargetBedTemperature;
startingBedTemp = printer.Connection.TargetBedTemperature;
}
}
int parensAfterCommand = lineToSend.IndexOf('(', MacroPrefix.Length);
@ -207,7 +207,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
UiThread.RunOnIdle(() =>
{
WizardWindow.Show(new RunningMacroPage(printerConnection, macroData));
WizardWindow.Show(new RunningMacroPage(printer.Connection, macroData));
});
break;
@ -225,7 +225,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
UiThread.RunOnIdle(() =>
{
WizardWindow.Show(new RunningMacroPage(printerConnection, macroData));
WizardWindow.Show(new RunningMacroPage(printer.Connection, macroData));
});
break;
@ -248,12 +248,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
runningMacro = false;
for (int i = 0; i < startingExtruderTemps.Count; i++)
{
printerConnection.SetTargetHotendTemperature(i, startingExtruderTemps[i]);
printer.Connection.SetTargetHotendTemperature(i, startingExtruderTemps[i]);
}
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed))
if (printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed))
{
printerConnection.TargetBedTemperature = startingBedTemp;
printer.Connection.TargetBedTemperature = startingBedTemp;
}
}
waitingForUserInput = false;

View file

@ -48,15 +48,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private PrinterMove moveLocationAtEndOfPauseCode;
private Stopwatch timeSinceLastEndstopRead = new Stopwatch();
bool readOutOfFilament = false;
PrinterConnection printerConnection;
private PrinterConfig printer;
private EventHandler unregisterEvents;
public PauseHandlingStream(PrinterConnection printerConnection, GCodeStream internalStream)
public PauseHandlingStream(PrinterConfig printer, GCodeStream internalStream)
: base(internalStream)
{
this.printerConnection = printerConnection;
printerConnection.ReadLine.RegisterEvent((s, e) =>
this.printer = printer;
printer.Connection.ReadLine.RegisterEvent((s, e) =>
{
StringEventArgs currentEvent = e as StringEventArgs;
if (currentEvent != null)
@ -105,18 +105,18 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
case PauseReason.PauseLayerReached:
case PauseReason.GCodeRequest:
printerConnection.PauseOnLayer.CallEvents(printerConnection, new PrintItemWrapperEventArgs(printerConnection.activePrintItem));
printer.Connection.PauseOnLayer.CallEvents(printer.Connection, new PrintItemWrapperEventArgs(printer.Connection.activePrintItem));
UiThread.RunOnIdle(() => StyledMessageBox.ShowMessageBox(ResumePrint, layerPauseMessage.FormatWith(layerNumber), pauseCaption, StyledMessageBox.MessageType.YES_NO, "Ok".Localize(), "Resume".Localize()));
break;
case PauseReason.FilamentRunout:
printerConnection.FilamentRunout.CallEvents(printerConnection, new PrintItemWrapperEventArgs(printerConnection.activePrintItem));
printer.Connection.FilamentRunout.CallEvents(printer.Connection, new PrintItemWrapperEventArgs(printer.Connection.activePrintItem));
UiThread.RunOnIdle(() => StyledMessageBox.ShowMessageBox(ResumePrint, filamentPauseMessage, pauseCaption, StyledMessageBox.MessageType.YES_NO, "Ok".Localize(), "Resume".Localize()));
break;
}
// Add the pause_gcode to the loadedGCode.GCodeCommandQueue
string pauseGCode = printerConnection.PrinterSettings.GetValue(SettingsKey.pause_gcode);
string pauseGCode = printer.Settings.GetValue(SettingsKey.pause_gcode);
// put in the gcode for pausing (if any)
InjectPauseGCode(pauseGCode);
@ -130,9 +130,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private void ResumePrint(bool clickedOk)
{
// They clicked either Resume or Ok
if (!clickedOk && printerConnection.PrinterIsPaused)
if (!clickedOk && printer.Connection.PrinterIsPaused)
{
printerConnection.Resume();
printer.Connection.Resume();
}
}
@ -151,7 +151,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
if (lineToSend == null)
{
if (!printerConnection.PrinterIsPaused)
if (!printer.Connection.PrinterIsPaused)
{
lineToSend = base.ReadLine();
if (lineToSend == null)
@ -160,12 +160,12 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
// We got a line from the gcode we are sending check if we should queue a request for filament runout
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.filament_runout_sensor))
if (printer.Settings.GetValue<bool>(SettingsKey.filament_runout_sensor))
{
// request to read the endstop state
if (!timeSinceLastEndstopRead.IsRunning || timeSinceLastEndstopRead.ElapsedMilliseconds > 5000)
{
printerConnection.SendLineToPrinterNow("M119");
printer.Connection.SendLineToPrinterNow("M119");
timeSinceLastEndstopRead.Restart();
}
}
@ -194,10 +194,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
moveLocationAtEndOfPauseCode = LastDestination;
if (printerConnection.PrinterIsPrinting)
if (printer.Connection.PrinterIsPrinting)
{
// remember where we were after we ran the pause gcode
printerConnection.CommunicationState = CommunicationStates.Paused;
printer.Connection.CommunicationState = CommunicationStates.Paused;
}
lineToSend = "";
@ -225,11 +225,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
Vector3 positionBeforeActualPause = moveLocationAtEndOfPauseCode.position;
InjectPauseGCode("G92 E{0:0.###}".FormatWith(moveLocationAtEndOfPauseCode.extrusion));
Vector3 ensureAllAxisAreSent = positionBeforeActualPause + new Vector3(.01, .01, .01);
var feedRates = printerConnection.PrinterSettings.Helpers.ManualMovementSpeeds();
var feedRates = printer.Settings.Helpers.ManualMovementSpeeds();
InjectPauseGCode("G1 X{0:0.###} Y{1:0.###} Z{2:0.###} F{3}".FormatWith(ensureAllAxisAreSent.x, ensureAllAxisAreSent.y, ensureAllAxisAreSent.z, feedRates.x + 1));
InjectPauseGCode("G1 X{0:0.###} Y{1:0.###} Z{2:0.###} F{3}".FormatWith(positionBeforeActualPause.x, positionBeforeActualPause.y, positionBeforeActualPause.z, feedRates));
string resumeGCode = printerConnection.PrinterSettings.GetValue(SettingsKey.resume_gcode);
string resumeGCode = printer.Settings.GetValue(SettingsKey.resume_gcode);
InjectPauseGCode(resumeGCode);
InjectPauseGCode("M114"); // make sure we know where we are after this resume code
}
@ -262,7 +262,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
int layerNumber;
if (int.TryParse(layer, out layerNumber) && printerConnection.PrinterSettings.Helpers.LayerToPauseOn().Contains(layerNumber))
if (int.TryParse(layer, out layerNumber) && printer.Settings.Helpers.LayerToPauseOn().Contains(layerNumber))
{
return true;
}

View file

@ -47,15 +47,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
RectangleDouble boundsOfSkippedLayers = RectangleDouble.ZeroIntersection;
RecoveryState recoveryState = RecoveryState.RemoveHeating;
PrinterConnection printerConnection;
private PrinterConfig printer;
public PrintRecoveryStream(PrinterConnection printerConnection, GCodeFileStream internalStream, double percentDone)
public PrintRecoveryStream(PrinterConfig printer, GCodeFileStream internalStream, double percentDone)
{
this.printerConnection = printerConnection;
this.printer = printer;
this.internalStream = internalStream;
this.percentDone = percentDone;
recoverFeedRate = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.recover_first_layer_speed);
recoverFeedRate = printer.Settings.GetValue<double>(SettingsKey.recover_first_layer_speed);
if (recoverFeedRate == 0)
{
recoverFeedRate = 10;
@ -96,8 +96,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
queuedCommands.Add("G92 E0; reset the expected extruder position");
queuedCommands.Add("M82; use absolute distance for extrusion");
bool hasHeatedBed = printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.has_heated_bed);
double bedTemp = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.bed_temperature);
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
double bedTemp = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
if (hasHeatedBed && bedTemp > 0)
{
// start heating the bed
@ -105,7 +105,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
// heat up the extruder
queuedCommands.Add("M109 S{0}".FormatWith(printerConnection.PrinterSettings.Helpers.ExtruderTemperature(0)));
queuedCommands.Add("M109 S{0}".FormatWith(printer.Settings.Helpers.ExtruderTemperature(0)));
if (hasHeatedBed && bedTemp > 0)
{
@ -122,14 +122,14 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
PrintLevelingStream.Enabled = false;
queuedCommands.Add("M114 ; get current position");
queuedCommands.Add("G91 ; move relative");
queuedCommands.Add("G1 Z10 F{0}".FormatWith(printerConnection.PrinterSettings.ZSpeed()));
queuedCommands.Add("G1 Z10 F{0}".FormatWith(printer.Settings.ZSpeed()));
queuedCommands.Add("G90 ; move absolute");
recoveryState = RecoveryState.Homing;
return "";
// if top homing, home the extruder
case RecoveryState.Homing:
if (printerConnection.PrinterSettings.GetValue<bool>(SettingsKey.z_homes_to_max))
if (printer.Settings.GetValue<bool>(SettingsKey.z_homes_to_max))
{
queuedCommands.Add("G28");
}
@ -140,8 +140,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
// home y
queuedCommands.Add("G28 Y0");
// move to the place we can home z from
Vector2 recoveryPositionXy = printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
queuedCommands.Add("G1 X{0:0.###}Y{1:0.###}F{2}".FormatWith(recoveryPositionXy.x, recoveryPositionXy.y, printerConnection.PrinterSettings.XSpeed()));
Vector2 recoveryPositionXy = printer.Settings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
queuedCommands.Add("G1 X{0:0.###}Y{1:0.###}F{2}".FormatWith(recoveryPositionXy.x, recoveryPositionXy.y, printer.Settings.XSpeed()));
// home z
queuedCommands.Add("G28 Z0");
}
@ -219,25 +219,25 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
case RecoveryState.PrimingAndMovingToStart:
{
if (printerConnection.PrinterSettings.GetValue("z_homes_to_max") == "0") // we are homed to the bed
if (printer.Settings.GetValue("z_homes_to_max") == "0") // we are homed to the bed
{
// move to the height we can recover printing from
Vector2 recoverPositionXy = printerConnection.PrinterSettings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
queuedCommands.Add(CreateMovementLine(new PrinterMove(new VectorMath.Vector3(recoverPositionXy.x, recoverPositionXy.y, lastDestination.position.z), 0, printerConnection.PrinterSettings.ZSpeed())));
Vector2 recoverPositionXy = printer.Settings.GetValue<Vector2>(SettingsKey.recover_position_before_z_home);
queuedCommands.Add(CreateMovementLine(new PrinterMove(new VectorMath.Vector3(recoverPositionXy.x, recoverPositionXy.y, lastDestination.position.z), 0, printer.Settings.ZSpeed())));
}
double extruderWidth = printerConnection.PrinterSettings.GetValue<double>(SettingsKey.nozzle_diameter);
double extruderWidth = printer.Settings.GetValue<double>(SettingsKey.nozzle_diameter);
// move to a position outside the printed bounds
queuedCommands.Add(CreateMovementLine(new PrinterMove(
new Vector3(boundsOfSkippedLayers.Left - extruderWidth*2, boundsOfSkippedLayers.Bottom + boundsOfSkippedLayers.Height / 2, lastDestination.position.z),
0, printerConnection.PrinterSettings.XSpeed())));
0, printer.Settings.XSpeed())));
// let's prime the extruder
queuedCommands.Add("G1 E10 F{0}".FormatWith(printerConnection.PrinterSettings.EFeedRate(0))); // extrude 10
queuedCommands.Add("G1 E10 F{0}".FormatWith(printer.Settings.EFeedRate(0))); // extrude 10
queuedCommands.Add("G1 E9"); // and retract a bit
// move to the actual print position
queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, printerConnection.PrinterSettings.XSpeed())));
queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, printer.Settings.XSpeed())));
/// reset the printer to know where the filament should be
queuedCommands.Add("G92 E{0}".FormatWith(lastDestination.extrusion));

View file

@ -359,7 +359,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
var eventArgs = e as StringEventArgs;
if (eventArgs?.Data == SettingsKey.feedrate_ratio)
{
feedRateRatio = this.PrinterSettings.GetValue<double>(SettingsKey.feedrate_ratio);
feedRateRatio = this.printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio);
}
}, ref unregisterEvents);
}
@ -403,13 +403,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication
get
{
int baudRate = 250000;
if (this.PrinterSettings != null)
if (this.printer.Settings != null)
{
try
{
if (!string.IsNullOrEmpty(PrinterSettings.GetValue(SettingsKey.baud_rate)))
if (!string.IsNullOrEmpty(printer.Settings.GetValue(SettingsKey.baud_rate)))
{
baudRate = Convert.ToInt32(PrinterSettings.GetValue(SettingsKey.baud_rate));
baudRate = Convert.ToInt32(printer.Settings.GetValue(SettingsKey.baud_rate));
}
}
catch
@ -500,15 +500,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication
PrintFinished.CallEvents(this, new PrintItemWrapperEventArgs(this.activePrintItem));
// clear single use setting on print completion
foreach (var keyValue in PrinterSettings.BaseLayer)
foreach (var keyValue in printer.Settings.BaseLayer)
{
string currentValue = PrinterSettings.GetValue(keyValue.Key);
string currentValue = printer.Settings.GetValue(keyValue.Key);
bool valueIsClear = currentValue == "0" | currentValue == "";
SliceSettingData data = SliceSettingsOrganizer.Instance.GetSettingsData(keyValue.Key);
if (data?.ResetAtEndOfPrint == true && !valueIsClear)
{
PrinterSettings.ClearValue(keyValue.Key);
printer.Settings.ClearValue(keyValue.Key);
}
}
}
@ -547,9 +547,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication
}
}
public string ComPort => PrinterSettings?.Helpers.ComPort();
public string ComPort => printer.Settings?.Helpers.ComPort();
public string DriverType => (this.ComPort == "Emulator") ? "Emulator" : PrinterSettings?.GetValue("driver_type");
public string DriverType => (this.ComPort == "Emulator") ? "Emulator" : printer.Settings?.GetValue("driver_type");
public bool AtxPowerEnabled
{
@ -909,16 +909,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication
}
}
// TODO: Consider having callers use the source rather than this proxy? Maybe better to change after arriving on a final type and location for printer settings
public PrinterSettings PrinterSettings => ActiveSliceSettings.Instance;
// HACK: PrinterConnection must be revised to take a constructor that receives and stores a reference to its parent PrinterConfig - this
private PrinterConfig printer => ApplicationController.Instance.Printer;
private int NumberOfLinesInCurrentPrint
{
get
{
return loadedGCode.LineCount;
}
}
private int NumberOfLinesInCurrentPrint => loadedGCode.LineCount;
/// <summary>
/// Abort an ongoing attempt to establish communication with a printer due to the specified problem. This is a specialized
@ -990,10 +984,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication
public void ConnectToActivePrinter(bool showHelpIfNoPort = false)
{
if (PrinterSettings != null)
if (printer.Settings != null)
{
// Start the process of requesting permission and exit if permission is not currently granted
if (!PrinterSettings.GetValue<bool>(SettingsKey.enable_network_printing)
if (!printer.Settings.GetValue<bool>(SettingsKey.enable_network_printing)
&& !FrostedSerialPort.EnsureDeviceAccess())
{
CommunicationState = CommunicationStates.FailedToConnect;
@ -1013,7 +1007,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
if (!string.IsNullOrEmpty(currentPortName))
{
// TODO: Ensure that this does *not* cause a write to the settings file and should be an in memory update only
PrinterSettings?.Helpers.SetComPort(currentPortName);
printer.Settings?.Helpers.SetComPort(currentPortName);
}
#endif
@ -1413,7 +1407,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
{
// TODO: Ideally we would shutdown the printer connection when this method is called and we're connected. The
// current approach results in unpredictable behavior if the caller fails to close the connection
if (serialPort == null && this.PrinterSettings != null)
if (serialPort == null && this.printer.Settings != null)
{
IFrostedSerialPort resetSerialPort = FrostedSerialPortFactory.GetAppropriateFactory(this.DriverType).Create(this.ComPort);
resetSerialPort.Open();
@ -1524,7 +1518,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
haveReportedError = false;
// now send any command that initialize this printer
ClearQueuedGCode();
string connectGCode = PrinterSettings.GetValue(SettingsKey.connect_gcode);
string connectGCode = printer.Settings.GetValue(SettingsKey.connect_gcode);
SendLineToPrinterNow(connectGCode);
// and call back anyone who would like to know we connected
@ -1679,7 +1673,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
{
try
{
if (PrinterSettings.PrinterSelected)
if (printer.Settings.PrinterSelected)
{
// first make sure we are not printing if possible (cancel slicing)
if (serialPort != null) // we still have a serial port
@ -1859,11 +1853,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication
private string ProcessReadRegEx(string lineBeingRead)
{
if (read_regex != PrinterSettings.GetValue(SettingsKey.read_regex))
if (read_regex != printer.Settings.GetValue(SettingsKey.read_regex))
{
ReadLineReplacements.Clear();
string splitString = "\\n";
read_regex = PrinterSettings.GetValue(SettingsKey.read_regex);
read_regex = printer.Settings.GetValue(SettingsKey.read_regex);
foreach (string regExLine in read_regex.Split(splitString.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
var matches = getQuotedParts.Matches(regExLine);
@ -2029,7 +2023,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
{
// get rid of all the gcode we have left to print
ClearQueuedGCode();
string cancelGCode = PrinterSettings.GetValue(SettingsKey.cancel_gcode);
string cancelGCode = printer.Settings.GetValue(SettingsKey.cancel_gcode);
if (cancelGCode.Trim() != "")
{
// add any gcode we want to print while canceling
@ -2300,17 +2294,17 @@ namespace MatterHackers.MatterControl.PrinterCommunication
loadedGCode = GCodeFile.Load(gcodeFilename, CancellationToken.None);
gCodeFileStream0 = new GCodeFileStream(loadedGCode);
if (PrinterSettings.GetValue<bool>(SettingsKey.recover_is_enabled)
if (printer.Settings.GetValue<bool>(SettingsKey.recover_is_enabled)
&& activePrintTask != null) // We are resuming a failed print (do lots of interesting stuff).
{
pauseHandlingStream1 = new PauseHandlingStream(this, new PrintRecoveryStream(this, gCodeFileStream0, activePrintTask.PercentDone));
pauseHandlingStream1 = new PauseHandlingStream(printer, new PrintRecoveryStream(printer, gCodeFileStream0, activePrintTask.PercentDone));
// And increment the recovery count
activePrintTask.RecoveryCount++;
activePrintTask.Commit();
}
else
{
pauseHandlingStream1 = new PauseHandlingStream(this, gCodeFileStream0);
pauseHandlingStream1 = new PauseHandlingStream(printer, gCodeFileStream0);
}
firstStream = pauseHandlingStream1;
@ -2321,11 +2315,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication
}
queuedCommandStream2 = new QueuedCommandsStream(firstStream);
macroProcessingStream3 = new MacroProcessingStream(queuedCommandStream2, this);
macroProcessingStream3 = new MacroProcessingStream(queuedCommandStream2, printer);
relativeToAbsoluteStream4 = new RelativeToAbsoluteStream(macroProcessingStream3);
printLevelingStream5 = new PrintLevelingStream(PrinterSettings, relativeToAbsoluteStream4, true);
printLevelingStream5 = new PrintLevelingStream(printer.Settings, relativeToAbsoluteStream4, true);
waitForTempStream6 = new WaitForTempStream(this, printLevelingStream5);
babyStepsStream7 = new BabyStepsStream(PrinterSettings, waitForTempStream6, gcodeFilename == null ? 2000 : 1);
babyStepsStream7 = new BabyStepsStream(printer.Settings, waitForTempStream6, gcodeFilename == null ? 2000 : 1);
if (activePrintTask != null)
{
// make sure we are in the position we were when we stopped printing
@ -2334,7 +2328,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
extrusionMultiplyerStream8 = new ExtrusionMultiplyerStream(babyStepsStream7);
feedrateMultiplyerStream9 = new FeedRateMultiplyerStream(extrusionMultiplyerStream8);
requestTemperaturesStream10 = new RequestTemperaturesStream(this, feedrateMultiplyerStream9);
processWriteRegExStream11 = new ProcessWriteRegexStream(this.PrinterSettings, requestTemperaturesStream10, queuedCommandStream2);
processWriteRegExStream11 = new ProcessWriteRegexStream(this.printer.Settings, requestTemperaturesStream10, queuedCommandStream2);
totalGCodeStream = processWriteRegExStream11;
// Get the current position of the printer any time we reset our streams
@ -2343,7 +2337,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
private void LoadGCodeToPrint(string gcodeFilename)
{
CreateStreamProcessors(gcodeFilename, PrinterSettings.GetValue<bool>(SettingsKey.recover_is_enabled));
CreateStreamProcessors(gcodeFilename, printer.Settings.GetValue<bool>(SettingsKey.recover_is_enabled));
}
internal PrintItemWrapper activePrintItem;
@ -2367,7 +2361,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
// TODO: Fix printerItemID int requirement
activePrintTask = new PrintTask();
activePrintTask.PrintStart = DateTime.Now;
activePrintTask.PrinterId = this.PrinterSettings.ID.GetHashCode();
activePrintTask.PrinterId = this.printer.Settings.ID.GetHashCode();
activePrintTask.PrintName = activePrintItem.PrintItem.Name;
activePrintTask.PrintItemId = activePrintItem.PrintItem.Id;
activePrintTask.PrintingGCodeFileName = activePrintItem.GetGCodePathAndFileName();
@ -2446,7 +2440,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
private bool IsNetworkPrinting()
{
return PrinterSettings.GetValue<bool>(SettingsKey.enable_network_printing);
return printer.Settings.GetValue<bool>(SettingsKey.enable_network_printing);
}
private void OnAtxPowerStateChanged(bool enableAtxPower)
@ -2619,7 +2613,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
private void TurnOffBedAndExtruders()
{
for (int i = 0; i < PrinterSettings.GetValue<int>(SettingsKey.extruder_count); i++)
for (int i = 0; i < printer.Settings.GetValue<int>(SettingsKey.extruder_count); i++)
{
SetTargetHotendTemperature(i, 0, true);
}

View file

@ -40,19 +40,19 @@ namespace MatterHackers.MatterControl.PrinterControls
{
public class MacroControls : ControlWidgetBase
{
public MacroControls(PrinterConnection printerConnection, int headingPointSize)
public MacroControls(PrinterConfig printer, int headingPointSize)
{
this.AddChild(new MacroControlsWidget(printerConnection, headingPointSize));
this.AddChild(new MacroControlsWidget(printer, headingPointSize));
}
}
public class MacroControlsWidget : FlowLayoutWidget
{
PrinterConnection printerConnection;
public MacroControlsWidget(PrinterConnection printerConnection, int headingPointSize)
private PrinterConfig printer;
public MacroControlsWidget(PrinterConfig printer, int headingPointSize)
: base(FlowDirection.TopToBottom)
{
this.printerConnection = printerConnection;
this.printer = printer;
var buttonFactory = ApplicationController.Instance.Theme.HomingButtons;
this.HAnchor = HAnchor.Stretch;
@ -90,17 +90,17 @@ namespace MatterHackers.MatterControl.PrinterControls
macroContainer.AddChild(noMacrosFound);
noMacrosFound.Visible = false;
if (printerConnection.PrinterSettings?.GetMacros(MacroUiLocation.Controls).Any() != true)
if (printer.Settings?.GetMacros(MacroUiLocation.Controls).Any() != true)
{
noMacrosFound.Visible = true;
return macroContainer;
}
foreach (GCodeMacro macro in printerConnection.PrinterSettings.GetMacros(MacroUiLocation.Controls))
foreach (GCodeMacro macro in printer.Settings.GetMacros(MacroUiLocation.Controls))
{
Button macroButton = buttonFactory.Generate(GCodeMacro.FixMacroName(macro.Name));
macroButton.Margin = new BorderDouble(right: 5);
macroButton.Click += (s, e) => macro.Run(printerConnection);
macroButton.Click += (s, e) => macro.Run(printer.Connection);
macroContainer.AddChild(macroButton);
}

View file

@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.PrinterControls
{
public class MovementControls : ControlWidgetBase
{
PrinterConnection printerConnection;
private PrinterConfig printer;
public FlowLayoutWidget manualControlsLayout;
private Button disableMotors;
private EditManualMovementSpeedsWindow editManualMovementSettingsWindow;
@ -85,9 +85,9 @@ namespace MatterHackers.MatterControl.PrinterControls
return container;
}
public MovementControls(PrinterConnection printerConnection, int headingPointSize)
public MovementControls(PrinterConfig printer, int headingPointSize)
{
this.printerConnection = printerConnection;
this.printer = printer;
var buttonFactory = ApplicationController.Instance.Theme.DisableableControlBase;
Button editButton;
@ -103,7 +103,7 @@ namespace MatterHackers.MatterControl.PrinterControls
{
if (editManualMovementSettingsWindow == null)
{
editManualMovementSettingsWindow = new EditManualMovementSpeedsWindow("Movement Speeds".Localize(), printerConnection.PrinterSettings.Helpers.GetMovementSpeedsString(), SetMovementSpeeds);
editManualMovementSettingsWindow = new EditManualMovementSpeedsWindow("Movement Speeds".Localize(), printer.Settings.Helpers.GetMovementSpeedsString(), SetMovementSpeeds);
editManualMovementSettingsWindow.Closed += (s, e2) =>
{
editManualMovementSettingsWindow = null;
@ -115,7 +115,7 @@ namespace MatterHackers.MatterControl.PrinterControls
}
};
jogControls = new JogControls(printerConnection, new XYZColors());
jogControls = new JogControls(printer, new XYZColors());
jogControls.Margin = new BorderDouble(0);
manualControlsLayout = new FlowLayoutWidget(FlowDirection.TopToBottom)
@ -145,7 +145,7 @@ namespace MatterHackers.MatterControl.PrinterControls
{
if (!string.IsNullOrEmpty(speedString))
{
printerConnection.PrinterSettings.SetValue(SettingsKey.manual_movement_speeds, speedString);
printer.Settings.SetValue(SettingsKey.manual_movement_speeds, speedString);
ApplicationController.Instance.ReloadAdvancedControlsPanel();
}
}
@ -198,7 +198,7 @@ namespace MatterHackers.MatterControl.PrinterControls
disableMotors.Margin = new BorderDouble(0);
disableMotors.Click += (s, e) =>
{
printerConnection.ReleaseMotors();
printer.Connection.ReleaseMotors();
};
homeButtonBar.AddChild(homeIconImageWidget);
@ -216,7 +216,7 @@ namespace MatterHackers.MatterControl.PrinterControls
};
homeButtonBar.AddChild(offsetStreamLabel);
var ztuningWidget = new ZTuningWidget(printerConnection.PrinterSettings);
var ztuningWidget = new ZTuningWidget(printer.Settings);
homeButtonBar.AddChild(ztuningWidget);
homeButtonBar.AddChild(new HorizontalSpacer());
@ -250,7 +250,7 @@ namespace MatterHackers.MatterControl.PrinterControls
});
});
printerConnection.DestinationChanged.RegisterEvent((object sender, EventArgs e) =>
printer.Connection.DestinationChanged.RegisterEvent((object sender, EventArgs e) =>
{
reportDestinationChanged.CallEvent();
}, ref unregisterEvents);
@ -260,7 +260,7 @@ namespace MatterHackers.MatterControl.PrinterControls
private void SetDestinationPositionText(TextWidget xPosition, TextWidget yPosition, TextWidget zPosition)
{
Vector3 destinationPosition = printerConnection.CurrentDestination;
Vector3 destinationPosition = printer.Connection.CurrentDestination;
xPosition.Text = "X: {0:0.00}".FormatWith(destinationPosition.x);
yPosition.Text = "Y: {0:0.00}".FormatWith(destinationPosition.y);
zPosition.Text = "Z: {0:0.00}".FormatWith(destinationPosition.z);
@ -268,22 +268,22 @@ namespace MatterHackers.MatterControl.PrinterControls
private void homeAll_Click(object sender, EventArgs mouseEvent)
{
printerConnection.HomeAxis(PrinterConnection.Axis.XYZ);
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
}
private void homeXButton_Click(object sender, EventArgs mouseEvent)
{
printerConnection.HomeAxis(PrinterConnection.Axis.X);
printer.Connection.HomeAxis(PrinterConnection.Axis.X);
}
private void homeYButton_Click(object sender, EventArgs mouseEvent)
{
printerConnection.HomeAxis(PrinterConnection.Axis.Y);
printer.Connection.HomeAxis(PrinterConnection.Axis.Y);
}
private void homeZButton_Click(object sender, EventArgs mouseEvent)
{
printerConnection.HomeAxis(PrinterConnection.Axis.Z);
printer.Connection.HomeAxis(PrinterConnection.Axis.Z);
}
}

View file

@ -44,14 +44,14 @@ namespace MatterHackers.MatterControl
{
static public RootedObjectEventHandler AddPluginControls = new RootedObjectEventHandler();
private static bool pluginsQueuedToAdd = false;
PrinterConnection printerConnection;
PrinterConfig printer;
public ManualPrinterControls(PrinterConnection printerConnection)
public ManualPrinterControls(PrinterConfig printer)
{
this.BackgroundColor = ApplicationController.Instance.Theme.TabBodyBackground;
AnchorAll();
AddChild(new ManualPrinterControlsDesktop(printerConnection));
AddChild(new ManualPrinterControlsDesktop(printer));
}
public override void OnLoad(EventArgs args)
@ -79,11 +79,11 @@ namespace MatterHackers.MatterControl
private DisableableWidget calibrationControlsContainer;
private EventHandler unregisterEvents;
PrinterConnection printerConnection;
private PrinterConfig printer;
public ManualPrinterControlsDesktop(PrinterConnection printerConnection)
public ManualPrinterControlsDesktop(PrinterConfig printer)
{
this.printerConnection = printerConnection;
this.printer = printer;
ScrollArea.HAnchor |= HAnchor.Stretch;
AnchorAll();
AutoScroll = true;
@ -104,16 +104,16 @@ namespace MatterHackers.MatterControl
};
this.AddChild(controlsTopToBottomLayout);
movementControlsContainer = new MovementControls(printerConnection, headingPointSize);
movementControlsContainer = new MovementControls(printer, headingPointSize);
controlsTopToBottomLayout.AddChild(movementControlsContainer);
if (!ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_hardware_leveling))
{
calibrationControlsContainer = new CalibrationSettingsWidget(printerConnection, theme.ButtonFactory, headingPointSize);
calibrationControlsContainer = new CalibrationSettingsWidget(printer, theme.ButtonFactory, headingPointSize);
controlsTopToBottomLayout.AddChild(calibrationControlsContainer);
}
macroControlsContainer = new MacroControls(printerConnection, headingPointSize);
macroControlsContainer = new MacroControls(printer, headingPointSize);
controlsTopToBottomLayout.AddChild(macroControlsContainer);
var linearPanel = new FlowLayoutWidget()
@ -122,14 +122,14 @@ namespace MatterHackers.MatterControl
};
controlsTopToBottomLayout.AddChild(linearPanel);
fanControlsContainer = new FanControls(printerConnection, headingPointSize);
fanControlsContainer = new FanControls(printer.Connection, headingPointSize);
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_fan))
{
controlsTopToBottomLayout.AddChild(fanControlsContainer);
}
#if !__ANDROID__
controlsTopToBottomLayout.AddChild(new PowerControls(printerConnection, headingPointSize));
controlsTopToBottomLayout.AddChild(new PowerControls(printer.Connection, headingPointSize));
#endif
tuningAdjustmentControlsContainer = new AdjustmentControls(headingPointSize);
controlsTopToBottomLayout.AddChild(tuningAdjustmentControlsContainer);
@ -137,8 +137,8 @@ namespace MatterHackers.MatterControl
// HACK: this is a hack to make the layout engine fire again for this control
UiThread.RunOnIdle(() => tuningAdjustmentControlsContainer.Width = tuningAdjustmentControlsContainer.Width + 1);
printerConnection.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
printerConnection.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
printer.Connection.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
printer.Connection.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
SetVisibleControls();
}
@ -167,7 +167,7 @@ namespace MatterHackers.MatterControl
}
else // we at least have a printer selected
{
switch (printerConnection.CommunicationState)
switch (printer.Connection.CommunicationState)
{
case CommunicationStates.Disconnecting:
case CommunicationStates.ConnectionLost:
@ -213,7 +213,7 @@ namespace MatterHackers.MatterControl
case CommunicationStates.PreparingToPrint:
case CommunicationStates.Printing:
switch (printerConnection.DetailedPrintingState)
switch (printer.Connection.DetailedPrintingState)
{
case DetailedPrintingState.HomingAxis:
case DetailedPrintingState.HeatingBed:

View file

@ -60,11 +60,11 @@ namespace MatterHackers.MatterControl
private MoveButton zMinusControl;
private MoveButtonFactory moveButtonFactory = new MoveButtonFactory();
PrinterConnection printerConnection;
private PrinterConfig printer;
public JogControls(PrinterConnection printerConnection, XYZColors colors)
public JogControls(PrinterConfig printer, XYZColors colors)
{
this.printerConnection = printerConnection;
this.printer = printer;
moveButtonFactory.Colors.Text.Normal = RGBA_Bytes.Black;
double distanceBetweenControls = 12;
@ -84,7 +84,7 @@ namespace MatterHackers.MatterControl
GuiWidget xyGrid = CreateXYGridControl(colors, distanceBetweenControls, buttonSeparationDistance);
xYZControls.AddChild(xyGrid);
FlowLayoutWidget zButtons = CreateZButtons(printerConnection, XYZColors.zColor, buttonSeparationDistance, out zPlusControl, out zMinusControl);
FlowLayoutWidget zButtons = CreateZButtons(printer, XYZColors.zColor, buttonSeparationDistance, out zPlusControl, out zMinusControl);
zButtons.VAnchor = Agg.UI.VAnchor.Bottom;
xYZControls.AddChild(zButtons);
xYZWithDistance.AddChild(xYZControls);
@ -325,58 +325,58 @@ namespace MatterHackers.MatterControl
int eMoveAmountNegative = -EAxisMoveAmount;
// if we are not printing and on mac or PC
if (printerConnection.CommunicationState != CommunicationStates.Printing
if (printer.Connection.CommunicationState != CommunicationStates.Printing
&& (AggContext.OperatingSystem == OSType.Windows || AggContext.OperatingSystem == OSType.Mac))
{
if (e.KeyCode == Keys.Z)
{
if (printerConnection.CommunicationState != CommunicationStates.Printing)
if (printer.Connection.CommunicationState != CommunicationStates.Printing)
{
printerConnection.HomeAxis(PrinterConnection.Axis.Z);
printer.Connection.HomeAxis(PrinterConnection.Axis.Z);
}
}
else if (e.KeyCode == Keys.Y)
{
printerConnection.HomeAxis(PrinterConnection.Axis.Y);
printer.Connection.HomeAxis(PrinterConnection.Axis.Y);
}
else if (e.KeyCode == Keys.X)
{
printerConnection.HomeAxis(PrinterConnection.Axis.X);
printer.Connection.HomeAxis(PrinterConnection.Axis.X);
}
if (e.KeyCode == Keys.Home)
{
printerConnection.HomeAxis(PrinterConnection.Axis.XYZ);
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
}
else if (e.KeyCode == Keys.Left)
{
printerConnection.MoveRelative(PrinterConnection.Axis.X, moveAmountNegative, printerConnection.PrinterSettings.XSpeed());
printer.Connection.MoveRelative(PrinterConnection.Axis.X, moveAmountNegative, printer.Settings.XSpeed());
}
else if (e.KeyCode == Keys.Right)
{
printerConnection.MoveRelative(PrinterConnection.Axis.X, moveAmountPositive, printerConnection.PrinterSettings.XSpeed());
printer.Connection.MoveRelative(PrinterConnection.Axis.X, moveAmountPositive, printer.Settings.XSpeed());
}
else if (e.KeyCode == Keys.Up)
{
printerConnection.MoveRelative(PrinterConnection.Axis.Y, moveAmountPositive, printerConnection.PrinterSettings.YSpeed());
printer.Connection.MoveRelative(PrinterConnection.Axis.Y, moveAmountPositive, printer.Settings.YSpeed());
}
else if (e.KeyCode == Keys.Down)
{
printerConnection.MoveRelative(PrinterConnection.Axis.Y, moveAmountNegative, printerConnection.PrinterSettings.YSpeed());
printer.Connection.MoveRelative(PrinterConnection.Axis.Y, moveAmountNegative, printer.Settings.YSpeed());
}
else if (e.KeyCode == Keys.E)
{
printerConnection.MoveRelative(PrinterConnection.Axis.E, eMoveAmountPositive, printerConnection.PrinterSettings.EFeedRate(0));
printer.Connection.MoveRelative(PrinterConnection.Axis.E, eMoveAmountPositive, printer.Settings.EFeedRate(0));
}
else if (e.KeyCode == Keys.R)
{
printerConnection.MoveRelative(PrinterConnection.Axis.E, eMoveAmountNegative, printerConnection.PrinterSettings.EFeedRate(0));
printer.Connection.MoveRelative(PrinterConnection.Axis.E, eMoveAmountNegative, printer.Settings.EFeedRate(0));
}
}
if ((AggContext.OperatingSystem == OSType.Windows && e.KeyCode == Keys.PageUp)
|| (AggContext.OperatingSystem == OSType.Mac && e.KeyCode == (Keys.Back | Keys.Cancel)))
{
if (printerConnection.CommunicationState == CommunicationStates.Printing)
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
var currentZ = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += moveAmountPositive;
@ -384,13 +384,13 @@ namespace MatterHackers.MatterControl
}
else
{
printerConnection.MoveRelative(PrinterConnection.Axis.Z, moveAmountPositive, printerConnection.PrinterSettings.ZSpeed());
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, moveAmountPositive, printer.Settings.ZSpeed());
}
}
else if ((AggContext.OperatingSystem == OSType.Windows && e.KeyCode == Keys.PageDown)
|| (AggContext.OperatingSystem == OSType.Mac && e.KeyCode == Keys.Clear))
{
if (printerConnection.CommunicationState == CommunicationStates.Printing)
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
var currentZ = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += moveAmountNegative;
@ -398,7 +398,7 @@ namespace MatterHackers.MatterControl
}
else
{
printerConnection.MoveRelative(PrinterConnection.Axis.Z, moveAmountNegative, printerConnection.PrinterSettings.ZSpeed());
printer.Connection.MoveRelative(PrinterConnection.Axis.Z, moveAmountNegative, printer.Settings.ZSpeed());
}
}
}
@ -414,7 +414,7 @@ namespace MatterHackers.MatterControl
if (extruderCount == 1)
{
ExtrudeButton eMinusControl = CreateExtrudeButton(printerConnection, "E-", printerConnection.PrinterSettings.EFeedRate(0), 0, moveButtonFactory);
ExtrudeButton eMinusControl = CreateExtrudeButton(printer, "E-", printer.Settings.EFeedRate(0), 0, moveButtonFactory);
eMinusControl.Margin = extrusionMargin;
eMinusControl.ToolTipText = "Retract filament".Localize();
eMinusButtonAndText.AddChild(eMinusControl);
@ -424,7 +424,7 @@ namespace MatterHackers.MatterControl
{
for (int i = 0; i < extruderCount; i++)
{
ExtrudeButton eMinusControl = CreateExtrudeButton(printerConnection, $"E{i + 1}-", printerConnection.PrinterSettings.EFeedRate(0), i, moveButtonFactory);
ExtrudeButton eMinusControl = CreateExtrudeButton(printer, $"E{i + 1}-", printer.Settings.EFeedRate(0), i, moveButtonFactory);
eMinusControl.ToolTipText = "Retract filament".Localize();
eMinusControl.Margin = extrusionMargin;
eMinusButtonAndText.AddChild(eMinusControl);
@ -460,7 +460,7 @@ namespace MatterHackers.MatterControl
FlowLayoutWidget ePlusButtonAndText = new FlowLayoutWidget();
if (extruderCount == 1)
{
ExtrudeButton ePlusControl = CreateExtrudeButton(printerConnection, "E+", printerConnection.PrinterSettings.EFeedRate(0), 0, moveButtonFactory);
ExtrudeButton ePlusControl = CreateExtrudeButton(printer, "E+", printer.Settings.EFeedRate(0), 0, moveButtonFactory);
ePlusControl.Margin = extrusionMargin;
ePlusControl.ToolTipText = "Extrude filament".Localize();
ePlusButtonAndText.AddChild(ePlusControl);
@ -470,7 +470,7 @@ namespace MatterHackers.MatterControl
{
for (int i = 0; i < extruderCount; i++)
{
ExtrudeButton ePlusControl = CreateExtrudeButton(printerConnection, $"E{i + 1}+", printerConnection.PrinterSettings.EFeedRate(0), i, moveButtonFactory);
ExtrudeButton ePlusControl = CreateExtrudeButton(printer, $"E{i + 1}+", printer.Settings.EFeedRate(0), i, moveButtonFactory);
ePlusControl.Margin = extrusionMargin;
ePlusControl.ToolTipText = "Extrude filament".Localize();
ePlusButtonAndText.AddChild(ePlusControl);
@ -529,9 +529,9 @@ namespace MatterHackers.MatterControl
return eButtons;
}
private static MoveButton CreateMoveButton(PrinterConnection printerConnection, string label, PrinterConnection.Axis axis, double moveSpeed, bool levelingButtons, MoveButtonFactory buttonFactory)
private static MoveButton CreateMoveButton(PrinterConfig printer, string label, PrinterConnection.Axis axis, double moveSpeed, bool levelingButtons, MoveButtonFactory buttonFactory)
{
var button = buttonFactory.GenerateMoveButton(printerConnection, label, axis, moveSpeed);
var button = buttonFactory.GenerateMoveButton(printer, label, axis, moveSpeed);
button.VAnchor = VAnchor.Absolute;
button.HAnchor = HAnchor.Absolute;
button.Height = (levelingButtons ? 45 : 40) * GuiWidget.DeviceScale;
@ -540,16 +540,16 @@ namespace MatterHackers.MatterControl
return button;
}
private static ExtrudeButton CreateExtrudeButton(PrinterConnection printerConnection, string label, double moveSpeed, int extruderNumber, MoveButtonFactory buttonFactory = null)
private static ExtrudeButton CreateExtrudeButton(PrinterConfig printer, string label, double moveSpeed, int extruderNumber, MoveButtonFactory buttonFactory = null)
{
var button = buttonFactory.GenerateExtrudeButton(printerConnection, label, moveSpeed, extruderNumber);
var button = buttonFactory.GenerateExtrudeButton(printer, label, moveSpeed, extruderNumber);
button.Height = 40 * GuiWidget.DeviceScale;
button.Width = 40 * GuiWidget.DeviceScale;
return button;
}
public static FlowLayoutWidget CreateZButtons(PrinterConnection printerConnection, RGBA_Bytes color, double buttonSeparationDistance,
public static FlowLayoutWidget CreateZButtons(PrinterConfig printer, RGBA_Bytes color, double buttonSeparationDistance,
out MoveButton zPlusControl, out MoveButton zMinusControl, bool levelingButtons = false)
{
FlowLayoutWidget zButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
@ -557,7 +557,7 @@ namespace MatterHackers.MatterControl
MoveButtonFactory moveButtonFactory = new MoveButtonFactory();
moveButtonFactory.Colors.Fill.Normal = color;
zPlusControl = CreateMoveButton(printerConnection, "Z+", PrinterConnection.Axis.Z, printerConnection.PrinterSettings.ZSpeed(), levelingButtons, moveButtonFactory);
zPlusControl = CreateMoveButton(printer, "Z+", PrinterConnection.Axis.Z, printer.Settings.ZSpeed(), levelingButtons, moveButtonFactory);
zPlusControl.Name = "Move Z positive".Localize();
zPlusControl.ToolTipText = "Move Z positive".Localize();
zButtons.AddChild(zPlusControl);
@ -567,7 +567,7 @@ namespace MatterHackers.MatterControl
spacer.BackgroundColor = XYZColors.zColor;
zButtons.AddChild(spacer);
zMinusControl = CreateMoveButton(printerConnection, "Z-", PrinterConnection.Axis.Z, printerConnection.PrinterSettings.ZSpeed(), levelingButtons, moveButtonFactory);
zMinusControl = CreateMoveButton(printer, "Z-", PrinterConnection.Axis.Z, printer.Settings.ZSpeed(), levelingButtons, moveButtonFactory);
zMinusControl.ToolTipText = "Move Z negative".Localize();
zButtons.AddChild(zMinusControl);
}
@ -585,7 +585,7 @@ namespace MatterHackers.MatterControl
xButtons.HAnchor |= Agg.UI.HAnchor.Center;
xButtons.VAnchor |= Agg.UI.VAnchor.Center;
xMinusControl = CreateMoveButton(printerConnection, "X-", PrinterConnection.Axis.X, printerConnection.PrinterSettings.XSpeed(), false, moveButtonFactory);
xMinusControl = CreateMoveButton(printer, "X-", PrinterConnection.Axis.X, printer.Settings.XSpeed(), false, moveButtonFactory);
xMinusControl.ToolTipText = "Move X negative".Localize();
xButtons.AddChild(xMinusControl);
@ -594,7 +594,7 @@ namespace MatterHackers.MatterControl
spacer.BackgroundColor = XYZColors.xColor;
xButtons.AddChild(spacer);
xPlusControl = CreateMoveButton(printerConnection, "X+", PrinterConnection.Axis.X, printerConnection.PrinterSettings.XSpeed(), false, moveButtonFactory);
xPlusControl = CreateMoveButton(printer, "X+", PrinterConnection.Axis.X, printer.Settings.XSpeed(), false, moveButtonFactory);
xPlusControl.ToolTipText = "Move X positive".Localize();
xButtons.AddChild(xPlusControl);
}
@ -605,7 +605,7 @@ namespace MatterHackers.MatterControl
moveButtonFactory.Colors.Fill.Normal = XYZColors.yColor;
yButtons.HAnchor |= Agg.UI.HAnchor.Center;
yButtons.VAnchor |= Agg.UI.VAnchor.Center;
yPlusControl = CreateMoveButton(printerConnection, "Y+", PrinterConnection.Axis.Y, printerConnection.PrinterSettings.YSpeed(), false, moveButtonFactory);
yPlusControl = CreateMoveButton(printer, "Y+", PrinterConnection.Axis.Y, printer.Settings.YSpeed(), false, moveButtonFactory);
yPlusControl.ToolTipText = "Move Y positive".Localize();
yButtons.AddChild(yPlusControl);
@ -614,7 +614,7 @@ namespace MatterHackers.MatterControl
spacer.BackgroundColor = XYZColors.yColor;
yButtons.AddChild(spacer);
yMinusControl = CreateMoveButton(printerConnection, "Y-", PrinterConnection.Axis.Y, printerConnection.PrinterSettings.YSpeed(), false, moveButtonFactory);
yMinusControl = CreateMoveButton(printer, "Y-", PrinterConnection.Axis.Y, printer.Settings.YSpeed(), false, moveButtonFactory);
yMinusControl.ToolTipText = "Move Y negative".Localize();
yButtons.AddChild(yMinusControl);
}
@ -635,12 +635,12 @@ namespace MatterHackers.MatterControl
public double MoveAmount = 10;
private double movementFeedRate;
PrinterConnection printerConnection;
private PrinterConfig printer;
public MoveButton(PrinterConnection printerConnection, double x, double y, GuiWidget buttonView, PrinterConnection.Axis axis, double movementFeedRate)
public MoveButton(PrinterConfig printer, double x, double y, GuiWidget buttonView, PrinterConnection.Axis axis, double movementFeedRate)
: base(x, y, buttonView)
{
this.printerConnection = printerConnection;
this.printer = printer;
this.moveAxis = axis;
this.movementFeedRate = movementFeedRate;
@ -648,7 +648,7 @@ namespace MatterHackers.MatterControl
{
MoveButton moveButton = (MoveButton)s;
if (printerConnection.CommunicationState == CommunicationStates.Printing)
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
if (moveAxis == PrinterConnection.Axis.Z) // only works on z
{
@ -659,7 +659,7 @@ namespace MatterHackers.MatterControl
}
else
{
printerConnection.MoveRelative(this.moveAxis, this.MoveAmount, movementFeedRate);
printer.Connection.MoveRelative(this.moveAxis, this.MoveAmount, movementFeedRate);
}
};
}
@ -672,12 +672,13 @@ namespace MatterHackers.MatterControl
private double movementFeedRate;
public int ExtruderNumber;
PrinterConnection printerConnection;
public ExtrudeButton(PrinterConnection printerConnection, double x, double y, GuiWidget buttonView, double movementFeedRate, int extruderNumber)
private PrinterConfig printer;
public ExtrudeButton(PrinterConfig printer, double x, double y, GuiWidget buttonView, double movementFeedRate, int extruderNumber)
: base(x, y, buttonView)
{
this.printerConnection = printerConnection;
this.printer = printer;
this.ExtruderNumber = extruderNumber;
this.movementFeedRate = movementFeedRate;
}
@ -687,7 +688,7 @@ namespace MatterHackers.MatterControl
base.OnClick(mouseEvent);
//Add more fancy movement here
printerConnection.MoveExtruderRelative(MoveAmount, movementFeedRate, ExtruderNumber);
printer.Connection.MoveExtruderRelative(MoveAmount, movementFeedRate, ExtruderNumber);
}
}
@ -780,20 +781,20 @@ namespace MatterHackers.MatterControl
public double BorderWidth { get; set; } = 1;
public MoveButton GenerateMoveButton(PrinterConnection printerConnection, string label, PrinterConnection.Axis axis, double movementFeedRate)
public MoveButton GenerateMoveButton(PrinterConfig printer, string label, PrinterConnection.Axis axis, double movementFeedRate)
{
//Create button based on view container widget
return new MoveButton(printerConnection, 0, 0, GetButtonView(label), axis, movementFeedRate)
return new MoveButton(printer, 0, 0, GetButtonView(label), axis, movementFeedRate)
{
Margin = 0,
Padding = 0
};
}
public ExtrudeButton GenerateExtrudeButton(PrinterConnection printerConnection, string label, double movementFeedRate, int extruderNumber)
public ExtrudeButton GenerateExtrudeButton(PrinterConfig printer, string label, double movementFeedRate, int extruderNumber)
{
//Create button based on view container widget
return new ExtrudeButton(printerConnection, 0, 0, GetButtonView(label), movementFeedRate, extruderNumber)
return new ExtrudeButton(printer, 0, 0, GetButtonView(label), movementFeedRate, extruderNumber)
{
Margin = 0,
Padding = 0

View file

@ -148,7 +148,7 @@ namespace MatterHackers.MatterControl
internal void ChangeToSetupBaudOrComPortOne()
{
if (string.IsNullOrEmpty(PrinterConnection.Instance?.PrinterSettings?.GetValue(SettingsKey.baud_rate)))
if (string.IsNullOrEmpty(ActiveSliceSettings.Instance?.GetValue(SettingsKey.baud_rate)))
{
ChangeToPage<SetupStepBaudRate>();
}

@ -1 +1 @@
Subproject commit 0119b456404a53765223ce946b8f8d7d5200d7a6
Subproject commit f007a6c79cc5899f72070f39a341ebd0ea655ac9

View file

@ -32,6 +32,7 @@ using System.Diagnostics;
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
using MatterHackers.GCodeVisualizer;
using MatterHackers.MatterControl;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterCommunication.Io;
using MatterHackers.MatterControl.SlicerConfiguration;
@ -95,15 +96,15 @@ namespace MatterControl.Tests.MatterControl
public static GCodeStream CreateTestGCodeStream(string[] inputLines, out List<GCodeStream> streamList)
{
var printerConnection = PrinterConnection.Instance;
var printer = ApplicationController.Instance.Printer;
streamList = new List<GCodeStream>();
streamList.Add(new TestGCodeStream(inputLines));
streamList.Add(new PauseHandlingStream(printerConnection, streamList[streamList.Count - 1]));
streamList.Add(new PauseHandlingStream(printer, streamList[streamList.Count - 1]));
streamList.Add(new QueuedCommandsStream(streamList[streamList.Count - 1]));
streamList.Add(new RelativeToAbsoluteStream(streamList[streamList.Count - 1]));
streamList.Add(new WaitForTempStream(printerConnection, streamList[streamList.Count - 1]));
streamList.Add(new BabyStepsStream(printerConnection.PrinterSettings, streamList[streamList.Count - 1]));
streamList.Add(new WaitForTempStream(printer.Connection, streamList[streamList.Count - 1]));
streamList.Add(new BabyStepsStream(printer.Settings, streamList[streamList.Count - 1]));
streamList.Add(new ExtrusionMultiplyerStream(streamList[streamList.Count - 1]));
streamList.Add(new FeedRateMultiplyerStream(streamList[streamList.Count - 1]));
GCodeStream totalGCodeStream = streamList[streamList.Count - 1];