Convert ActiveSliceSettings usage from static to local references

This commit is contained in:
John Lewin 2017-09-17 01:11:18 -07:00
parent e926b747cf
commit 294df0a588
27 changed files with 205 additions and 197 deletions

View file

@ -295,7 +295,7 @@ namespace MatterHackers.MatterControl.ActionBar
container.AddChild(graph);
// put in the material selector
var presetsSelector = new PresetSelectorWidget(string.Format($"{"Material".Localize()} {hotendIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, hotendIndex, true)
var presetsSelector = new PresetSelectorWidget(printer, string.Format($"{"Material".Localize()} {hotendIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, hotendIndex, true)
{
Margin = 0,
BackgroundColor = RGBA_Bytes.Transparent,

View file

@ -54,7 +54,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
: base(printer, pageDescription, instructionsText)
{
int extruderIndex = 0;
var materialSelector = new PresetSelectorWidget(string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, extruderIndex);
var materialSelector = new PresetSelectorWidget(printer, string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, extruderIndex);
materialSelector.BackgroundColor = RGBA_Bytes.Transparent;
materialSelector.Margin = new BorderDouble(0, 0, 0, 15);
topToBottomControls.AddChild(materialSelector);

View file

@ -48,37 +48,37 @@ namespace MatterHackers.MatterControl.PrinterControls
private TextWidget progressBarText;
private long timeToWaitMs;
PrinterConnection printerConnection;
private PrinterConfig printer;
public RunningMacroPage(PrinterConnection printerConnection, MacroCommandData macroData)
public RunningMacroPage(PrinterConfig printer, MacroCommandData macroData)
: base("Cancel")
{
this.printerConnection = printerConnection;
this.printer = printer;
this.WindowTitle = "Running Macro".Localize();
this.HeaderText = macroData.title;
cancelButton.Click += (s, e) =>
{
printerConnection.MacroCancel();
printer.Connection.MacroCancel();
};
if (macroData.showMaterialSelector)
{
int extruderIndex = 0;
var materialSelector = new PresetSelectorWidget(string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, extruderIndex);
var materialSelector = new PresetSelectorWidget(printer, string.Format($"{"Material".Localize()} {extruderIndex + 1}"), RGBA_Bytes.Transparent, NamedSettingsLayers.Material, extruderIndex);
materialSelector.BackgroundColor = RGBA_Bytes.Transparent;
materialSelector.Margin = new BorderDouble(0, 0, 0, 15);
contentRow.AddChild(materialSelector);
}
printerConnection.WroteLine.RegisterEvent(LookForTempRequest, ref unregisterEvents);
printer.Connection.WroteLine.RegisterEvent(LookForTempRequest, ref unregisterEvents);
if (macroData.waitOk | macroData.expireTime > 0)
{
Button okButton = textImageButtonFactory.Generate("Continue".Localize());
okButton.Click += (s, e) =>
{
printerConnection.MacroContinue();
printer.Connection.MacroContinue();
UiThread.RunOnIdle(() => WizardWindow?.Close());
};
@ -139,7 +139,7 @@ namespace MatterHackers.MatterControl.PrinterControls
{
if(e.OsEvent)
{
printerConnection.MacroCancel();
printer.Connection.MacroCancel();
}
unregisterEvents?.Invoke(this, null);
@ -166,7 +166,7 @@ namespace MatterHackers.MatterControl.PrinterControls
if(stringEvent != null
&& stringEvent.Data.Contains("M104"))
{
startingTemp = printerConnection.GetActualHotendTemperature(0);
startingTemp = printer.Connection.GetActualHotendTemperature(0);
UiThread.RunOnIdle(ShowTempChangeProgress);
}
}
@ -174,8 +174,8 @@ namespace MatterHackers.MatterControl.PrinterControls
private void ShowTempChangeProgress()
{
progressBar.Visible = true;
double targetTemp = printerConnection.GetTargetHotendTemperature(0);
double actualTemp = printerConnection.GetActualHotendTemperature(0);
double targetTemp = printer.Connection.GetTargetHotendTemperature(0);
double actualTemp = printer.Connection.GetActualHotendTemperature(0);
double totalDelta = targetTemp - startingTemp;
double currentDelta = actualTemp - startingTemp;
double ratioDone = totalDelta != 0 ? (currentDelta / totalDelta) : 1;

View file

@ -69,7 +69,6 @@ namespace MatterHackers.MatterControl
var commonMargin = new BorderDouble(4, 2);
bool isFirstItem = true;
// GCode export
bool showExportGCodeButton = ActiveSliceSettings.Instance.PrinterSelected;

View file

@ -36,8 +36,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
private GCodeFile loadedGCode;
public GCodeDetails(GCodeFile loadedGCode)
private PrinterConfig printer;
public GCodeDetails(PrinterConfig printer, GCodeFile loadedGCode)
{
this.printer = printer;
this.loadedGCode = loadedGCode;
}
@ -67,9 +69,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
public string FilamentUsed => string.Format("{0:0.0} mm", loadedGCode.GetFilamentUsedMm(ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.filament_diameter)));
public string FilamentUsed => string.Format("{0:0.0} mm", loadedGCode.GetFilamentUsedMm(printer.Settings.GetValue<double>(SettingsKey.filament_diameter)));
public string FilamentVolume => string.Format("{0:0.00} cm³", loadedGCode.GetFilamentCubicMm(ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.filament_diameter)) / 1000);
public string FilamentVolume => string.Format("{0:0.00} cm³", loadedGCode.GetFilamentCubicMm(printer.Settings.GetValue<double>(SettingsKey.filament_diameter)) / 1000);
public string EstimatedMass => this.TotalMass <= 0 ? "Unknown" : string.Format("{0:0.00} g", this.TotalMass);
@ -79,8 +81,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
get
{
double filamentDiameter = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.filament_diameter);
double filamentDensity = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.filament_density);
double filamentDiameter = printer.Settings.GetValue<double>(SettingsKey.filament_diameter);
double filamentDensity = printer.Settings.GetValue<double>(SettingsKey.filament_density);
return loadedGCode.GetFilamentWeightGrams(filamentDiameter, filamentDensity);
}
@ -90,7 +92,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
get
{
double filamentCost = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.filament_cost);
double filamentCost = printer.Settings.GetValue<double>(SettingsKey.filament_cost);
return this.TotalMass / 1000 * filamentCost;
}
}

View file

@ -52,15 +52,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.AnchorAll();
var activeSettings = ActiveSliceSettings.Instance;
var tabControl = ApplicationController.Instance.Theme.CreateTabControl(2);
var separator = tabControl.Children<HorizontalLine>().FirstOrDefault();
separator.BackgroundColor = ApplicationController.Instance.Theme.PrimaryTabFillColor;
string tabTitle = !activeSettings.PrinterSelected ? "Printer".Localize() : activeSettings.GetValue(SettingsKey.printer_name);
RGBA_Bytes selectedTabColor;
if (!UserSettings.Instance.IsTouchScreen)
{
@ -76,6 +72,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// Add a tab for the current printer
if (ActiveSliceSettings.Instance.PrinterSelected)
{
string tabTitle = ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name);
printerTab = CreatePrinterTab(printerConfig, theme, tabTitle);
tabControl.AddTab(printerTab);
}

View file

@ -160,7 +160,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
var partTab = new MainTab(
"New Part",
"newPart" + tabControl.TabCount,
new PrinterTabBase(sceneContext, theme, "xxxxx"),
new PrinterTabBase(null, sceneContext, theme, "xxxxx"),
"https://i.imgur.com/nkeYgfU.png");
theme.SetPrinterTabStyles(partTab);

View file

@ -30,8 +30,6 @@ either expressed or implied, of the FreeBSD Project.
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath;
@ -50,7 +48,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
protected FlowLayoutWidget topToBottom;
protected FlowLayoutWidget leftToRight;
public PrinterTabBase(BedConfig sceneContext, ThemeConfig theme, string tabTitle)
public PrinterTabBase(PrinterConfig printer, BedConfig sceneContext, ThemeConfig theme, string tabTitle)
: base (tabTitle)
{
this.sceneContext = sceneContext;
@ -82,6 +80,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// The 3D model view
modelViewer = new View3DWidget(
printer,
sceneContext,
View3DWidget.AutoRotate.Disabled,
viewControls3D,

View file

@ -58,7 +58,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private PrinterConfig printer;
public PrinterTabPage(PrinterConfig printer, ThemeConfig theme, string tabTitle)
: base(printer.Bed, theme, tabTitle)
: base(printer, printer.Bed, theme, tabTitle)
{
this.printer = printer;
modelViewer.meshViewerWidget.EditorMode = MeshViewerWidget.EditorType.Printer;
@ -147,7 +147,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.Invalidate();
};
currentLayerInfo = new ValueDisplayInfo("1000")
{
GetDisplayString = (value) => $"{value + 1}"
@ -355,6 +355,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
// TODO: Moved from View3DWidget as printer specialized logic can't be in the generic base. Consider moving to model
private bool PartsAreInPrintVolume()
{
AxisAlignedBoundingBox allBounds = AxisAlignedBoundingBox.Empty;
foreach (var aabb in printer.Bed.Scene.Children.Select(item => item.GetAxisAlignedBoundingBox(Matrix4X4.Identity)))
{
allBounds += aabb;
}
bool onBed = allBounds.minXYZ.z > -.001 && allBounds.minXYZ.z < .001; // really close to the bed
RectangleDouble bedRect = new RectangleDouble(0, 0, printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).x, printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).y);
bedRect.Offset(printer.Settings.GetValue<Vector2>(SettingsKey.print_center) - printer.Settings.GetValue<Vector2>(SettingsKey.bed_size) / 2);
bool inBounds = bedRect.Contains(new Vector2(allBounds.minXYZ)) && bedRect.Contains(new Vector2(allBounds.maxXYZ));
return onBed && inBounds;
}
private void SetSliderSizes()
{
if (selectLayerSlider == null || modelViewer == null)
@ -597,7 +615,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
sideBar.AddPage(
"Slice Settings".Localize(),
new SliceSettingsWidget(
printer,
new SettingsContext(
printer,
null,
SlicerConfiguration.NamedSettingsLayers.All)));
}

View file

@ -130,7 +130,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
printerTabPage.ViewMode = PartViewMode.Layers3D;
// HACK: directly fire method which previously ran on SlicingDone event on PrintItemWrapper
UiThread.RunOnIdle(printerTabPage.modelViewer.gcodeViewer.CreateAndAddChildren);
UiThread.RunOnIdle(() => printerTabPage.modelViewer.gcodeViewer.CreateAndAddChildren(printer));
}
catch (Exception ex)
{

View file

@ -135,7 +135,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private BedConfig sceneContext;
public View3DWidget(BedConfig sceneContext, AutoRotate autoRotate, ViewControls3D viewControls3D, ThemeConfig theme, OpenMode openMode = OpenMode.Viewing, MeshViewerWidget.EditorType editorType = MeshViewerWidget.EditorType.Part)
public View3DWidget(PrinterConfig printer, BedConfig sceneContext, AutoRotate autoRotate, ViewControls3D viewControls3D, ThemeConfig theme, OpenMode openMode = OpenMode.Viewing, MeshViewerWidget.EditorType editorType = MeshViewerWidget.EditorType.Part)
{
var smallMarginButtonFactory = theme.SmallMarginButtonFactory;
@ -177,7 +177,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
this.InteractionLayer.AddChild(meshViewerWidget);
// The slice layers view
gcodeViewer = new ViewGcodeBasic(sceneContext, viewControls3D);
gcodeViewer = new ViewGcodeBasic(printer, sceneContext, viewControls3D);
gcodeViewer.AnchorAll();
gcodeViewer.Visible = false;
this.InteractionLayer.AddChild(gcodeViewer);
@ -2283,23 +2283,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
private bool PartsAreInPrintVolume()
{
AxisAlignedBoundingBox allBounds = AxisAlignedBoundingBox.Empty;
foreach (var aabb in Scene.Children.Select(item => item.GetAxisAlignedBoundingBox(Matrix4X4.Identity)))
{
allBounds += aabb;
}
bool onBed = allBounds.minXYZ.z > -.001 && allBounds.minXYZ.z < .001; // really close to the bed
RectangleDouble bedRect = new RectangleDouble(0, 0, ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.bed_size).x, ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.bed_size).y);
bedRect.Offset(ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.print_center) - ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.bed_size) / 2);
bool inBounds = bedRect.Contains(new Vector2(allBounds.minXYZ)) && bedRect.Contains(new Vector2(allBounds.maxXYZ));
return onBed && inBounds;
}
private void OpenExportWindow()
{
var exportPage = new ExportPrintItemPage(new[] { new FileSystemFileItem(sceneContext.printItem.FileLocation) });
@ -2452,8 +2435,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}));
double buildHeight = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.build_height);
if (buildHeight > 0)
if (sceneContext.BuildHeight > 0)
{
popupContainer.AddChild(
this.theme.CreateCheckboxMenuItem(
@ -2469,7 +2451,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}));
}
popupContainer.AddChild(new HorizontalLine());
var renderOptions = CreateRenderTypeRadioButtons();

