2016-01-13 16:11:13 -08:00
|
|
|
|
/*
|
2017-02-01 10:12:33 -08:00
|
|
|
|
Copyright (c) 2017, Kevin Pope, John Lewin
|
2016-01-13 16:11:13 -08:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-02-01 10:12:33 -08:00
|
|
|
|
using System;
|
2018-04-06 17:34:08 -07:00
|
|
|
|
using System.Linq;
|
2016-01-13 16:11:13 -08:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2017-10-31 17:27:37 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2017-03-09 12:44:20 -08:00
|
|
|
|
using MatterHackers.MatterControl.PrinterCommunication.Io;
|
2017-02-01 17:36:33 -08:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2016-01-13 16:11:13 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrinterControls
|
|
|
|
|
|
{
|
2018-01-10 16:34:24 -08:00
|
|
|
|
public class AdjustmentControls : FlowLayoutWidget
|
2016-01-13 16:11:13 -08:00
|
|
|
|
{
|
2022-07-15 17:28:39 -07:00
|
|
|
|
private ThemedNumberEdit feedRateValue;
|
|
|
|
|
|
private ThemedNumberEdit extrusionValue;
|
2017-02-01 10:12:33 -08:00
|
|
|
|
|
2016-01-13 16:11:13 -08:00
|
|
|
|
private SolidSlider feedRateRatioSlider;
|
|
|
|
|
|
private SolidSlider extrusionRatioSlider;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly double minExtrutionRatio = .5;
|
|
|
|
|
|
private readonly double maxExtrusionRatio = 3;
|
2017-02-01 17:36:33 -08:00
|
|
|
|
private readonly double minFeedRateRatio = .25;
|
|
|
|
|
|
private readonly double maxFeedRateRatio = 3;
|
2016-01-13 16:11:13 -08:00
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
private PrinterConfig printer;
|
2016-01-13 16:11:13 -08:00
|
|
|
|
|
2018-01-10 18:22:13 -08:00
|
|
|
|
private AdjustmentControls(PrinterConfig printer, ThemeConfig theme)
|
2022-07-15 17:28:39 -07:00
|
|
|
|
: base(FlowDirection.TopToBottom)
|
2016-01-13 16:11:13 -08:00
|
|
|
|
{
|
2017-02-01 10:12:33 -08:00
|
|
|
|
double sliderWidth = 300 * GuiWidget.DeviceScale;
|
|
|
|
|
|
double sliderThumbWidth = 10 * GuiWidget.DeviceScale;
|
|
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
this.printer = printer;
|
|
|
|
|
|
|
2018-04-06 17:34:08 -07:00
|
|
|
|
SettingsRow settingsRow;
|
|
|
|
|
|
|
2017-02-01 10:12:33 -08:00
|
|
|
|
{
|
2018-04-06 17:34:08 -07:00
|
|
|
|
this.AddChild(settingsRow = new SettingsRow(
|
|
|
|
|
|
"Speed Multiplier".Localize(),
|
|
|
|
|
|
null,
|
|
|
|
|
|
theme));
|
2017-02-01 10:12:33 -08:00
|
|
|
|
|
2018-04-06 17:34:08 -07:00
|
|
|
|
// Remove the HorizontalSpacer
|
|
|
|
|
|
settingsRow.Children.Last().Close();
|
2016-01-13 16:11:13 -08:00
|
|
|
|
|
2020-07-02 15:45:22 -07:00
|
|
|
|
feedRateRatioSlider = new SolidSlider(default(Vector2), sliderThumbWidth, theme, minFeedRateRatio, maxFeedRateRatio)
|
2016-01-13 16:11:13 -08:00
|
|
|
|
{
|
2017-02-01 10:12:33 -08:00
|
|
|
|
Name = "Feed Rate Slider",
|
|
|
|
|
|
Margin = new BorderDouble(5, 0),
|
2020-07-01 21:59:06 -07:00
|
|
|
|
Value = printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio),
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-04-06 17:34:08 -07:00
|
|
|
|
VAnchor = VAnchor.Center,
|
2017-02-01 10:12:33 -08:00
|
|
|
|
TotalWidthInPixels = sliderWidth,
|
|
|
|
|
|
};
|
2018-10-21 11:29:59 -07:00
|
|
|
|
theme.ApplySliderStyle(feedRateRatioSlider);
|
2017-02-01 10:12:33 -08:00
|
|
|
|
feedRateRatioSlider.ValueChanged += (sender, e) =>
|
|
|
|
|
|
{
|
2017-02-01 17:36:33 -08:00
|
|
|
|
feedRateValue.ActuallNumberEdit.Value = Math.Round(feedRateRatioSlider.Value, 2);
|
|
|
|
|
|
};
|
|
|
|
|
|
feedRateRatioSlider.SliderReleased += (s, e) =>
|
|
|
|
|
|
{
|
2017-03-09 12:44:20 -08:00
|
|
|
|
// Update state for runtime use
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.FeedRateMultiplierStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
|
2017-03-09 12:44:20 -08:00
|
|
|
|
|
|
|
|
|
|
// Persist data for future use
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.SetValue(
|
2017-03-09 12:44:20 -08:00
|
|
|
|
SettingsKey.feedrate_ratio,
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.FeedRateMultiplierStream.FeedRateRatio.ToString());
|
2017-02-01 10:12:33 -08:00
|
|
|
|
};
|
2018-04-06 17:34:08 -07:00
|
|
|
|
settingsRow.AddChild(feedRateRatioSlider);
|
2017-02-01 10:12:33 -08:00
|
|
|
|
|
2022-07-15 17:28:39 -07:00
|
|
|
|
feedRateValue = new ThemedNumberEdit(Math.Round(printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio), 2), theme, allowDecimals: true, minValue: minFeedRateRatio, maxValue: maxFeedRateRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
|
2017-02-01 10:12:33 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Feed Rate NumberEdit",
|
|
|
|
|
|
SelectAllOnFocus = true,
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, 5, 0),
|
2017-08-07 15:47:27 -07:00
|
|
|
|
VAnchor = VAnchor.Center | VAnchor.Fit,
|
2017-02-01 10:12:33 -08:00
|
|
|
|
};
|
|
|
|
|
|
feedRateValue.ActuallNumberEdit.EditComplete += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
feedRateRatioSlider.Value = feedRateValue.ActuallNumberEdit.Value;
|
2017-03-09 12:44:20 -08:00
|
|
|
|
|
|
|
|
|
|
// Update state for runtime use
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.FeedRateMultiplierStream.FeedRateRatio = Math.Round(feedRateRatioSlider.Value, 2);
|
2017-03-09 12:44:20 -08:00
|
|
|
|
|
|
|
|
|
|
// Persist data for future use
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.SetValue(
|
2017-03-09 12:44:20 -08:00
|
|
|
|
SettingsKey.feedrate_ratio,
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.FeedRateMultiplierStream.FeedRateRatio.ToString());
|
2017-02-01 10:12:33 -08:00
|
|
|
|
};
|
2018-04-06 17:34:08 -07:00
|
|
|
|
settingsRow.AddChild(feedRateValue);
|
2016-01-13 16:11:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-01 10:12:33 -08:00
|
|
|
|
{
|
2018-04-06 17:34:08 -07:00
|
|
|
|
this.AddChild(settingsRow = new SettingsRow(
|
|
|
|
|
|
"Extrusion Multiplier".Localize(),
|
|
|
|
|
|
null,
|
|
|
|
|
|
theme));
|
2017-02-01 10:12:33 -08:00
|
|
|
|
|
2018-04-06 17:34:08 -07:00
|
|
|
|
// Remove the HorizontalSpacer
|
|
|
|
|
|
settingsRow.Children.Last().Close();
|
2017-02-01 10:12:33 -08:00
|
|
|
|
|
2020-07-02 15:45:22 -07:00
|
|
|
|
extrusionRatioSlider = new SolidSlider(default(Vector2), sliderThumbWidth, theme, minExtrutionRatio, maxExtrusionRatio, Orientation.Horizontal)
|
2017-02-01 10:12:33 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Extrusion Multiplier Slider",
|
|
|
|
|
|
TotalWidthInPixels = sliderWidth,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2018-04-06 17:34:08 -07:00
|
|
|
|
VAnchor = VAnchor.Center,
|
2017-02-01 10:12:33 -08:00
|
|
|
|
Margin = new BorderDouble(5, 0),
|
2020-07-01 21:59:06 -07:00
|
|
|
|
Value = printer.Settings.GetValue<double>(SettingsKey.extrusion_ratio)
|
2017-02-01 10:12:33 -08:00
|
|
|
|
};
|
2020-07-02 15:45:22 -07:00
|
|
|
|
|
2018-10-21 11:29:59 -07:00
|
|
|
|
theme.ApplySliderStyle(extrusionRatioSlider);
|
2017-02-01 10:12:33 -08:00
|
|
|
|
extrusionRatioSlider.ValueChanged += (sender, e) =>
|
|
|
|
|
|
{
|
2017-02-01 17:36:33 -08:00
|
|
|
|
extrusionValue.ActuallNumberEdit.Value = Math.Round(extrusionRatioSlider.Value, 2);
|
|
|
|
|
|
};
|
|
|
|
|
|
extrusionRatioSlider.SliderReleased += (s, e) =>
|
|
|
|
|
|
{
|
2017-03-09 12:44:20 -08:00
|
|
|
|
// Update state for runtime use
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
|
2017-03-09 12:44:20 -08:00
|
|
|
|
|
|
|
|
|
|
// Persist data for future use
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.SetValue(
|
2017-03-09 12:44:20 -08:00
|
|
|
|
SettingsKey.extrusion_ratio,
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio.ToString());
|
2017-02-01 10:12:33 -08:00
|
|
|
|
};
|
2018-04-06 17:34:08 -07:00
|
|
|
|
settingsRow.AddChild(extrusionRatioSlider);
|
2017-02-01 10:12:33 -08:00
|
|
|
|
|
2022-07-15 17:28:39 -07:00
|
|
|
|
extrusionValue = new ThemedNumberEdit(Math.Round(printer.Settings.GetValue<double>(SettingsKey.extrusion_ratio), 2), theme, allowDecimals: true, minValue: minExtrutionRatio, maxValue: maxExtrusionRatio, pixelWidth: 40 * GuiWidget.DeviceScale)
|
2017-02-01 10:12:33 -08:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Extrusion Multiplier NumberEdit",
|
|
|
|
|
|
SelectAllOnFocus = true,
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, 5, 0),
|
2017-08-07 15:47:27 -07:00
|
|
|
|
VAnchor = VAnchor.Center | VAnchor.Fit,
|
2017-02-01 10:12:33 -08:00
|
|
|
|
};
|
|
|
|
|
|
extrusionValue.ActuallNumberEdit.EditComplete += (sender, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
extrusionRatioSlider.Value = extrusionValue.ActuallNumberEdit.Value;
|
2017-03-09 12:44:20 -08:00
|
|
|
|
|
|
|
|
|
|
// Update state for runtime use
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio = Math.Round(extrusionRatioSlider.Value, 2);
|
2017-03-09 12:44:20 -08:00
|
|
|
|
|
|
|
|
|
|
// Persist data for future use
|
2017-09-17 01:11:18 -07:00
|
|
|
|
printer.Settings.SetValue(
|
2017-03-09 12:44:20 -08:00
|
|
|
|
SettingsKey.extrusion_ratio,
|
2020-07-01 21:59:06 -07:00
|
|
|
|
printer.Connection.ExtrusionMultiplierStream.ExtrusionRatio.ToString());
|
2017-02-01 10:12:33 -08:00
|
|
|
|
};
|
2018-04-06 17:34:08 -07:00
|
|
|
|
settingsRow.AddChild(extrusionValue);
|
2017-02-01 10:12:33 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Register listeners
|
2018-11-12 17:20:59 -08:00
|
|
|
|
printer.Settings.SettingChanged += Printer_SettingChanged;
|
2020-07-02 15:45:22 -07:00
|
|
|
|
printer.Disposed += (s, e) => printer.Settings.SettingChanged -= Printer_SettingChanged;
|
2016-01-13 16:11:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-10 18:22:13 -08:00
|
|
|
|
public static SectionWidget CreateSection(PrinterConfig printer, ThemeConfig theme)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new SectionWidget(
|
|
|
|
|
|
"Tuning Adjustment".Localize(),
|
|
|
|
|
|
new AdjustmentControls(printer, theme),
|
|
|
|
|
|
theme);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-12 12:12:11 -07:00
|
|
|
|
public override void OnLoad(EventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// This is a hack to fix the layout issue this control is having.
|
|
|
|
|
|
Width = Width + 1;
|
|
|
|
|
|
base.OnLoad(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-23 16:44:11 -07:00
|
|
|
|
public override void OnClosed(EventArgs e)
|
2016-01-13 16:11:13 -08:00
|
|
|
|
{
|
2018-11-16 08:44:56 -08:00
|
|
|
|
// Unregister listeners
|
|
|
|
|
|
printer.Settings.SettingChanged -= Printer_SettingChanged;
|
|
|
|
|
|
|
2017-02-01 10:12:33 -08:00
|
|
|
|
base.OnClosed(e);
|
2016-01-13 16:11:13 -08:00
|
|
|
|
}
|
2018-11-16 08:44:56 -08:00
|
|
|
|
|
2018-12-20 12:38:05 -08:00
|
|
|
|
private void Printer_SettingChanged(object s, StringEventArgs eventArgs)
|
2018-11-16 08:44:56 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (eventArgs?.Data == 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 = printer.Settings.GetValue<double>(SettingsKey.feedrate_ratio);
|
|
|
|
|
|
feedRateRatioSlider.Value = feedrateRatio;
|
|
|
|
|
|
feedRateValue.ActuallNumberEdit.Value = Math.Round(feedrateRatio, 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-01-13 16:11:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|