Reduce PrinterSettingsView to essentials

This commit is contained in:
John Lewin 2017-06-15 21:56:07 -07:00
parent f39e701ed9
commit a96302c549

View file

@ -1,163 +1,86 @@
using MatterHackers.Agg;
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.EeProm;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
using System;
using System.IO;
namespace MatterHackers.MatterControl.ConfigurationPage
{
public class HardwareSettingsWidget : SettingsViewBase
{
private Button openCameraButton;
private EventHandler unregisterEvents;
public HardwareSettingsWidget()
: base("Hardware".Localize())
{
DisableableWidget cameraContainer = new DisableableWidget();
cameraContainer.AddChild(GetCameraControl());
bool hasCamera = true || ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true";
if (ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true")
var settingsRow = new FlowLayoutWidget()
{
mainContainer.AddChild(new HorizontalLine(50));
mainContainer.AddChild(cameraContainer);
}
HAnchor = HAnchor.ParentLeftRight,
Margin = new BorderDouble(0, 4)
};
AddChild(mainContainer);
AddHandlers();
SetEnabledStates();
}
public override void OnClosed(ClosedEventArgs e)
{
unregisterEvents?.Invoke(this, null);
base.OnClosed(e);
}
private FlowLayoutWidget GetCameraControl()
{
FlowLayoutWidget buttonRow = new FlowLayoutWidget();
buttonRow.HAnchor = HAnchor.ParentLeftRight;
buttonRow.Margin = new BorderDouble(0, 4);
ImageBuffer cameraIconImage = StaticData.Instance.LoadIcon("camera-24x24.png",24,24).InvertLightness();
ImageBuffer cameraIconImage = StaticData.Instance.LoadIcon("camera-24x24.png", 24, 24).InvertLightness();
cameraIconImage.SetRecieveBlender(new BlenderPreMultBGRA());
int iconSize = (int)(24 * GuiWidget.DeviceScale);
if (!ActiveTheme.Instance.IsDarkTheme)
{
cameraIconImage.InvertLightness();
}
ImageWidget cameraIcon = new ImageWidget(cameraIconImage);
cameraIcon.Margin = new BorderDouble(right: 6);
TextWidget cameraLabel = new TextWidget("Camera Monitoring".Localize());
cameraLabel.AutoExpandBoundsToText = true;
cameraLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
cameraLabel.VAnchor = VAnchor.ParentCenter;
openCameraButton = textImageButtonFactory.Generate("Preview".Localize().ToUpper());
openCameraButton.Click += openCameraPreview_Click;
var openCameraButton = textImageButtonFactory.Generate("Preview".Localize().ToUpper());
openCameraButton.Click += (s, e) =>
{
MatterControlApplication.Instance.OpenCameraPreview();
};
openCameraButton.Margin = new BorderDouble(left: 6);
buttonRow.AddChild(cameraIcon);
buttonRow.AddChild(cameraLabel);
buttonRow.AddChild(new HorizontalSpacer());
buttonRow.AddChild(openCameraButton);
if (ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true")
settingsRow.AddChild(new ImageWidget(cameraIconImage)
{
GuiWidget publishImageSwitchContainer = new FlowLayoutWidget();
publishImageSwitchContainer.VAnchor = VAnchor.ParentCenter;
publishImageSwitchContainer.Margin = new BorderDouble(left: 16);
Margin = new BorderDouble(right: 6)
});
settingsRow.AddChild(new TextWidget("Camera Monitoring".Localize())
{
AutoExpandBoundsToText = true,
TextColor = ActiveTheme.Instance.PrimaryTextColor,
VAnchor = VAnchor.ParentCenter
});
settingsRow.AddChild(new HorizontalSpacer());
settingsRow.AddChild(openCameraButton);
if (hasCamera)
{
var publishImageSwitchContainer = new FlowLayoutWidget()
{
VAnchor = VAnchor.ParentCenter,
Margin = new BorderDouble(left: 16)
};
CheckBox toggleSwitch = ImageButtonFactory.CreateToggleSwitch(ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.publish_bed_image));
toggleSwitch.CheckedStateChanged += (sender, e) =>
{
CheckBox thisControl = sender as CheckBox;
ActiveSliceSettings.Instance.SetValue(SettingsKey.publish_bed_image, thisControl.Checked ? "1" : "0");
ActiveSliceSettings.Instance.SetValue(SettingsKey.publish_bed_image, toggleSwitch.Checked ? "1" : "0");
};
publishImageSwitchContainer.AddChild(toggleSwitch);
publishImageSwitchContainer.SetBoundsToEncloseChildren();
buttonRow.AddChild(publishImageSwitchContainer);
settingsRow.AddChild(publishImageSwitchContainer);
}
return buttonRow;
}
private void AddHandlers()
{
PrinterConnection.Instance.CommunicationStateChanged.RegisterEvent((e, s) => SetEnabledStates(), ref unregisterEvents);
PrinterConnection.Instance.EnableChanged.RegisterEvent((e,s) => SetEnabledStates(), ref unregisterEvents);
}
private void openCameraPreview_Click(object sender, EventArgs e)
{
MatterControlApplication.Instance.OpenCameraPreview();
}
private void SetEnabledStates()
{
if (!ActiveSliceSettings.Instance.PrinterSelected)
if (hasCamera)
{
//cloudMonitorContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled);
}
else // we at least have a printer selected
{
//cloudMonitorContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled);
switch (PrinterConnection.Instance.CommunicationState)
{
case CommunicationStates.Disconnecting:
case CommunicationStates.ConnectionLost:
case CommunicationStates.Disconnected:
case CommunicationStates.AttemptingToConnect:
case CommunicationStates.FailedToConnect:
break;
mainContainer.AddChild(new HorizontalLine(50));
case CommunicationStates.FinishedPrint:
case CommunicationStates.Connected:
break;
case CommunicationStates.PrintingFromSd:
break;
case CommunicationStates.PreparingToPrint:
case CommunicationStates.Printing:
switch (PrinterConnection.Instance.PrintingState)
{
case DetailedPrintingState.HomingAxis:
case DetailedPrintingState.HeatingBed:
case DetailedPrintingState.HeatingExtruder:
case DetailedPrintingState.Printing:
break;
default:
throw new NotImplementedException();
}
break;
case CommunicationStates.Paused:
break;
default:
throw new NotImplementedException();
}
var cameraContainer = new DisableableWidget();
cameraContainer.AddChild(settingsRow);
mainContainer.AddChild(cameraContainer);
}
this.Invalidate();
AddChild(mainContainer);
}
}
}