diff options
Diffstat (limited to 'grapher/Models/Options')
| -rw-r--r-- | grapher/Models/Options/AccelOptions.cs | 15 | ||||
| -rw-r--r-- | grapher/Models/Options/ActiveValueLabel.cs | 107 | ||||
| -rw-r--r-- | grapher/Models/Options/ActiveValueLabelXY.cs | 84 | ||||
| -rw-r--r-- | grapher/Models/Options/CapOptions.cs | 30 | ||||
| -rw-r--r-- | grapher/Models/Options/Option.cs | 50 | ||||
| -rw-r--r-- | grapher/Models/Options/OptionXY.cs | 22 |
6 files changed, 291 insertions, 17 deletions
diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs index b233552..cd7c4e5 100644 --- a/grapher/Models/Options/AccelOptions.cs +++ b/grapher/Models/Options/AccelOptions.cs @@ -1,4 +1,5 @@ using grapher.Layouts; +using grapher.Models.Options; using System; using System.Collections.Generic; using System.Linq; @@ -22,6 +23,8 @@ namespace grapher new LogLayout(), new SigmoidLayout(), new PowerLayout(), + new NaturalGainLayout(), + new SigmoidGainLayout(), new OffLayout() }.ToDictionary(k => k.Name); @@ -29,7 +32,8 @@ namespace grapher ComboBox accelDropdown, Option[] options, OptionXY[] optionsXY, - Button writeButton) + Button writeButton, + ActiveValueLabel activeValueLabel) { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); @@ -49,6 +53,7 @@ namespace grapher Options = options; OptionsXY = optionsXY; WriteButton = writeButton; + ActiveValueLabel = activeValueLabel; Layout("Default"); } @@ -59,10 +64,18 @@ namespace grapher public int AccelerationIndex { get; private set; } + public ActiveValueLabel ActiveValueLabel { get; } + public Option[] Options { get; } public OptionXY[] OptionsXY { get; } + public void SetActiveValue(int index) + { + var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name; + ActiveValueLabel.SetValue(name); + } + private void OnIndexChanged(object sender, EventArgs e) { var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); diff --git a/grapher/Models/Options/ActiveValueLabel.cs b/grapher/Models/Options/ActiveValueLabel.cs new file mode 100644 index 0000000..138775a --- /dev/null +++ b/grapher/Models/Options/ActiveValueLabel.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class ActiveValueLabel + { + public const string DefaultFormatString = "0.######"; + public static readonly Color ActiveValueFontColor = Color.FromArgb(255, 65, 65, 65); + + private string _prefix; + private string _value; + + public ActiveValueLabel(Label valueLabel, Label centeringLabel) + { + ValueLabel = valueLabel; + ValueLabel.ForeColor = ActiveValueFontColor; + Left = centeringLabel.Left; + Width = centeringLabel.Width; + ValueLabel.AutoSize = false; + ValueLabel.TextAlign = ContentAlignment.MiddleCenter; + + FormatString = DefaultFormatString; + Prefix = string.Empty; + } + + public Label ValueLabel { get; } + + public string FormatString { get; set; } + + public string Prefix + { + get { return _prefix; } + set + { + _prefix = value; + RefreshText(); + } + } + + private string Value + { + get { return _value; } + set + { + _value = value; + RefreshText(); + } + } + + public int Left + { + get + { + return ValueLabel.Left; + } + + set + { + ValueLabel.Left = value; + } + } + + public int Width + { + get + { + return ValueLabel.Width; + } + + set + { + ValueLabel.Width = value; + } + } + + public void Hide() + { + ValueLabel.Hide(); + } + + public void Show() + { + ValueLabel.Show(); + } + + public void SetValue(double value) + { + SetValue(value.ToString(FormatString)); + } + + public void SetValue(string value) + { + Value = value; + } + + public void RefreshText() + { + ValueLabel.Text = string.IsNullOrWhiteSpace(Prefix) ? Value: $"{Prefix}: {Value}"; + } + } +} diff --git a/grapher/Models/Options/ActiveValueLabelXY.cs b/grapher/Models/Options/ActiveValueLabelXY.cs new file mode 100644 index 0000000..12506e9 --- /dev/null +++ b/grapher/Models/Options/ActiveValueLabelXY.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Options +{ + public class ActiveValueLabelXY + { + public const int ActiveLabelXYSeparation = 2; + public const string ShortenedFormatString = "0.###"; + + public ActiveValueLabelXY( + ActiveValueLabel x, + ActiveValueLabel y) + { + X = x; + Y = y; + + FullWidth = x.Width; + ShortenedWidth = (FullWidth - ActiveLabelXYSeparation) / 2; + + Y.Left = X.Left + ShortenedWidth + ActiveLabelXYSeparation; + Y.Width = ShortenedWidth; + Y.FormatString = ShortenedFormatString; + + Combined = false; + SetCombined(); + } + + public ActiveValueLabel X { get; } + + public ActiveValueLabel Y { get; } + + public bool Combined { get; private set; } + + private int FullWidth { get; } + + private int ShortenedWidth { get; } + + public void SetValues(double x, double y) + { + X.SetValue(x); + Y.SetValue(y); + + if (x == y) + { + SetCombined(); + } + else + { + SetSeparate(); + } + } + + public void SetCombined() + { + if (!Combined) + { + X.FormatString = ActiveValueLabel.DefaultFormatString; + X.Width = FullWidth; + X.Prefix = string.Empty; + Y.Hide(); + } + + Combined = true; + } + + public void SetSeparate() + { + if (Combined) + { + X.FormatString = ShortenedFormatString; + X.Width = ShortenedWidth; + X.Prefix = "X"; + Y.Prefix = "Y"; + Y.Show(); + } + + Combined = false; + } + } +} diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs index 2ee7f6b..493561a 100644 --- a/grapher/Models/Options/CapOptions.cs +++ b/grapher/Models/Options/CapOptions.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Options; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,6 +10,9 @@ namespace grapher { public class CapOptions { + + public const string GainCapFormatString = "0.##"; + public CapOptions( ToolStripMenuItem sensitivityCapCheck, ToolStripMenuItem velocityGainCapCheck, @@ -30,13 +34,13 @@ namespace grapher EnableSensitivityCap(); } - ToolStripMenuItem SensitivityCapCheck { get; } + public ToolStripMenuItem SensitivityCapCheck { get; } - ToolStripMenuItem VelocityGainCapCheck { get; } + public ToolStripMenuItem VelocityGainCapCheck { get; } - OptionXY CapOption { get; } + public OptionXY CapOption { get; } - OptionXY WeightOption { get; } + public OptionXY WeightOption { get; } public double SensitivityCapX { get @@ -82,6 +86,22 @@ namespace grapher public bool IsSensitivityGain { get; private set; } + public void SetActiveValues(double gainCap, double sensCapX, double sensCapY, bool capGainEnabled) + { + if (capGainEnabled) + { + CapOption.ActiveValueLabels.X.FormatString = GainCapFormatString; + CapOption.ActiveValueLabels.X.Prefix = "Gain"; + CapOption.SetActiveValues(gainCap, gainCap); + } + else + { + CapOption.ActiveValueLabels.X.FormatString = ActiveValueLabel.DefaultFormatString; + CapOption.ActiveValueLabels.X.Prefix = string.Empty; + CapOption.SetActiveValues(sensCapX, sensCapY); + } + } + void OnSensitivityCapCheckClick(object sender, EventArgs e) { if (!SensitivityCapCheck.Checked) diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs index eb5105e..bacd760 100644 --- a/grapher/Models/Options/Option.cs +++ b/grapher/Models/Options/Option.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Options; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,19 +10,42 @@ namespace grapher { public class Option { - public Option(Field field, Label label) + public Option( + Field field, + Label label, + ActiveValueLabel activeValueLabel) { Field = field; Label = label; + ActiveValueLabel = activeValueLabel; } - public Option(TextBox box, Form containingForm, double defaultData, Label label) - : this(new Field(box, containingForm, defaultData), label) + public Option( + TextBox box, + Form containingForm, + double defaultData, + Label label, + ActiveValueLabel activeValueLabel) + : this( + new Field(box, containingForm, defaultData), + label, + activeValueLabel) { } - public Option(TextBox box, Form containingForm, double defaultData, Label label, string startingName) - : this(box, containingForm, defaultData, label) + public Option( + TextBox box, + Form containingForm, + double defaultData, + Label label, + ActiveValueLabel activeValueLabel, + string startingName) + : this( + box, + containingForm, + defaultData, + label, + activeValueLabel) { SetName(startingName); } @@ -30,22 +54,36 @@ namespace grapher public Label Label { get; } + public ActiveValueLabel ActiveValueLabel { get; } + public void SetName(string name) { Label.Text = name; Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); } + public void SetActiveValue(double value) + { + ActiveValueLabel.SetValue(value); + } + public void Hide() { Field.Box.Hide(); Label.Hide(); + ActiveValueLabel.Hide(); } public void Show() { Field.Box.Show(); Label.Show(); + ActiveValueLabel.Show(); + } + + public void UpdateActiveValue(double value) + { + ActiveValueLabel.SetValue(value); } public void Show(string name) diff --git a/grapher/Models/Options/OptionXY.cs b/grapher/Models/Options/OptionXY.cs index 90a46d7..b22bb78 100644 --- a/grapher/Models/Options/OptionXY.cs +++ b/grapher/Models/Options/OptionXY.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Options; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,10 +10,11 @@ namespace grapher { public class OptionXY { - public OptionXY(FieldXY fields, Label label) + public OptionXY(FieldXY fields, Label label, ActiveValueLabelXY activeValueLabels) { Fields = fields; Label = label; + ActiveValueLabels = activeValueLabels; } public OptionXY( @@ -22,8 +24,9 @@ namespace grapher Form containingForm, double defaultData, Label label, - AccelCharts accelCharts) - : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label) + AccelCharts accelCharts, + ActiveValueLabelXY activeValueLabels) + : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label, activeValueLabels) { } @@ -34,6 +37,7 @@ namespace grapher Form containingForm, double defaultData, Label label, + ActiveValueLabelXY activeValueLabels, string startingName, AccelCharts accelCharts): this( @@ -43,7 +47,8 @@ namespace grapher containingForm, defaultData, label, - accelCharts) + accelCharts, + activeValueLabels) { SetName(startingName); } @@ -52,12 +57,19 @@ namespace grapher public Label Label { get; } + public ActiveValueLabelXY ActiveValueLabels { get; } + public void SetName(string name) { Label.Text = name; Label.Left = Convert.ToInt32((Fields.XField.Box.Left / 2.0) - (Label.Width / 2.0)); } + public void SetActiveValues(double x, double y) + { + ActiveValueLabels.SetValues(x, y); + } + public void Hide() { Fields.Hide(); |