diff options
| author | a1xd <[email protected]> | 2020-08-14 03:48:40 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-14 03:48:40 -0400 |
| commit | 0621a7ebd431102d720497a143190505dcfeb7a1 (patch) | |
| tree | 01d7df8f55e5a1cce90617fd876eaf994eb26846 /grapher/Models/Options | |
| parent | Merge pull request #14 from JacobPalecki/GainCap (diff) | |
| parent | Fix initial points, add poll time constant (diff) | |
| download | rawaccel-0621a7ebd431102d720497a143190505dcfeb7a1.tar.xz rawaccel-0621a7ebd431102d720497a143190505dcfeb7a1.zip | |
Merge pull request #15 from JacobPalecki/GUI
GUI: Add x/y graphs, moving dot
Diffstat (limited to 'grapher/Models/Options')
| -rw-r--r-- | grapher/Models/Options/AccelOptions.cs | 79 | ||||
| -rw-r--r-- | grapher/Models/Options/CapOptions.cs | 137 | ||||
| -rw-r--r-- | grapher/Models/Options/Option.cs | 58 | ||||
| -rw-r--r-- | grapher/Models/Options/OptionXY.cs | 83 |
4 files changed, 357 insertions, 0 deletions
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..90a46d7 --- /dev/null +++ b/grapher/Models/Options/OptionXY.cs @@ -0,0 +1,83 @@ +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, + AccelCharts accelCharts) + : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label) + { + } + + public OptionXY( + TextBox xBox, + TextBox yBox, + CheckBox lockCheckBox, + Form containingForm, + double defaultData, + Label label, + string startingName, + AccelCharts accelCharts): + this( + xBox, + yBox, + lockCheckBox, + containingForm, + defaultData, + label, + accelCharts) + { + 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(); + } + + } +} |