1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
using grapher.Layouts;
using grapher.Models.Options;
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
{
#region Fields
public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase>
{
new LinearLayout(),
new ClassicLayout(),
new NaturalLayout(),
new LogLayout(),
new SigmoidLayout(),
new PowerLayout(),
new NaturalGainLayout(),
new SigmoidGainLayout(),
new OffLayout()
}.ToDictionary(k => k.Name);
#endregion Fields
#region Constructors
public AccelOptions(
ComboBox accelDropdown,
Option[] options,
OptionXY[] optionsXY,
Button writeButton,
ActiveValueLabel activeValueLabel)
{
AccelDropdown = accelDropdown;
AccelDropdown.Items.Clear();
AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray());
AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
if (options.Length > Constants.PossibleOptionsCount)
{
throw new Exception("Layout given too many options.");
}
if (optionsXY.Length > Constants.PossibleOptionsXYCount)
{
throw new Exception("Layout given too many options.");
}
Options = options;
OptionsXY = optionsXY;
WriteButton = writeButton;
ActiveValueLabel = activeValueLabel;
Layout("Off");
}
#endregion Constructors
#region Properties
public Button WriteButton { get; }
public ComboBox AccelDropdown { get; }
public int AccelerationIndex { get; private set; }
public ActiveValueLabel ActiveValueLabel { get; }
public Option[] Options { get; }
public OptionXY[] OptionsXY { get; }
#endregion Properties
#region Methods
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();
Layout(accelerationTypeString);
}
private void Layout(string type)
{
var accelerationType = AccelerationTypes[type];
AccelerationIndex = accelerationType.Index;
accelerationType.Layout(Options, OptionsXY, WriteButton);
}
#endregion Methods
}
}
|