More making printerConnection passed to classes.

This commit is contained in:
Lars Brubaker 2017-09-03 11:48:08 -07:00
parent a0e77afa66
commit 3dd9270797
34 changed files with 151 additions and 351 deletions

View file

@ -62,22 +62,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return result;
}
public void Run()
public void Run(PrinterConnection printerConnection)
{
if (PrinterConnection.Instance.PrinterIsConnected)
if (printerConnection.PrinterIsConnected)
{
PrinterConnection.Instance.MacroStart();
SendCommandToPrinter(GCode);
printerConnection.MacroStart();
SendCommandToPrinter(printerConnection, GCode);
if (GCode.Contains(MacroProcessingStream.MacroPrefix))
{
SendCommandToPrinter("\n" + MacroProcessingStream.MacroPrefix + "close()");
SendCommandToPrinter(printerConnection, "\n" + MacroProcessingStream.MacroPrefix + "close()");
}
}
}
protected void SendCommandToPrinter(string command)
protected void SendCommandToPrinter(PrinterConnection printerConnection, string command)
{
PrinterConnection.Instance.SendLineToPrinterNow(command);
printerConnection.SendLineToPrinterNow(command);
}
}
}

View file

@ -32,18 +32,21 @@ using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using System;
using System.Collections.Generic;
using MatterHackers.MatterControl.PrinterCommunication;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class SettingsControlBar : FlowLayoutWidget
{
public SettingsControlBar()
PrinterConnection printerConnection;
public SettingsControlBar(PrinterConnection printerConnection)
{
this.printerConnection = printerConnection;
this.HAnchor = HAnchor.Stretch;
int numberOfHeatedExtruders = ActiveSliceSettings.Instance.Helpers.NumberOfHotEnds();
this.AddChild(new PresetSelectorWidget("Quality".Localize(), RGBA_Bytes.Yellow, NamedSettingsLayers.Quality, 0));
this.AddChild(new PresetSelectorWidget(printerConnection, "Quality".Localize(), RGBA_Bytes.Yellow, NamedSettingsLayers.Quality, 0));
this.AddChild(new GuiWidget(8, 0));
if (numberOfHeatedExtruders > 1)
@ -58,12 +61,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
int colorIndex = i % colorList.Count;
RGBA_Bytes color = colorList[colorIndex];
this.AddChild(new PresetSelectorWidget(string.Format("{0} {1}", "Material".Localize(), i + 1), color, NamedSettingsLayers.Material, i));
this.AddChild(new PresetSelectorWidget(printerConnection, string.Format("{0} {1}", "Material".Localize(), i + 1), color, NamedSettingsLayers.Material, i));
}
}
else
{
this.AddChild(new PresetSelectorWidget("Material".Localize(), RGBA_Bytes.Orange, NamedSettingsLayers.Material, 0));
this.AddChild(new PresetSelectorWidget(printerConnection, "Material".Localize(), RGBA_Bytes.Orange, NamedSettingsLayers.Material, 0));
}
this.Height = 60 * GuiWidget.DeviceScale;

View file