View file

@ -53,15 +53,17 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private string fileTooBigToLoad = "GCode file too big to preview ({0}).".Localize();
private BedConfig sceneContext;
private PrinterConfig printer;
private ViewControls3D viewControls3D;
public ViewGcodeBasic(BedConfig sceneContext, ViewControls3D viewControls3D)
public ViewGcodeBasic(PrinterConfig printer, BedConfig sceneContext, ViewControls3D viewControls3D)
{
this.printer = printer;
this.sceneContext = sceneContext;
this.viewControls3D = viewControls3D;
CreateAndAddChildren();
CreateAndAddChildren(printer);
ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
{
@ -69,16 +71,16 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
if (stringEvent.Data == "extruder_offset")
{
sceneContext.GCodeRenderer?.Clear3DGCode();
printer.Bed.GCodeRenderer?.Clear3DGCode();
}
}
}, ref unregisterEvents);
// TODO: Why do we clear GCode on AdvancedControlsPanelReloading - assume some slice settings should invalidate. If so, code should be more specific and bound to slice settings changed
ApplicationController.Instance.AdvancedControlsPanelReloading.RegisterEvent((s, e) => sceneContext.GCodeRenderer?.Clear3DGCode(), ref unregisterEvents);
ApplicationController.Instance.AdvancedControlsPanelReloading.RegisterEvent((s, e) => printer.Bed.GCodeRenderer?.Clear3DGCode(), ref unregisterEvents);
}
internal void CreateAndAddChildren()
internal void CreateAndAddChildren(PrinterConfig printer)
{
CloseAllChildren();
@ -123,7 +125,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
AddChild(gradientWidget);
var gcodeDetails = new GCodeDetails(sceneContext.LoadedGCode);
var gcodeDetails = new GCodeDetails(printer, printer.Bed.LoadedGCode);
this.AddChild(new GCodeDetailsView(gcodeDetails)
{

View file

@ -207,7 +207,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
UiThread.RunOnIdle(() =>
{
WizardWindow.Show(new RunningMacroPage(printer.Connection, macroData));
WizardWindow.Show(new RunningMacroPage(printer, macroData));
});
break;
@ -225,7 +225,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
UiThread.RunOnIdle(() =>
{
WizardWindow.Show(new RunningMacroPage(printer.Connection, macroData));
WizardWindow.Show(new RunningMacroPage(printer, macroData));
});
break;

View file

@ -52,7 +52,7 @@ namespace MatterHackers.MatterControl.PrinterControls
private EventHandler unregisterEvents;
public AdjustmentControls(int headingPointSize)
public AdjustmentControls(PrinterConfig printer, int headingPointSize)
{
var adjustmentControlsGroupBox = new AltGroupBox(new TextWidget("Tuning Adjustment".Localize(), pointSize: headingPointSize, textColor: ActiveTheme.Instance.SecondaryAccentColor))
{
@ -113,7 +113,7 @@ namespace MatterHackers.MatterControl.PrinterControls
FeedRateMultiplyerStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
// Persist data for future use
ActiveSliceSettings.Instance.SetValue(
printer.Settings.SetValue(
SettingsKey.feedrate_ratio,
FeedRateMultiplyerStream.FeedRateRatio.ToString());
};
@ -135,7 +135,7 @@ namespace MatterHackers.MatterControl.PrinterControls
FeedRateMultiplyerStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
// Persist data for future use
ActiveSliceSettings.Instance.SetValue(
printer.Settings.SetValue(
SettingsKey.feedrate_ratio,
FeedRateMultiplyerStream.FeedRateRatio.ToString());
};
@ -179,7 +179,7 @@ namespace MatterHackers.MatterControl.PrinterControls
ExtrusionMultiplyerStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
// Persist data for future use
ActiveSliceSettings.Instance.SetValue(
printer.Settings.SetValue(
SettingsKey.extrusion_ratio,
ExtrusionMultiplyerStream.ExtrusionRatio.ToString());
};
@ -200,7 +200,7 @@ namespace MatterHackers.MatterControl.PrinterControls
ExtrusionMultiplyerStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
// Persist data for future use
ActiveSliceSettings.Instance.SetValue(
printer.Settings.SetValue(
SettingsKey.extrusion_ratio,
ExtrusionMultiplyerStream.ExtrusionRatio.ToString());
};
@ -219,13 +219,13 @@ namespace MatterHackers.MatterControl.PrinterControls
var eventArgs = e as StringEventArgs;
if (eventArgs?.Data == SettingsKey.extrusion_ratio)
{
double extrusionRatio = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.extrusion_ratio);
double extrusionRatio = printer.Settings.GetValue<double>(SettingsKey.extrusion_ratio);
extrusionRatioSlider.Value = extrusionRatio;
extrusionValue.ActuallNumberEdit.Value = Math.Round(extrusionRatio, 2);
}
else if (eventArgs?.Data == SettingsKey.feedrate_ratio)
{
double feedrateRatio = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.feedrate_ratio);
double feedrateRatio = printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio);
feedRateRatioSlider.Value = feedrateRatio;
feedRateValue.ActuallNumberEdit.Value = Math.Round(feedrateRatio, 2);
}

View file

@ -27,36 +27,35 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
using System;
namespace MatterHackers.MatterControl.PrinterControls
{
public class PowerControls : ControlWidgetBase
{
private EventHandler unregisterEvents;
private CheckBox atxPowertoggleSwitch;
PrinterConnection printerConnection;
private PrinterConfig printer;
public PowerControls(PrinterConnection printerConnection, int headingPointSize)
public PowerControls(PrinterConfig printer, int headingPointSize)
{
this.printerConnection = printerConnection;
AltGroupBox fanControlsGroupBox = new AltGroupBox(new TextWidget("ATX Power Control".Localize(), pointSize: headingPointSize, textColor: ActiveTheme.Instance.SecondaryAccentColor));
this.printer = printer;
var fanControlsGroupBox = new AltGroupBox(new TextWidget("ATX Power Control".Localize(), pointSize: headingPointSize, textColor: ActiveTheme.Instance.SecondaryAccentColor));
fanControlsGroupBox.Margin = new BorderDouble(0);
fanControlsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
fanControlsGroupBox.HAnchor |= Agg.UI.HAnchor.Stretch;
fanControlsGroupBox.HAnchor |= HAnchor.Stretch;
this.AddChild(fanControlsGroupBox);
atxPowertoggleSwitch = ImageButtonFactory.CreateToggleSwitch(false);
atxPowertoggleSwitch.Margin = new BorderDouble(6, 0, 6, 6);
atxPowertoggleSwitch.CheckedStateChanged += (sender, e) =>
{
printerConnection.AtxPowerEnabled = atxPowertoggleSwitch.Checked;
printer.Connection.AtxPowerEnabled = atxPowertoggleSwitch.Checked;
};
FlowLayoutWidget paddingContainer = new FlowLayoutWidget();
@ -66,27 +65,25 @@ namespace MatterHackers.MatterControl.PrinterControls
}
fanControlsGroupBox.AddChild(paddingContainer);
UpdateControlVisibility(null, null);
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
{
this.Visible = printer.Settings.GetValue<bool>(SettingsKey.has_power_control);
this.SetEnableLevel(printer.Connection.PrinterIsConnected ? EnableLevel.Enabled : EnableLevel.Disabled);
}, ref unregisterEvents);
printerConnection.CommunicationStateChanged.RegisterEvent(this.UpdateControlVisibility, ref unregisterEvents);
printerConnection.AtxPowerStateChanged.RegisterEvent(this.UpdatePowerSwitch, ref unregisterEvents);
printer.Connection.AtxPowerStateChanged.RegisterEvent((s, e) =>
{
this.atxPowertoggleSwitch.Checked = printer.Connection.AtxPowerEnabled;
}, ref unregisterEvents);
this.HAnchor = Agg.UI.HAnchor.Stretch;
this.Visible = printer.Settings.GetValue<bool>(SettingsKey.has_power_control);
this.SetEnableLevel(printer.Connection.PrinterIsConnected ? EnableLevel.Enabled : EnableLevel.Disabled);
this.HAnchor = HAnchor.Stretch;
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Stretch;
}
private void UpdateControlVisibility(object sender, EventArgs args)
{
this.Visible = ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_power_control);
this.SetEnableLevel(printerConnection.PrinterIsConnected ? EnableLevel.Enabled : EnableLevel.Disabled);
}
private void UpdatePowerSwitch(object sender, EventArgs args)
{
this.atxPowertoggleSwitch.Checked = printerConnection.AtxPowerEnabled;
}
public override void OnClosed(ClosedEventArgs e)
{
unregisterEvents?.Invoke(this, null);

View file

@ -28,10 +28,8 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.PrinterCommunication;
@ -43,20 +41,21 @@ namespace MatterHackers.MatterControl
public class ManualPrinterControls : GuiWidget
{
static public RootedObjectEventHandler AddPluginControls = new RootedObjectEventHandler();
private static bool pluginsQueuedToAdd = false;
PrinterConfig printer;
private PrinterConfig printer;
public ManualPrinterControls(PrinterConfig printer)
{
this.printer = printer;
this.BackgroundColor = ApplicationController.Instance.Theme.TabBodyBackground;
AnchorAll();
AddChild(new ManualPrinterControlsDesktop(printer));
this.AnchorAll();
this.AddChild(new ManualPrinterControlsDesktop(printer));
}
public override void OnLoad(EventArgs args)
{
if (!pluginsQueuedToAdd && ActiveSliceSettings.Instance.GetValue("include_firmware_updater") == "Simple Arduino")
if (!pluginsQueuedToAdd && printer.Settings.GetValue("include_firmware_updater") == "Simple Arduino")
{
UiThread.RunOnIdle(() =>
{
@ -107,7 +106,7 @@ namespace MatterHackers.MatterControl
movementControlsContainer = new MovementControls(printer, headingPointSize);
controlsTopToBottomLayout.AddChild(movementControlsContainer);
if (!ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_hardware_leveling))
if (!printer.Settings.GetValue<bool>(SettingsKey.has_hardware_leveling))
{
calibrationControlsContainer = new CalibrationSettingsWidget(printer, theme.ButtonFactory, headingPointSize);
controlsTopToBottomLayout.AddChild(calibrationControlsContainer);
@ -123,15 +122,15 @@ namespace MatterHackers.MatterControl
controlsTopToBottomLayout.AddChild(linearPanel);
fanControlsContainer = new FanControls(printer.Connection, headingPointSize);
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_fan))
if (printer.Settings.GetValue<bool>(SettingsKey.has_fan))
{
controlsTopToBottomLayout.AddChild(fanControlsContainer);
}
#if !__ANDROID__
controlsTopToBottomLayout.AddChild(new PowerControls(printer.Connection, headingPointSize));
controlsTopToBottomLayout.AddChild(new PowerControls(printer, headingPointSize));
#endif
tuningAdjustmentControlsContainer = new AdjustmentControls(headingPointSize);
tuningAdjustmentControlsContainer = new AdjustmentControls(printer, headingPointSize);
controlsTopToBottomLayout.AddChild(tuningAdjustmentControlsContainer);
// HACK: this is a hack to make the layout engine fire again for this control
@ -157,7 +156,7 @@ namespace MatterHackers.MatterControl
private void SetVisibleControls()
{
if (!ActiveSliceSettings.Instance.PrinterSelected)
if (!printer.Settings.PrinterSelected)
{
movementControlsContainer?.SetEnableLevel(DisableableWidget.EnableLevel.Disabled);
fanControlsContainer?.SetEnableLevel(DisableableWidget.EnableLevel.Disabled);

View file

@ -58,7 +58,7 @@ namespace MatterHackers.MatterControl
private MoveButton zPlusControl;
private MoveButton zMinusControl;
private MoveButtonFactory moveButtonFactory = new MoveButtonFactory();
private PrinterConfig printer;
@ -378,9 +378,9 @@ namespace MatterHackers.MatterControl
{
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
var currentZ = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.baby_step_z_offset);
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += moveAmountPositive;
ActiveSliceSettings.Instance.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
}
else
{
@ -392,9 +392,9 @@ namespace MatterHackers.MatterControl
{
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
var currentZ = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.baby_step_z_offset);
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += moveAmountNegative;
ActiveSliceSettings.Instance.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
}
else
{
@ -405,7 +405,7 @@ namespace MatterHackers.MatterControl
private FlowLayoutWidget CreateEButtons(double buttonSeparationDistance)
{
int extruderCount = ActiveSliceSettings.Instance.GetValue<int>(SettingsKey.extruder_count);
int extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
FlowLayoutWidget eButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
{
@ -652,9 +652,9 @@ namespace MatterHackers.MatterControl
{
if (moveAxis == PrinterConnection.Axis.Z) // only works on z
{
var currentZ = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.baby_step_z_offset);
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += this.MoveAmount;
ActiveSliceSettings.Instance.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
}
}
else

View file

@ -49,12 +49,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
bool whiteBackground;
public DropDownList DropDownList;
private PrinterConfig printer;
private int extruderIndex; //For multiple materials
public PresetSelectorWidget(string label, RGBA_Bytes accentColor, NamedSettingsLayers layerType, int extruderIndex, bool whiteBackground = false)
public PresetSelectorWidget(PrinterConfig printer, string label, RGBA_Bytes accentColor, NamedSettingsLayers layerType, int extruderIndex, bool whiteBackground = false)
: base(FlowDirection.TopToBottom)
{
this.printer = printer;
this.whiteBackground = whiteBackground;
Name = label;
@ -122,24 +124,24 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
if (ApplicationController.Instance.EditMaterialPresetsWindow == null)
{
string presetsID = ActiveSliceSettings.Instance.GetMaterialPresetKey(extruderIndex);
string presetsID = printer.Settings.GetMaterialPresetKey(extruderIndex);
if (string.IsNullOrEmpty(presetsID))
{
return;
}
var layerToEdit = ActiveSliceSettings.Instance.MaterialLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();
var layerToEdit = printer.Settings.MaterialLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();
var presetsContext = new PresetsContext(ActiveSliceSettings.Instance.MaterialLayers, layerToEdit)
var presetsContext = new PresetsContext(printer.Settings.MaterialLayers, layerToEdit)
{
LayerType = NamedSettingsLayers.Material,
SetAsActive = (materialKey) =>
{
ActiveSliceSettings.Instance.SetMaterialPreset(this.extruderIndex, materialKey);
printer.Settings.SetMaterialPreset(this.extruderIndex, materialKey);
},
DeleteLayer = () =>
{
var materialKeys = ActiveSliceSettings.Instance.MaterialSettingsKeys;
var materialKeys = printer.Settings.MaterialSettingsKeys;
for (var i = 0; i < materialKeys.Count; i++)
{
if (materialKeys[i] == presetsID)
@ -148,15 +150,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
}
ActiveSliceSettings.Instance.SetMaterialPreset(extruderIndex, "");
ActiveSliceSettings.Instance.MaterialLayers.Remove(layerToEdit);
ActiveSliceSettings.Instance.Save();
printer.Settings.SetMaterialPreset(extruderIndex, "");
printer.Settings.MaterialLayers.Remove(layerToEdit);
printer.Settings.Save();
UiThread.RunOnIdle(() => ApplicationController.Instance.ReloadAdvancedControlsPanel());
}
};
ApplicationController.Instance.EditMaterialPresetsWindow = new SlicePresetsWindow(presetsContext);
ApplicationController.Instance.EditMaterialPresetsWindow = new SlicePresetsWindow(printer, presetsContext);
ApplicationController.Instance.EditMaterialPresetsWindow.Closed += (s, e2) =>
{
ApplicationController.Instance.EditMaterialPresetsWindow = null;
@ -174,29 +176,29 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
if (ApplicationController.Instance.EditQualityPresetsWindow == null)
{
string presetsID = ActiveSliceSettings.Instance.ActiveQualityKey;
string presetsID = printer.Settings.ActiveQualityKey;
if (string.IsNullOrEmpty(presetsID))
{
return;
}
var layerToEdit = ActiveSliceSettings.Instance.QualityLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();
var layerToEdit = printer.Settings.QualityLayers.Where(layer => layer.LayerID == presetsID).FirstOrDefault();
var presetsContext = new PresetsContext(ActiveSliceSettings.Instance.QualityLayers, layerToEdit)
var presetsContext = new PresetsContext(printer.Settings.QualityLayers, layerToEdit)
{
LayerType = NamedSettingsLayers.Quality,
SetAsActive = (qualityKey) => ActiveSliceSettings.Instance.ActiveQualityKey = qualityKey,
SetAsActive = (qualityKey) => printer.Settings.ActiveQualityKey = qualityKey,
DeleteLayer = () =>
{
ActiveSliceSettings.Instance.ActiveQualityKey = "";
ActiveSliceSettings.Instance.QualityLayers.Remove(layerToEdit);
ActiveSliceSettings.Instance.Save();
printer.Settings.ActiveQualityKey = "";
printer.Settings.QualityLayers.Remove(layerToEdit);
printer.Settings.Save();
UiThread.RunOnIdle(() => ApplicationController.Instance.ReloadAdvancedControlsPanel());
}
};
ApplicationController.Instance.EditQualityPresetsWindow = new SlicePresetsWindow(presetsContext);
ApplicationController.Instance.EditQualityPresetsWindow = new SlicePresetsWindow(printer, presetsContext);
ApplicationController.Instance.EditQualityPresetsWindow.Closed += (s, e2) =>
{
ApplicationController.Instance.EditQualityPresetsWindow = null;
@ -229,10 +231,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
Dictionary<string, string> settingBeforeChange = new Dictionary<string, string>();
foreach (var keyName in PrinterSettings.KnownSettings)
{
settingBeforeChange.Add(keyName, ActiveSliceSettings.Instance.GetValue(keyName));
settingBeforeChange.Add(keyName, printer.Settings.GetValue(keyName));
}
var activeSettings = ActiveSliceSettings.Instance;
var activeSettings = printer.Settings;
MenuItem item = (MenuItem)sender;
if (layerType == NamedSettingsLayers.Material)
@ -270,7 +272,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
ApplicationController.Instance.ReloadAdvancedControlsPanel();
foreach (var keyName in PrinterSettings.KnownSettings)
{
if (settingBeforeChange[keyName] != ActiveSliceSettings.Instance.GetValue(keyName))
if (settingBeforeChange[keyName] != printer.Settings.GetValue(keyName))
{
ActiveSliceSettings.OnSettingChanged(keyName);
}
@ -296,7 +298,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
MenuItem defaultMenuItem = dropDownList.AddItem(defaultMenuItemText, "");
defaultMenuItem.Selected += MenuItem_Selected;
var listSource = (layerType == NamedSettingsLayers.Material) ? ActiveSliceSettings.Instance.MaterialLayers : ActiveSliceSettings.Instance.QualityLayers;
var listSource = (layerType == NamedSettingsLayers.Material) ? printer.Settings.MaterialLayers : printer.Settings.QualityLayers;
foreach (var layer in listSource)
{
MenuItem menuItem = dropDownList.AddItem(layer.Name, layer.LayerID);
@ -310,15 +312,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
var newLayer = new PrinterSettingsLayer();
if (layerType == NamedSettingsLayers.Quality)
{
newLayer.Name = "Quality" + ActiveSliceSettings.Instance.QualityLayers.Count;
ActiveSliceSettings.Instance.QualityLayers.Add(newLayer);
ActiveSliceSettings.Instance.ActiveQualityKey = newLayer.LayerID;
newLayer.Name = "Quality" + printer.Settings.QualityLayers.Count;
printer.Settings.QualityLayers.Add(newLayer);
printer.Settings.ActiveQualityKey = newLayer.LayerID;
}
else
{
newLayer.Name = "Material" + ActiveSliceSettings.Instance.MaterialLayers.Count;
ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer);
ActiveSliceSettings.Instance.SetMaterialPreset(this.extruderIndex, newLayer.LayerID);
newLayer.Name = "Material" + printer.Settings.MaterialLayers.Count;
printer.Settings.MaterialLayers.Add(newLayer);
printer.Settings.SetMaterialPreset(this.extruderIndex, newLayer.LayerID);
}
RebuildDropDownList();
@ -332,22 +334,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (layerType == NamedSettingsLayers.Material)
{
settingsKey = ActiveSliceSettings.Instance.GetMaterialPresetKey(extruderIndex);
settingsKey = printer.Settings.GetMaterialPresetKey(extruderIndex);
ActiveSliceSettings.Instance.MaterialLayers.CollectionChanged += SettingsLayers_CollectionChanged;
printer.Settings.MaterialLayers.CollectionChanged += SettingsLayers_CollectionChanged;
dropDownList.Closed += (s1, e1) =>
{
ActiveSliceSettings.Instance.MaterialLayers.CollectionChanged -= SettingsLayers_CollectionChanged;
printer.Settings.MaterialLayers.CollectionChanged -= SettingsLayers_CollectionChanged;
};
}
else
{
settingsKey = ActiveSliceSettings.Instance.ActiveQualityKey;
settingsKey = printer.Settings.ActiveQualityKey;
ActiveSliceSettings.Instance.QualityLayers.CollectionChanged += SettingsLayers_CollectionChanged;
printer.Settings.QualityLayers.CollectionChanged += SettingsLayers_CollectionChanged;
dropDownList.Closed += (s1, e1) =>
{
ActiveSliceSettings.Instance.QualityLayers.CollectionChanged -= SettingsLayers_CollectionChanged;
printer.Settings.QualityLayers.CollectionChanged -= SettingsLayers_CollectionChanged;
};
}

View file

@ -31,19 +31,18 @@ using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class PresetsToolbar : FlowLayoutWidget
{
public PresetsToolbar()
public PresetsToolbar(PrinterConfig printer)
{
this.HAnchor = HAnchor.Stretch;
int numberOfHeatedExtruders = ActiveSliceSettings.Instance.Helpers.NumberOfHotEnds();
int numberOfHeatedExtruders = printer.Settings.Helpers.NumberOfHotEnds();
this.AddChild(new PresetSelectorWidget("Quality".Localize(), RGBA_Bytes.Yellow, NamedSettingsLayers.Quality, 0));
this.AddChild(new PresetSelectorWidget(printer, "Quality".Localize(), RGBA_Bytes.Yellow, NamedSettingsLayers.Quality, 0));
this.AddChild(new GuiWidget(8, 0));
if (numberOfHeatedExtruders > 1)
@ -58,12 +57,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(printer, 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(printer, "Material".Localize(), RGBA_Bytes.Orange, NamedSettingsLayers.Material, 0));
}
this.Height = 60 * GuiWidget.DeviceScale;

View file

@ -42,7 +42,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
public enum NamedSettingsLayers { MHBaseSettings, OEMSettings, Quality, Material, User, All }
public class ActiveSliceSettings
public static class ActiveSliceSettings
{
public static RootedObjectEventHandler ActivePrinterChanged = new RootedObjectEventHandler();
public static RootedObjectEventHandler ActiveProfileModified = new RootedObjectEventHandler();
@ -81,8 +81,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (!MatterControlApplication.IsLoading)
{
if (ActiveSliceSettings.Instance.PrinterSelected
&& Instance.GetValue<bool>(SettingsKey.auto_connect))
if (activeInstance.PrinterSelected
&& activeInstance.GetValue<bool>(SettingsKey.auto_connect))
{
UiThread.RunOnIdle(() =>
{

View file

@ -302,7 +302,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (printLevelingData == null)
{
printLevelingData = PrintLevelingData.Create(
ActiveSliceSettings.Instance,
printerSettings,
printerSettings.GetValue(SettingsKey.print_leveling_data));
if (printLevelingData.SampledPositions.Count == 3)
@ -311,7 +311,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
printLevelingData.SampledPositions[0],
printLevelingData.SampledPositions[1],
printLevelingData.SampledPositions[2],
ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.print_center));
printerSettings.GetValue<Vector2>(SettingsKey.print_center));
}
}
@ -322,7 +322,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
if (clearUserZOffset)
{
ActiveSliceSettings.Instance.SetValue(SettingsKey.baby_step_z_offset, "0");
printerSettings.SetValue(SettingsKey.baby_step_z_offset, "0");
}
printLevelingData = data;
printerSettings.SetValue(SettingsKey.print_leveling_data, JsonConvert.SerializeObject(data));
@ -348,14 +348,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public void UpdateLevelSettings()
{
PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData();
PrintLevelingData levelingData = this.GetPrintLevelingData();
if (levelingData.SampledPositions.Count > 2)
{
PrintLevelingPlane.Instance.SetPrintLevelingEquation(
levelingData.SampledPositions[0],
levelingData.SampledPositions[1],
levelingData.SampledPositions[2],
ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.print_center));
printerSettings.GetValue<Vector2>(SettingsKey.print_center));
}
}
@ -436,7 +436,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
Vector3 feedRate = new Vector3(3000, 3000, 315);
string savedSettings = ActiveSliceSettings.Instance.GetValue(SettingsKey.manual_movement_speeds);
string savedSettings = printerSettings.GetValue(SettingsKey.manual_movement_speeds);
if (!string.IsNullOrEmpty(savedSettings))
{
var segments = savedSettings.Split(',');
@ -478,17 +478,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public int NumberOfHotEnds()
{
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.extruders_share_temperature))
if (printerSettings.GetValue<bool>(SettingsKey.extruders_share_temperature))
{
return 1;
}
return ActiveSliceSettings.Instance.GetValue<int>(SettingsKey.extruder_count);
return printerSettings.GetValue<int>(SettingsKey.extruder_count);
}
public bool UseZProbe()
{
return ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.has_z_probe) && ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.use_z_probe);
return printerSettings.GetValue<bool>(SettingsKey.has_z_probe) && printerSettings.GetValue<bool>(SettingsKey.use_z_probe);
}
}

View file

@ -38,9 +38,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
private IEnumerable<PrinterSettingsLayer> layerCascade;
private PrinterSettingsLayer persistenceLayer;
private PrinterConfig printer;
public SettingsContext(IEnumerable<PrinterSettingsLayer> layerCascade, NamedSettingsLayers viewFilter)
public SettingsContext(PrinterConfig printer, IEnumerable<PrinterSettingsLayer> layerCascade, NamedSettingsLayers viewFilter)
{
this.printer = printer;
this.layerCascade = layerCascade;
this.ViewFilter = viewFilter;
@ -48,7 +50,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
this.IsPrimarySettingsView = layerCascade == null;
// The last layer of the layerFilters is the target persistence
this.persistenceLayer = layerCascade?.First() ?? ActiveSliceSettings.Instance.UserLayer;
this.persistenceLayer = layerCascade?.First() ?? printer.Settings.UserLayer;
}
public NamedSettingsLayers ViewFilter { get; set; }
@ -57,22 +59,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public string GetValue(string slicerConfigName)
{
return ActiveSliceSettings.Instance.GetValue(slicerConfigName, layerCascade);
return printer.Settings.GetValue(slicerConfigName, layerCascade);
}
public void SetValue(string slicerConfigName, string settingsValue)
{
ActiveSliceSettings.Instance.SetValue(slicerConfigName, settingsValue, persistenceLayer);
printer.Settings.SetValue(slicerConfigName, settingsValue, persistenceLayer);
}
public void SetComPort(string settingsValue)
{
ActiveSliceSettings.Instance.Helpers.SetComPort(settingsValue, persistenceLayer);
printer.Settings.Helpers.SetComPort(settingsValue, persistenceLayer);
}
public void ClearValue(string slicerConfigName)
{
ActiveSliceSettings.Instance.ClearValue(slicerConfigName, persistenceLayer);
printer.Settings.ClearValue(slicerConfigName, persistenceLayer);
}
public bool ContainsKey(string slicerConfigName)
@ -82,7 +84,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
internal bool ParseShowString(string enableIfSet)
{
return ActiveSliceSettings.Instance.ParseShowString(enableIfSet, layerCascade);
return printer.Settings.ParseShowString(enableIfSet, layerCascade);
}
}
}

View file

@ -64,16 +64,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private static Regex numberMatch = new Regex("\\s*\\(\\d+\\)", RegexOptions.Compiled);
private PresetsContext presetsContext;
private PrinterConfig printer;
private MHTextEditWidget presetNameInput;
private string initialPresetName = null;
private GuiWidget middleRow;
public SlicePresetsWindow(PresetsContext presetsContext)
public SlicePresetsWindow(PrinterConfig printer, PresetsContext presetsContext)
: base(641, 481)
{
this.presetsContext = presetsContext;
this.printer = printer;
this.AlwaysOnTopOfMain = true;
this.Title = "Slice Presets Editor".Localize();
this.MinimumSize = new Vector2(640, 480);
@ -95,7 +97,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
middleRow = new GuiWidget();
middleRow.AnchorAll();
middleRow.AddChild(CreateSliceSettingsWidget(presetsContext.PersistenceLayer));
middleRow.AddChild(CreateSliceSettingsWidget(printer, presetsContext.PersistenceLayer));
mainContainer.AddChild(GetTopRow());
mainContainer.AddChild(middleRow);
@ -141,9 +143,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
return topRow;
}
private GuiWidget CreateSliceSettingsWidget(PrinterSettingsLayer persistenceLayer)
private GuiWidget CreateSliceSettingsWidget(PrinterConfig printer, PrinterSettingsLayer persistenceLayer)
{
var settingsContext = new SettingsContext(
printer,
new List<PrinterSettingsLayer>
{
persistenceLayer,
@ -152,7 +155,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
},
presetsContext.LayerType);
return new SliceSettingsWidget(settingsContext)
return new SliceSettingsWidget(printer, settingsContext)
{
ShowControlBar = false
};
@ -202,7 +205,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
presetsContext.PersistenceLayer = clonedLayer;
middleRow.CloseAllChildren();
middleRow.AddChild(CreateSliceSettingsWidget(clonedLayer));
middleRow.AddChild(CreateSliceSettingsWidget(printer, clonedLayer));
presetNameInput.Text = newProfileName;
});

View file

@ -42,10 +42,10 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
string resetToDefaultsMessage = "Resetting to default values will remove your current overrides and restore your original printer settings.\nAre you sure you want to continue?".Localize();
string resetToDefaultsWindowTitle = "Revert Settings".Localize();
public SliceSettingsOverflowDropdown(SliceSettingsWidget sliceSettingsWidget)
public SliceSettingsOverflowDropdown(PrinterConfig printer, SliceSettingsWidget sliceSettingsWidget)
{
this.VAnchor = VAnchor.Fit | VAnchor.Center;
var overflowDropdown = new OverflowDropdown(true)
{
AlignToRightEdge = true,
@ -98,14 +98,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (revertSettings)
{
bool onlyReloadSliceSettings = true;
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
&& ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled))
if (printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
&& printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled))
{
onlyReloadSliceSettings = false;
}
ActiveSliceSettings.Instance.ClearUserOverrides();
ActiveSliceSettings.Instance.Save();
printer.Settings.ClearUserOverrides();
printer.Settings.Save();
if (onlyReloadSliceSettings)
{

View file

@ -44,8 +44,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public static readonly RGBA_Bytes userSettingBackgroundColor = new RGBA_Bytes(68, 95, 220, 150);
public event EventHandler StyleChanged;
private SettingsContext settingsContext;
private SettingsContext settingsContext;
private PrinterConfig printer;
private SliceSettingData settingData;
private GuiWidget dataArea;
@ -56,8 +57,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private const bool debugLayout = false;
public SliceSettingsRow(SettingsContext settingsContext, SliceSettingData settingData, bool fullRow = false)
public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, bool fullRow = false)
{
this.printer = printer;
this.settingData = settingData;
this.settingsContext = settingsContext;
@ -163,9 +165,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
case NamedSettingsLayers.All:
if (settingData.ShowAsOverride)
{
var defaultCascade = ActiveSliceSettings.Instance.defaultLayerCascade;
var firstParentValue = ActiveSliceSettings.Instance.GetValueAndLayerName(settingData.SlicerConfigName, defaultCascade.Skip(1));
var currentValueAndLayerName = ActiveSliceSettings.Instance.GetValueAndLayerName(settingData.SlicerConfigName, defaultCascade);
var defaultCascade = printer.Settings.defaultLayerCascade;
var firstParentValue = printer.Settings.GetValueAndLayerName(settingData.SlicerConfigName, defaultCascade.Skip(1));
var currentValueAndLayerName = printer.Settings.GetValueAndLayerName(settingData.SlicerConfigName, defaultCascade);
var currentValue = currentValueAndLayerName.Item1;
var layerName = currentValueAndLayerName.Item2;
@ -209,11 +211,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
else if (settingsContext.IsPrimarySettingsView)
{
if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, NamedSettingsLayers.Material))
if (printer.Settings.SettingExistsInLayer(settingData.SlicerConfigName, NamedSettingsLayers.Material))
{
this.HighlightColor = materialSettingBackgroundColor;
}
else if (ActiveSliceSettings.Instance.SettingExistsInLayer(settingData.SlicerConfigName, NamedSettingsLayers.Quality))
else if (printer.Settings.SettingExistsInLayer(settingData.SlicerConfigName, NamedSettingsLayers.Quality))
{
this.HighlightColor = qualitySettingBackgroundColor;
}

View file

@ -46,19 +46,21 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
internal PresetsToolbar settingsControlBar;
private SettingsContext settingsContext;
private PrinterConfig printer;
private Dictionary<string, UIField> allUiFields = new Dictionary<string, UIField>();
private EventHandler unregisterEvents;
public SliceSettingsWidget(SettingsContext settingsContext)
public SliceSettingsWidget(PrinterConfig printer, SettingsContext settingsContext)
: base (FlowDirection.TopToBottom)
{
this.printer = printer;
this.BackgroundColor = ApplicationController.Instance.Theme.TabBodyBackground;
this.settingsContext = settingsContext;
settingsControlBar = new PresetsToolbar()
settingsControlBar = new PresetsToolbar(printer)
{
HAnchor = HAnchor.Stretch,
Padding = new BorderDouble(8, 12, 8, 8)
@ -143,7 +145,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (settingsContext.IsPrimarySettingsView)
{
var sliceSettingsDetailControl = new SliceSettingsOverflowDropdown(this);
var sliceSettingsDetailControl = new SliceSettingsOverflowDropdown(printer, this);
primaryTabControl.TabBar.AddChild(sliceSettingsDetailControl);
}
@ -351,7 +353,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (group.Name == "Connection")
{
subGroupLayoutTopToBottom.AddChild(SliceSettingsWidget.CreateOemProfileInfoRow(isPrimarySettingsView: true));
subGroupLayoutTopToBottom.AddChild(SliceSettingsWidget.CreateOemProfileInfoRow(settingsContext, isPrimarySettingsView: true));
}
}
@ -414,7 +416,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
}
// Creates an information row showing the base OEM profile and its create_date value
public static GuiWidget CreateOemProfileInfoRow(bool isPrimarySettingsView = false)
public static GuiWidget CreateOemProfileInfoRow(SettingsContext settingsContext, bool isPrimarySettingsView = false)
{
var dataArea = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
@ -449,8 +451,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
HAnchor = HAnchor.Stretch,
};
string make = ActiveSliceSettings.Instance.GetValue(SettingsKey.make);
string model = ActiveSliceSettings.Instance.GetValue(SettingsKey.model);
string make = settingsContext.GetValue(SettingsKey.make);
string model = settingsContext.GetValue(SettingsKey.model);
string title = $"{make} {model}";
if (title == "Other Other")
@ -487,7 +489,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
bool useDefaultSavePattern = true;
bool placeFieldInDedicatedRow = false;
var settingsRow = new SliceSettingsRow(settingsContext, settingData)
var settingsRow = new SliceSettingsRow(printer, settingsContext, settingData)
{
Margin = new BorderDouble(0, 0),
Padding = new BorderDouble(0, 0, 10, 0),

View file

@ -110,6 +110,7 @@ namespace MatterHackers.PolygonMesh.UnitTests
var sceneContext = new BedConfig();
// TODO: Entire app is spun up just to persist a scene - rewrite to reduce footprint/scope
var view3DWidget = new View3DWidget(
null,
sceneContext,
View3DWidget.AutoRotate.Disabled,
new ViewControls3D(ApplicationController.Instance.Theme, new Agg.UI.UndoBuffer()),