summaryrefslogtreecommitdiff
path: root/grapher/Models
diff options
context:
space:
mode:
Diffstat (limited to 'grapher/Models')
-rw-r--r--grapher/Models/AccelGUI.cs180
-rw-r--r--grapher/Models/Charts/AccelCharts.cs117
-rw-r--r--grapher/Models/Charts/ChartXY.cs142
-rw-r--r--grapher/Models/Fields/Field.cs226
-rw-r--r--grapher/Models/Fields/FieldXY.cs130
-rw-r--r--grapher/Models/Options/AccelOptions.cs79
-rw-r--r--grapher/Models/Options/CapOptions.cs137
-rw-r--r--grapher/Models/Options/Option.cs58
-rw-r--r--grapher/Models/Options/OptionXY.cs80
9 files changed, 1149 insertions, 0 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs
new file mode 100644
index 0000000..54564b3
--- /dev/null
+++ b/grapher/Models/AccelGUI.cs
@@ -0,0 +1,180 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Windows.Forms.DataVisualization.Charting;
+
+namespace grapher
+{
+ public class AccelGUI
+ {
+ public struct MagnitudeData
+ {
+ public double magnitude;
+ public int x;
+ public int y;
+ }
+
+ public static ReadOnlyCollection<MagnitudeData> Magnitudes = GetMagnitudes();
+
+ #region constructors
+
+ public AccelGUI(
+ RawAcceleration accelForm,
+ AccelCharts accelCharts,
+ ManagedAccel managedAccel,
+ AccelOptions accelOptions,
+ OptionXY sensitivity,
+ Option rotation,
+ OptionXY weight,
+ CapOptions cap,
+ Option offset,
+ Option acceleration,
+ Option limtOrExp,
+ Option midpoint,
+ Button writeButton)
+ {
+ AccelForm = accelForm;
+ AccelCharts = accelCharts;
+ ManagedAcceleration = managedAccel;
+ AccelerationOptions = accelOptions;
+ Sensitivity = sensitivity;
+ Rotation = rotation;
+ Weight = weight;
+ Cap = cap;
+ Offset = offset;
+ Acceleration = acceleration;
+ LimitOrExponent = limtOrExp;
+ Midpoint = midpoint;
+ WriteButton = writeButton;
+
+ OrderedAccelPoints = new SortedDictionary<double, double>();
+ OrderedVelocityPoints = new SortedDictionary<double, double>();
+ OrderedGainPoints = new SortedDictionary<double, double>();
+
+
+ ManagedAcceleration.ReadFromDriver();
+ UpdateGraph();
+ }
+
+ #endregion constructors
+
+ #region properties
+
+ public RawAcceleration AccelForm { get; }
+
+ public AccelCharts AccelCharts { get; }
+
+ public ManagedAccel ManagedAcceleration { get; }
+
+ public AccelOptions AccelerationOptions { get; }
+
+ public OptionXY Sensitivity { get; }
+
+ public Option Rotation { get; }
+
+ public OptionXY Weight { get; }
+
+ public CapOptions Cap { get; }
+
+ public Option Offset { get; }
+
+ public Option Acceleration { get; }
+
+ public Option LimitOrExponent { get; }
+
+ public Option Midpoint { get; }
+
+ public Button WriteButton { get; }
+
+ public SortedDictionary<double, double> OrderedAccelPoints { get; }
+
+ public SortedDictionary<double, double> OrderedVelocityPoints { get; }
+
+ public SortedDictionary<double, double> OrderedGainPoints { get; }
+
+ #endregion properties
+
+ #region methods
+
+ public static ReadOnlyCollection<MagnitudeData> GetMagnitudes()
+ {
+ var magnitudes = new List<MagnitudeData>();
+ for (int i = 0; i < 100; i++)
+ {
+ for (int j = 0; j <= i; j++)
+ {
+ MagnitudeData magnitudeData;
+ magnitudeData.magnitude = Magnitude(i, j);
+ magnitudeData.x = i;
+ magnitudeData.y = j;
+ magnitudes.Add(magnitudeData);
+ }
+ }
+
+ magnitudes.Sort((m1, m2) => m1.magnitude.CompareTo(m2.magnitude));
+
+ return magnitudes.AsReadOnly();
+ }
+
+ public static double Magnitude(int x, int y)
+ {
+ return Math.Sqrt(x * x + y * y);
+ }
+
+ public static double Magnitude(double x, double y)
+ {
+ return Math.Sqrt(x * x + y * y);
+ }
+
+ public void UpdateGraph()
+ {
+ OrderedAccelPoints.Clear();
+ OrderedVelocityPoints.Clear();
+ OrderedGainPoints.Clear();
+
+ double lastInputMagnitude = 0;
+ double lastOutputMagnitude = 0;
+
+ foreach (var magnitudeData in Magnitudes)
+ {
+ var output = ManagedAcceleration.Accelerate(magnitudeData.x, magnitudeData.y, 1);
+
+ var outMagnitude = Magnitude(output.Item1, output.Item2);
+ var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X;
+
+ var inDiff = magnitudeData.magnitude - lastInputMagnitude;
+ var outDiff = outMagnitude - lastOutputMagnitude;
+ var slope = inDiff > 0 ? outDiff / inDiff : Sensitivity.Fields.X;
+
+ if (!OrderedAccelPoints.ContainsKey(magnitudeData.magnitude))
+ {
+ OrderedAccelPoints.Add(magnitudeData.magnitude, ratio);
+ }
+
+ if (!OrderedVelocityPoints.ContainsKey(magnitudeData.magnitude))
+ {
+ OrderedVelocityPoints.Add(magnitudeData.magnitude, outMagnitude);
+ }
+
+ if (!OrderedGainPoints.ContainsKey(magnitudeData.magnitude))
+ {
+ OrderedGainPoints.Add(magnitudeData.magnitude, slope);
+ }
+
+ lastInputMagnitude = magnitudeData.magnitude;
+ lastOutputMagnitude = outMagnitude;
+ }
+
+ AccelCharts.SensitivityChart.ChartX.Series[0].Points.DataBindXY(OrderedAccelPoints.Keys, OrderedAccelPoints.Values);
+ AccelCharts.VelocityChart.ChartX.Series[0].Points.DataBindXY(OrderedVelocityPoints.Keys, OrderedVelocityPoints.Values);
+ AccelCharts.GainChart.ChartX.Series[0].Points.DataBindXY(OrderedGainPoints.Keys, OrderedGainPoints.Values);
+ }
+
+ #endregion methods
+ }
+
+}
diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs
new file mode 100644
index 0000000..9952016
--- /dev/null
+++ b/grapher/Models/Charts/AccelCharts.cs
@@ -0,0 +1,117 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Windows.Forms.DataVisualization.Charting;
+
+namespace grapher
+{
+ public class AccelCharts
+ {
+ public const int ChartSeparationVertical = 10;
+
+ /// <summary> Needed to show full contents in form. Unsure why. </summary>
+ public const int FormHeightPadding = 35;
+
+ public AccelCharts(
+ Form form,
+ ChartXY sensitivityChart,
+ ChartXY velocityChart,
+ ChartXY gainChart,
+ ToolStripMenuItem enableVelocityAndGain)
+ {
+ ContaingForm = form;
+ SensitivityChart = sensitivityChart;
+ VelocityChart = velocityChart;
+ GainChart = gainChart;
+ EnableVelocityAndGain = enableVelocityAndGain;
+
+ SensitivityChart.SetTop(0);
+ VelocityChart.SetHeight(SensitivityChart.Height);
+ VelocityChart.SetTop(SensitivityChart.Height + ChartSeparationVertical);
+ GainChart.SetHeight(SensitivityChart.Height);
+ GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + ChartSeparationVertical);
+
+ Rectangle screenRectangle = ContaingForm.RectangleToScreen(ContaingForm.ClientRectangle);
+ FormBorderHeight = screenRectangle.Top - ContaingForm.Top;
+
+ EnableVelocityAndGain.Click += new System.EventHandler(OnEnableClick);
+ EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableCheckStateChange);
+
+ HideVelocityAndGain();
+ ShowCombined();
+ }
+
+ public Form ContaingForm { get; }
+
+ public ChartXY SensitivityChart { get; }
+
+ public ChartXY VelocityChart { get; }
+
+ public ChartXY GainChart { get; }
+
+ public ToolStripMenuItem EnableVelocityAndGain { get; }
+
+ private int FormBorderHeight { get; }
+
+ private void OnEnableClick(object sender, EventArgs e)
+ {
+ EnableVelocityAndGain.Checked = !EnableVelocityAndGain.Checked;
+ }
+
+ private void OnEnableCheckStateChange(object sender, EventArgs e)
+ {
+ if (EnableVelocityAndGain.Checked)
+ {
+ ShowVelocityAndGain();
+ }
+ else
+ {
+ HideVelocityAndGain();
+ }
+ }
+
+ private void ShowVelocityAndGain()
+ {
+ VelocityChart.Show();
+ GainChart.Show();
+ ContaingForm.Height = SensitivityChart.Height +
+ ChartSeparationVertical +
+ VelocityChart.Height +
+ ChartSeparationVertical +
+ GainChart.Height +
+ FormBorderHeight;
+ }
+
+ private void HideVelocityAndGain()
+ {
+ VelocityChart.Hide();
+ GainChart.Hide();
+ ContaingForm.Height = SensitivityChart.Height + FormBorderHeight;
+ }
+
+ private void ShowXandYSeparate()
+ {
+ SensitivityChart.SetSeparate();
+ VelocityChart.SetSeparate();
+ GainChart.SetSeparate();
+ UpdateFormWidth();
+ }
+
+ private void ShowCombined()
+ {
+ SensitivityChart.SetCombined();
+ VelocityChart.SetCombined();
+ GainChart.SetCombined();
+ UpdateFormWidth();
+ }
+
+ private void UpdateFormWidth()
+ {
+ ContaingForm.Width = SensitivityChart.Left + SensitivityChart.Width;
+ }
+ }
+}
diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs
new file mode 100644
index 0000000..4bb1bd5
--- /dev/null
+++ b/grapher/Models/Charts/ChartXY.cs
@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Windows.Forms.DataVisualization.Charting;
+
+namespace grapher
+{
+ public class ChartXY
+ {
+ public const int ChartSeparationHorizontal = 10;
+
+ public ChartXY(Chart chartX, Chart chartY)
+ {
+ ChartX = chartX;
+ ChartY = chartY;
+
+ ChartY.Top = ChartX.Top;
+ ChartY.Height = ChartX.Height;
+ ChartY.Width = ChartX.Width;
+ ChartY.Left = ChartX.Left + ChartX.Width + ChartSeparationHorizontal;
+
+ SetupChart(ChartX);
+ SetupChart(ChartY);
+ }
+
+ public Chart ChartX { get; }
+
+ public Chart ChartY { get; }
+
+ public static void SetupChart(Chart chart)
+ {
+ chart.ChartAreas[0].AxisX.RoundAxisValues();
+
+ chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
+ chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
+
+ chart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01;
+ chart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001;
+
+ chart.ChartAreas[0].CursorY.Interval = 0.001;
+
+ chart.ChartAreas[0].CursorX.AutoScroll = true;
+ chart.ChartAreas[0].CursorY.AutoScroll = true;
+
+ chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
+ chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
+
+ chart.ChartAreas[0].CursorX.IsUserEnabled = true;
+ chart.ChartAreas[0].CursorY.IsUserEnabled = true;
+ }
+
+ public int Height {
+ get
+ {
+ return ChartX.Height;
+ }
+ }
+
+ public int Width {
+ get
+ {
+ if (Combined)
+ {
+ return ChartX.Width;
+ }
+ else
+ {
+ return ChartY.Left + ChartY.Width - ChartX.Left;
+ }
+ }
+ }
+
+ public int Top {
+ get
+ {
+ return ChartX.Height;
+ }
+ }
+
+ public int Left {
+ get
+ {
+ return ChartX.Left;
+ }
+ }
+
+ public bool Combined { get; private set; }
+
+ public void SetCombined()
+ {
+ if (!Combined)
+ {
+ ChartY.Hide();
+ Combined = true;
+ }
+ }
+
+ public void SetSeparate()
+ {
+ if (Combined)
+ {
+ if (ChartX.Visible)
+ {
+ ChartY.Show();
+ }
+
+ Combined = false;
+ }
+ }
+
+ public void Hide()
+ {
+ ChartX.Hide();
+ ChartY.Hide();
+ }
+
+ public void Show()
+ {
+ ChartX.Show();
+
+ if (!Combined)
+ {
+ ChartY.Show();
+ }
+ }
+
+ public void SetTop(int top)
+ {
+ ChartX.Top = top;
+ ChartY.Top = top;
+ }
+
+ public void SetHeight(int height)
+ {
+ ChartX.Height = height;
+ ChartY.Height = height;
+ }
+ }
+}
diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs
new file mode 100644
index 0000000..8d75172
--- /dev/null
+++ b/grapher/Models/Fields/Field.cs
@@ -0,0 +1,226 @@
+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
+{
+ public class Field
+ {
+ #region Constants
+
+ public const string DefaultFormatString = "0.#########";
+
+ #endregion Constants
+
+ #region Enums
+
+ public enum FieldState
+ {
+ Undefined,
+ Default,
+ Typing,
+ Entered,
+ Unavailable,
+ }
+
+ #endregion Enums
+
+
+ #region Constructors
+
+ public Field(TextBox box, Form containingForm, double defaultData)
+ {
+ DefaultText = DecimalString(defaultData);
+ Box = box;
+ Data = defaultData;
+ DefaultData = defaultData;
+ State = FieldState.Undefined;
+ ContainingForm = containingForm;
+ FormatString = DefaultFormatString;
+ box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown);
+ box.Leave += new System.EventHandler(FocusLeave);
+
+ SetToDefault();
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public TextBox Box { get; }
+
+ private Form ContainingForm { get; }
+
+ public double Data { get; private set; }
+
+ public string FormatString { get; set; }
+
+ public string DefaultText { get; }
+
+ public FieldState State { get; private set; }
+
+ public FieldState PreviousState { get; private set; }
+
+ private double DefaultData { get; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public void SetToDefault()
+ {
+ if (State != FieldState.Default)
+ {
+ Box.BackColor = Color.White;
+ Box.ForeColor = Color.Gray;
+ State = FieldState.Default;
+ PreviousState = FieldState.Default;
+ }
+
+ Data = DefaultData;
+ Box.Text = DefaultText;
+ ContainingForm.ActiveControl = null;
+ }
+
+ public void SetToTyping()
+ {
+ if (State != FieldState.Typing)
+ {
+ Box.BackColor = Color.White;
+ Box.ForeColor = Color.Black;
+
+ PreviousState = State;
+ State = FieldState.Typing;
+ }
+
+ Box.Text = string.Empty;
+ }
+
+ public void SetToEntered()
+ {
+ if (State != FieldState.Entered)
+ {
+ Box.BackColor = Color.AntiqueWhite;
+ Box.ForeColor = Color.DarkGray;
+
+ PreviousState = State;
+ State = FieldState.Entered;
+ }
+
+ ContainingForm.ActiveControl = null;
+ }
+
+ public void SetToEntered(double value)
+ {
+ SetToEntered();
+
+ Data = value;
+ Box.Text = DecimalString(Data);
+ }
+
+ public void SetToUnavailable()
+ {
+ if (State != FieldState.Unavailable)
+ {
+ Box.BackColor = Color.LightGray;
+ Box.ForeColor = Color.LightGray;
+ Box.Text = string.Empty;
+
+ PreviousState = State;
+ State = FieldState.Unavailable;
+ }
+ }
+
+ public void KeyDown(object sender, KeyEventArgs e)
+ {
+ switch(State)
+ {
+ case FieldState.Default:
+ if (e.KeyCode == Keys.Enter)
+ {
+ SetToDefault();
+ }
+ else
+ {
+ SetToTyping();
+ }
+ break;
+
+ case FieldState.Entered:
+ if (e.KeyCode != Keys.Enter)
+ {
+ SetToTyping();
+ }
+ break;
+ case FieldState.Typing:
+ HandleTyping(sender, e);
+ break;
+ case FieldState.Unavailable:
+ Box.Text = string.Empty;
+ ContainingForm.ActiveControl = null;
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void FocusLeave(object sender, EventArgs e)
+ {
+ if (State == FieldState.Typing)
+ {
+ TextToData();
+ }
+ }
+
+ private void HandleTyping(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Enter)
+ {
+ TextToData();
+
+ e.Handled = true;
+ e.SuppressKeyPress = true;
+ }
+ else if (e.KeyCode == Keys.Escape)
+ {
+ ContainingForm.ActiveControl = null;
+ e.Handled = true;
+ e.SuppressKeyPress = true;
+ }
+ }
+
+ private void TextToData()
+ {
+ try
+ {
+ Data = Convert.ToDouble(Box.Text);
+ }
+ catch
+ {
+ }
+
+ Box.Text = DecimalString(Data);
+
+ if (string.Equals(Box.Text, DefaultText))
+ {
+ SetToDefault();
+ }
+ else
+ {
+ SetToEntered();
+ }
+ }
+
+ private string DecimalString(double value)
+ {
+ return value.ToString(FormatString);
+ }
+
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Fields/FieldXY.cs b/grapher/Models/Fields/FieldXY.cs
new file mode 100644
index 0000000..87e0b9c
--- /dev/null
+++ b/grapher/Models/Fields/FieldXY.cs
@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class FieldXY
+ {
+ public const int DefaultSeparation = 4;
+
+ public const string ShortenedFormatString = "0.###";
+
+ public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData)
+ {
+ XField = new Field(xBox, containingForm, defaultData);
+ YField = new Field(yBox, containingForm, defaultData);
+ YField.FormatString = ShortenedFormatString;
+ LockCheckBox = lockCheckBox;
+ LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged);
+
+ XField.Box.Width = (YField.Box.Left + YField.Box.Width - XField.Box.Left - DefaultSeparation) / 2;
+ YField.Box.Width = XField.Box.Width;
+
+ DefaultWidthX = XField.Box.Width;
+ DefaultWidthY = YField.Box.Width;
+
+ YField.Box.Left = XField.Box.Left + XField.Box.Width + DefaultSeparation;
+
+ CombinedWidth = DefaultWidthX + DefaultWidthY + YField.Box.Left - (XField.Box.Left + DefaultWidthX);
+ SetCombined();
+ }
+ public double X
+ {
+ get => XField.Data;
+ }
+
+ public double Y
+ {
+ get
+ {
+ if (Combined)
+ {
+ return X;
+ }
+ else
+ {
+ return YField.Data;
+ }
+ }
+ }
+
+ public CheckBox LockCheckBox { get; }
+
+ public Field XField { get; }
+
+ public Field YField { get; }
+
+ private bool Combined { get; set; }
+
+ private int DefaultWidthX { get; }
+
+ private int DefaultWidthY { get; }
+
+ private int CombinedWidth { get; }
+
+ private void CheckChanged(object sender, EventArgs e)
+ {
+ if (LockCheckBox.CheckState == CheckState.Checked)
+ {
+ SetCombined();
+ }
+ else
+ {
+ SetSeparate();
+ }
+ }
+
+ public void SetCombined()
+ {
+ Combined = true;
+ YField.SetToUnavailable();
+ YField.Box.Hide();
+ XField.Box.Width = CombinedWidth;
+ XField.FormatString = Field.DefaultFormatString;
+ }
+
+ public void SetSeparate()
+ {
+ Combined = false;
+
+ XField.Box.Width = DefaultWidthX;
+ YField.Box.Width = DefaultWidthY;
+
+ XField.FormatString = ShortenedFormatString;
+
+ if (XField.State == Field.FieldState.Default)
+ {
+ YField.SetToDefault();
+ }
+ else
+ {
+ YField.SetToEntered(XField.Data);
+ }
+
+ if (XField.Box.Visible)
+ {
+ YField.Box.Show();
+ }
+ }
+
+ public void Show()
+ {
+ XField.Box.Show();
+
+ if (!Combined)
+ {
+ YField.Box.Show();
+ }
+ }
+
+ public void Hide()
+ {
+ XField.Box.Hide();
+ YField.Box.Hide();
+ }
+ }
+}
diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs
new file mode 100644
index 0000000..b233552
--- /dev/null
+++ b/grapher/Models/Options/AccelOptions.cs
@@ -0,0 +1,79 @@
+using grapher.Layouts;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class AccelOptions
+ {
+ public const int PossibleOptionsCount = 4;
+ public const int PossibleOptionsXYCount = 2;
+
+ public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase>
+ {
+ new DefaultLayout(),
+ new LinearLayout(),
+ new ClassicLayout(),
+ new NaturalLayout(),
+ new LogLayout(),
+ new SigmoidLayout(),
+ new PowerLayout(),
+ new OffLayout()
+ }.ToDictionary(k => k.Name);
+
+ public AccelOptions(
+ ComboBox accelDropdown,
+ Option[] options,
+ OptionXY[] optionsXY,
+ Button writeButton)
+ {
+ AccelDropdown = accelDropdown;
+ AccelDropdown.Items.Clear();
+ AccelDropdown.Items.AddRange(AccelerationTypes.Keys.Skip(1).ToArray());
+ AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
+
+ if (options.Length > PossibleOptionsCount)
+ {
+ throw new Exception("Layout given too many options.");
+ }
+
+ if (optionsXY.Length > PossibleOptionsXYCount)
+ {
+ throw new Exception("Layout given too many options.");
+ }
+
+ Options = options;
+ OptionsXY = optionsXY;
+ WriteButton = writeButton;
+
+ Layout("Default");
+ }
+
+ public Button WriteButton { get; }
+
+ public ComboBox AccelDropdown { get; }
+
+ public int AccelerationIndex { get; private set; }
+
+ public Option[] Options { get; }
+
+ public OptionXY[] OptionsXY { get; }
+
+ private void OnIndexChanged(object sender, EventArgs e)
+ {
+ var accelerationTypeString = AccelDropdown.SelectedItem.ToString();
+ Layout(accelerationTypeString);
+ }
+
+ private void Layout(string type)
+ {
+ var accelerationType = AccelerationTypes[type];
+ AccelerationIndex = accelerationType.Index;
+ accelerationType.Layout(Options, OptionsXY, WriteButton);
+ }
+ }
+}
diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs
new file mode 100644
index 0000000..2ee7f6b
--- /dev/null
+++ b/grapher/Models/Options/CapOptions.cs
@@ -0,0 +1,137 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class CapOptions
+ {
+ public CapOptions(
+ ToolStripMenuItem sensitivityCapCheck,
+ ToolStripMenuItem velocityGainCapCheck,
+ OptionXY capOption,
+ OptionXY weightOption)
+ {
+
+ SensitivityCapCheck = sensitivityCapCheck;
+ VelocityGainCapCheck = velocityGainCapCheck;
+ CapOption = capOption;
+ WeightOption = weightOption;
+
+ SensitivityCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick);
+ VelocityGainCapCheck.Click += new System.EventHandler(OnVelocityGainCapCheckClick);
+
+ SensitivityCapCheck.CheckedChanged += new System.EventHandler(OnSensitivityCapCheckedChange);
+ VelocityGainCapCheck.CheckedChanged += new System.EventHandler(OnVelocityGainCapCheckedChange);
+
+ EnableSensitivityCap();
+ }
+
+ ToolStripMenuItem SensitivityCapCheck { get; }
+
+ ToolStripMenuItem VelocityGainCapCheck { get; }
+
+ OptionXY CapOption { get; }
+
+ OptionXY WeightOption { get; }
+
+ public double SensitivityCapX {
+ get
+ {
+ if (IsSensitivityGain)
+ {
+ return CapOption.Fields.X;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+
+ public double SensitivityCapY {
+ get
+ {
+ if (IsSensitivityGain)
+ {
+ return CapOption.Fields.Y;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+
+ public double VelocityGainCap {
+ get
+ {
+ if (IsSensitivityGain)
+ {
+ return 0;
+ }
+ else
+ {
+ return CapOption.Fields.X;
+ }
+ }
+ }
+
+ public bool IsSensitivityGain { get; private set; }
+
+ void OnSensitivityCapCheckClick(object sender, EventArgs e)
+ {
+ if (!SensitivityCapCheck.Checked)
+ {
+ VelocityGainCapCheck.Checked = false;
+ SensitivityCapCheck.Checked = true;
+ }
+ }
+
+ void OnVelocityGainCapCheckClick(object sender, EventArgs e)
+ {
+ if (!VelocityGainCapCheck.Checked)
+ {
+ VelocityGainCapCheck.Checked = true;
+ SensitivityCapCheck.Checked = false;
+ }
+ }
+
+ void OnSensitivityCapCheckedChange(object sender, EventArgs e)
+ {
+ if (SensitivityCapCheck.Checked == true)
+ {
+ EnableSensitivityCap();
+ }
+ }
+
+ void OnVelocityGainCapCheckedChange(object sender, EventArgs e)
+ {
+ if (SensitivityCapCheck.Checked == true)
+ {
+ EnableVelocityGainCap();
+ }
+ }
+
+ void EnableSensitivityCap()
+ {
+ IsSensitivityGain = true;
+ CapOption.Fields.LockCheckBox.Enabled = true;
+ WeightOption.Fields.LockCheckBox.Enabled = true;
+ CapOption.SetName("Sensitivity Cap");
+ }
+
+ void EnableVelocityGainCap()
+ {
+ IsSensitivityGain = false;
+ CapOption.Fields.LockCheckBox.Checked = true;
+ CapOption.Fields.LockCheckBox.Enabled = false;
+ WeightOption.Fields.LockCheckBox.Checked = true;
+ WeightOption.Fields.LockCheckBox.Enabled = false;
+ CapOption.SetName("Velocity Gain Cap");
+ }
+ }
+}
diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs
new file mode 100644
index 0000000..eb5105e
--- /dev/null
+++ b/grapher/Models/Options/Option.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class Option
+ {
+ public Option(Field field, Label label)
+ {
+ Field = field;
+ Label = label;
+ }
+
+ 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, string startingName)
+ : this(box, containingForm, defaultData, label)
+ {
+ SetName(startingName);
+ }
+
+ public Field Field { get; }
+
+ public Label Label { get; }
+
+ public void SetName(string name)
+ {
+ Label.Text = name;
+ Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0));
+ }
+
+ public void Hide()
+ {
+ Field.Box.Hide();
+ Label.Hide();
+ }
+
+ public void Show()
+ {
+ Field.Box.Show();
+ Label.Show();
+ }
+
+ public void Show(string name)
+ {
+ SetName(name);
+
+ Show();
+ }
+ }
+}
diff --git a/grapher/Models/Options/OptionXY.cs b/grapher/Models/Options/OptionXY.cs
new file mode 100644
index 0000000..ca1559d
--- /dev/null
+++ b/grapher/Models/Options/OptionXY.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class OptionXY
+ {
+ public OptionXY(FieldXY fields, Label label)
+ {
+ Fields = fields;
+ Label = label;
+ }
+
+ public OptionXY(
+ TextBox xBox,
+ TextBox yBox,
+ CheckBox lockCheckBox,
+ Form containingForm,
+ double defaultData,
+ Label label)
+ : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData), label)
+ {
+ }
+
+ public OptionXY(
+ TextBox xBox,
+ TextBox yBox,
+ CheckBox lockCheckBox,
+ Form containingForm,
+ double defaultData,
+ Label label,
+ string startingName):
+ this(
+ xBox,
+ yBox,
+ lockCheckBox,
+ containingForm,
+ defaultData,
+ label)
+ {
+ SetName(startingName);
+ }
+
+ public FieldXY Fields { get; }
+
+ public Label Label { 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 Hide()
+ {
+ Fields.Hide();
+ Fields.LockCheckBox.Hide();
+ Label.Hide();
+ }
+
+ public void Show()
+ {
+ Fields.Show();
+ Fields.LockCheckBox.Show();
+ Label.Show();
+ }
+
+ public void Show(string name)
+ {
+ SetName(name);
+
+ Show();
+ }
+
+ }
+}