@ -36,6 +36,7 @@ using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.SlicerConfiguration
@ -48,10 +49,12 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
GuiWidget pullDownContainer;
private int extruderIndex; //For multiple materials
PrinterConnection printerConnection;
public PresetSelectorWidget(string label, RGBA_Bytes accentColor, NamedSettingsLayers layerType, int extruderIndex)
public PresetSelectorWidget(PrinterConnection printerConnection, string label, RGBA_Bytes accentColor, NamedSettingsLayers layerType, int extruderIndex)
: base(FlowDirection.TopToBottom)
{
this.printerConnection = printerConnection;
Name = label;
ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
@ -152,7 +155,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
};
ApplicationController.Instance.EditMaterialPresetsWindow = new SlicePresetsWindow(presetsContext);
ApplicationController.Instance.EditMaterialPresetsWindow = new SlicePresetsWindow(printerConnection, presetsContext);
ApplicationController.Instance.EditMaterialPresetsWindow.Closed += (s, e2) =>
{
ApplicationController.Instance.EditMaterialPresetsWindow = null;
@ -192,7 +195,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
};
ApplicationController.Instance.EditQualityPresetsWindow = new SlicePresetsWindow(presetsContext);
ApplicationController.Instance.EditQualityPresetsWindow = new SlicePresetsWindow(printerConnection, presetsContext);
ApplicationController.Instance.EditQualityPresetsWindow.Closed += (s, e2) =>
{
ApplicationController.Instance.EditQualityPresetsWindow = null;

View file

@ -39,6 +39,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using MatterHackers.MatterControl.PrinterCommunication;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
@ -68,8 +69,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private string initialPresetName = null;
private GuiWidget middleRow;
PrinterConnection printerConnection;
public SlicePresetsWindow(PresetsContext presetsContext)
public SlicePresetsWindow(PrinterConnection printerConnection, PresetsContext presetsContext)
: base(641, 481)
{
this.presetsContext = presetsContext;
@ -149,7 +151,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
ActiveSliceSettings.Instance.BaseLayer
};
return new SliceSettingsWidget(layerCascade, presetsContext.LayerType)
return new SliceSettingsWidget(printerConnection, layerCascade, presetsContext.LayerType)
{
ShowControlBar = false
};

View file

@ -79,13 +79,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private NamedSettingsLayers viewFilter;
private bool isPrimarySettingsView { get; set; }
PrinterConnection printerConnection;
static SliceSettingsWidget()
{
}
public SliceSettingsWidget(List<PrinterSettingsLayer> layerCascade = null, NamedSettingsLayers viewFilter = NamedSettingsLayers.All)
public SliceSettingsWidget(PrinterConnection printerConnection, List<PrinterSettingsLayer> layerCascade = null, NamedSettingsLayers viewFilter = NamedSettingsLayers.All)
{
this.printerConnection = printerConnection;
// When editing presets, LayerCascade contains a filtered list of settings layers. If the list is null we're in the primarySettingsView
isPrimarySettingsView = layerCascade == null;
@ -105,7 +107,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
pageTopToBottomLayout.Padding = new BorderDouble(3, 0);
this.AddChild(pageTopToBottomLayout);
settingsControlBar = new SettingsControlBar()
settingsControlBar = new SettingsControlBar(printerConnection)
{
HAnchor = HAnchor.Stretch,
Padding = new BorderDouble(8, 12, 8, 8)
@ -121,8 +123,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
TextColor = ActiveTheme.Instance.PrimaryTextColor,
HAnchor = HAnchor.Stretch
};
PrinterConnection.Instance.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
PrinterConnection.Instance.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
printerConnection.CommunicationStateChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
printerConnection.EnableChanged.RegisterEvent(onPrinterStatusChanged, ref unregisterEvents);
RebuildSliceSettingsTabs();
@ -409,6 +411,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
addedSettingToSubGroup = true;
topToBottomSettings.AddChild(
CreateSettingInfoUIControls(
printerConnection,
settingData,
layerCascade,
persistenceLayer,
@ -573,6 +576,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (EngineMappingsMatterSlice.Instance.MapContains(settingData.SlicerConfigName))
{
GuiWidget controlsForThisSetting = CreateSettingInfoUIControls(
printerConnection,
settingData,
layerCascade,
persistenceLayer,
@ -741,9 +745,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return dataArea;
}
public static GuiWidget CreateSettingControl(string sliceSettingsKey, ref int tabIndex)
public static GuiWidget CreateSettingControl(PrinterConnection printerConnection, string sliceSettingsKey, ref int tabIndex)
{
return CreateSettingInfoUIControls(
printerConnection,
SliceSettingsOrganizer.Instance.GetSettingsData(sliceSettingsKey),
null,
ActiveSliceSettings.Instance.UserLayer,
@ -753,6 +758,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
private static GuiWidget CreateSettingInfoUIControls(
PrinterConnection printerConnection,
SliceSettingData settingData,
List<PrinterSettingsLayer> layerCascade,
PrinterSettingsLayer persistenceLayer,
@ -1235,7 +1241,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
EventHandler localUnregisterEvents = null;
bool canChangeComPort = !PrinterConnection.Instance.PrinterIsConnected && PrinterConnection.Instance.CommunicationState != CommunicationStates.AttemptingToConnect;
bool canChangeComPort = !printerConnection.PrinterIsConnected && printerConnection.CommunicationState != CommunicationStates.AttemptingToConnect;
// The COM_PORT control is unique in its approach to the SlicerConfigName. It uses "com_port" settings name to
// bind to a context that will place it in the SliceSetting view but it binds its values to a machine
// specific dictionary key that is not exposed in the UI. At runtime we lookup and store to '<machinename>_com_port'
@ -1267,9 +1273,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
};
// Prevent droplist interaction when connected
PrinterConnection.Instance.CommunicationStateChanged.RegisterEvent((s, e) =>
printerConnection.CommunicationStateChanged.RegisterEvent((s, e) =>
{
canChangeComPort = !PrinterConnection.Instance.PrinterIsConnected && PrinterConnection.Instance.CommunicationState != CommunicationStates.AttemptingToConnect;
canChangeComPort = !printerConnection.PrinterIsConnected && printerConnection.CommunicationState != CommunicationStates.AttemptingToConnect;
selectableOptions.Enabled = canChangeComPort;
selectableOptions.TextColor = canChangeComPort ? ActiveTheme.Instance.PrimaryTextColor : new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 150);
selectableOptions.BorderColor = canChangeComPort ? ActiveTheme.Instance.SecondaryTextColor : new RGBA_Bytes(ActiveTheme.Instance.SecondaryTextColor, 150);