diff options
| author | Jacob Palecki <[email protected]> | 2020-09-21 14:27:12 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-21 14:27:12 -0700 |
| commit | 96112bf6eaee310985ae607b66b43fafcc5efb1e (patch) | |
| tree | 6ffdee3a16c7b5c89b6f12117e8a9b78b1112e6f /grapher/Models/Charts | |
| parent | conditional around lookup map (diff) | |
| parent | Merge pull request #21 from JacobPalecki/GUI (diff) | |
| download | rawaccel-96112bf6eaee310985ae607b66b43fafcc5efb1e.tar.xz rawaccel-96112bf6eaee310985ae607b66b43fafcc5efb1e.zip | |
Merge branch 'GUI' into experiment
Diffstat (limited to 'grapher/Models/Charts')
| -rw-r--r-- | grapher/Models/Charts/AccelCharts.cs | 206 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/ChartState.cs | 104 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/ChartStateManager.cs | 78 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/CombinedState.cs | 46 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/XYOneGraphState.cs | 48 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/XYTwoGraphState.cs | 76 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartXY.cs | 26 |
7 files changed, 463 insertions, 121 deletions
diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 3f228c3..d22ab78 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -1,5 +1,6 @@ using grapher.Models.Calculations; using grapher.Models.Charts; +using grapher.Models.Charts.ChartState; using grapher.Models.Serialized; using System; using System.Drawing; @@ -18,56 +19,40 @@ namespace grapher ChartXY gainChart, ToolStripMenuItem enableVelocityAndGain, ToolStripMenuItem enableLastMouseMove, - Button writeButton) + Button writeButton, + AccelCalculator accelCalculator) { - Estimated = new EstimatedPoints(); - EstimatedX = new EstimatedPoints(); - EstimatedY = new EstimatedPoints(); - AccelData = new AccelData(Estimated, EstimatedX, EstimatedY); + var estimated = new EstimatedPoints(); + var estimatedX = new EstimatedPoints(); + var estimatedY = new EstimatedPoints(); + SetupCharts(sensitivityChart, velocityChart, gainChart, estimated, estimatedX, estimatedY); + var accelData = new AccelData(estimated, estimatedX, estimatedY); + ChartStateManager = new ChartStateManager(sensitivityChart, velocityChart, gainChart, accelData, accelCalculator); - ContaingForm = form; - SensitivityChart = sensitivityChart; - VelocityChart = velocityChart; - GainChart = gainChart; + ContainingForm = form; EnableVelocityAndGain = enableVelocityAndGain; EnableLastValue = enableLastMouseMove; WriteButton = writeButton; - SensitivityChart.SetPointBinds(Estimated.Sensitivity, EstimatedX.Sensitivity, EstimatedY.Sensitivity); - VelocityChart.SetPointBinds(Estimated.Velocity, EstimatedX.Velocity, EstimatedY.Velocity); - GainChart.SetPointBinds(Estimated.Gain, EstimatedX.Gain, EstimatedY.Gain); - SensitivityChart.SetTop(0); - VelocityChart.SetHeight(SensitivityChart.Height); - VelocityChart.SetTop(SensitivityChart.Height + Constants.ChartSeparationVertical); - GainChart.SetHeight(SensitivityChart.Height); - GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + Constants.ChartSeparationVertical); - - Rectangle screenRectangle = ContaingForm.RectangleToScreen(ContaingForm.ClientRectangle); - FormBorderHeight = screenRectangle.Top - ContaingForm.Top; + Rectangle screenRectangle = ContainingForm.RectangleToScreen(ContainingForm.ClientRectangle); + FormBorderHeight = screenRectangle.Top - ContainingForm.Top; EnableVelocityAndGain.Click += new System.EventHandler(OnEnableClick); EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableVelocityGainCheckStateChange); EnableLastValue.CheckedChanged += new System.EventHandler(OnEnableLastMouseMoveCheckStateChange); + ChartState = ChartStateManager.InitialState(); + ChartState.Activate(); HideVelocityAndGain(); - SensitivityChart.Show(); - Combined = false; - ShowCombined(); } #endregion Constructors #region Properties - public Form ContaingForm { get; } - - public ChartXY SensitivityChart { get; } - - public ChartXY VelocityChart { get; } - - public ChartXY GainChart { get; } + public Form ContainingForm { get; } public ToolStripMenuItem EnableVelocityAndGain { get; } @@ -75,90 +60,116 @@ namespace grapher private Button WriteButton { get; } - public AccelData AccelData { get; } - - private EstimatedPoints Estimated { get; } + public AccelData AccelData + { + get + { + return ChartState.Data; + } + } - private EstimatedPoints EstimatedX { get; } + public int Left + { + get + { + return ChartState.SensitivityChart.Left; + } + } - private EstimatedPoints EstimatedY { get; } + public int Top + { + get + { + return ChartState.SensitivityChart.Top; + } + } - private bool Combined { get; set; } + public int TopChartHeight + { + get + { + return ChartState.SensitivityChart.Height; + } + } private int FormBorderHeight { get; } + private ChartState ChartState { get; set; } + + private ChartStateManager ChartStateManager { get; } + + #endregion Properties #region Methods public void MakeDots(int x, int y, double timeInMs) { - if (Combined) - { - AccelData.CalculateDots(x, y, timeInMs); - } - else - { - AccelData.CalculateDotsXY(x, y, timeInMs); - } + ChartState.MakeDots(x, y, timeInMs); } public void DrawLastMovement() { if (EnableLastValue.Checked) { - SensitivityChart.DrawLastMovementValue(); - VelocityChart.DrawLastMovementValue(); - GainChart.DrawLastMovementValue(); + ChartState.DrawLastMovement(); } } public void Bind() { - if (Combined) - { - SensitivityChart.Bind(AccelData.Combined.AccelPoints); - VelocityChart.Bind(AccelData.Combined.VelocityPoints); - GainChart.Bind(AccelData.Combined.GainPoints); - } - else - { - SensitivityChart.BindXY(AccelData.X.AccelPoints, AccelData.Y.AccelPoints); - VelocityChart.BindXY(AccelData.X.VelocityPoints, AccelData.Y.VelocityPoints); - GainChart.BindXY(AccelData.X.GainPoints, AccelData.Y.GainPoints); - } + ChartState.Bind(); } public void ShowActive(DriverSettings driverSettings) { - if (driverSettings.combineMagnitudes) - { - ShowCombined(); - } - else - { - ShowXandYSeparate(); - } + ChartState = ChartStateManager.DetermineState(driverSettings); + ChartState.Activate(); + UpdateFormWidth(); + Bind(); } public void SetWidened() { - SensitivityChart.SetWidened(); - VelocityChart.SetWidened(); - GainChart.SetWidened(); + ChartState.SetWidened(); UpdateFormWidth(); AlignWriteButton(); } public void SetNarrowed() { - SensitivityChart.SetNarrowed(); - VelocityChart.SetNarrowed(); - GainChart.SetNarrowed(); + ChartState.SetNarrowed(); UpdateFormWidth(); AlignWriteButton(); } + public void Calculate(ManagedAccel accel, DriverSettings settings) + { + ChartState.SetUpCalculate(settings); + ChartState.Calculate(accel, settings); + } + + private static void SetupCharts( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + EstimatedPoints estimated, + EstimatedPoints estimatedX, + EstimatedPoints estimatedY) + { + sensitivityChart.SetPointBinds(estimated.Sensitivity, estimatedX.Sensitivity, estimatedY.Sensitivity); + velocityChart.SetPointBinds(estimated.Velocity, estimatedX.Velocity, estimatedY.Velocity); + gainChart.SetPointBinds(estimated.Gain, estimatedX.Gain, estimatedY.Gain); + + sensitivityChart.SetTop(0); + velocityChart.SetHeight(sensitivityChart.Height); + velocityChart.SetTop(sensitivityChart.Height + Constants.ChartSeparationVertical); + gainChart.SetHeight(sensitivityChart.Height); + gainChart.SetTop(velocityChart.Top + velocityChart.Height + Constants.ChartSeparationVertical); + + sensitivityChart.Show(); + } + private void OnEnableClick(object sender, EventArgs e) { EnableVelocityAndGain.Checked = !EnableVelocityAndGain.Checked; @@ -180,67 +191,28 @@ namespace grapher { if (!EnableLastValue.Checked) { - SensitivityChart.ClearLastValue(); - VelocityChart.ClearLastValue(); - GainChart.ClearLastValue(); + ChartState.ClearLastValue(); } } private void ShowVelocityAndGain() { - VelocityChart.Show(); - GainChart.Show(); - ContaingForm.Height = SensitivityChart.Height + - Constants.ChartSeparationVertical + - VelocityChart.Height + - Constants.ChartSeparationVertical + - GainChart.Height + - FormBorderHeight; + ChartState.ShowVelocityAndGain(ContainingForm, FormBorderHeight); } private void HideVelocityAndGain() { - VelocityChart.Hide(); - GainChart.Hide(); - ContaingForm.Height = SensitivityChart.Height + FormBorderHeight; - } - - private void ShowXandYSeparate() - { - if (Combined) - { - Combined = false; - - SensitivityChart.SetSeparate(); - VelocityChart.SetSeparate(); - GainChart.SetSeparate(); - UpdateFormWidth(); - Bind(); - } - } - - private void ShowCombined() - { - if (!Combined) - { - Combined = true; - - SensitivityChart.SetCombined(); - VelocityChart.SetCombined(); - GainChart.SetCombined(); - UpdateFormWidth(); - Bind(); - } + ChartState.HideVelocityAndGain(ContainingForm, FormBorderHeight); } private void UpdateFormWidth() { - ContaingForm.Width = SensitivityChart.Left + SensitivityChart.Width; + ContainingForm.Width = ChartState.SensitivityChart.Left + ChartState.SensitivityChart.Width; } private void AlignWriteButton() { - WriteButton.Left = SensitivityChart.Left / 2 - WriteButton.Width / 2; + WriteButton.Left = ChartState.SensitivityChart.Left / 2 - WriteButton.Width / 2; } #endregion Methods diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs new file mode 100644 index 0000000..ea67e83 --- /dev/null +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -0,0 +1,104 @@ +using grapher.Models.Calculations; +using grapher.Models.Serialized; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Charts.ChartState +{ + public abstract class ChartState + { + public ChartState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData, + AccelCalculator calculator) + { + SensitivityChart = sensitivityChart; + VelocityChart = velocityChart; + GainChart = gainChart; + Data = accelData; + Calculator = calculator; + TwoDotsPerGraph = false; + } + + public ChartXY SensitivityChart { get; } + + public ChartXY VelocityChart { get; } + + public ChartXY GainChart { get; } + + public AccelData Data { get; } + + public AccelCalculator Calculator { get; } + + public virtual DriverSettings Settings { get; set; } + + internal bool TwoDotsPerGraph { get; set; } + + public abstract void MakeDots(int x, int y, double timeInMs); + + public abstract void Bind(); + + public abstract void Activate(); + + public abstract void Calculate(ManagedAccel accel, DriverSettings settings); + + public virtual void SetUpCalculate(DriverSettings settings) + { + Data.Clear(); + Calculator.ScaleByMouseSettings(); + } + + public void DrawLastMovement() + { + SensitivityChart.DrawLastMovementValue(TwoDotsPerGraph); + VelocityChart.DrawLastMovementValue(TwoDotsPerGraph); + GainChart.DrawLastMovementValue(TwoDotsPerGraph); + } + + public void SetWidened() + { + SensitivityChart.SetWidened(); + VelocityChart.SetWidened(); + GainChart.SetWidened(); + } + + public void SetNarrowed() + { + SensitivityChart.SetNarrowed(); + VelocityChart.SetNarrowed(); + GainChart.SetNarrowed(); + } + + public void ClearLastValue() + { + SensitivityChart.ClearLastValue(); + VelocityChart.ClearLastValue(); + GainChart.ClearLastValue(); + } + + public void ShowVelocityAndGain(Form form, int borderHeight) + { + VelocityChart.Show(); + GainChart.Show(); + form.Height = SensitivityChart.Height + + Constants.ChartSeparationVertical + + VelocityChart.Height + + Constants.ChartSeparationVertical + + GainChart.Height + + borderHeight; + } + + public void HideVelocityAndGain(Form form, int borderHeight) + { + VelocityChart.Hide(); + GainChart.Hide(); + form.Height = SensitivityChart.Height + borderHeight; + } + } +} diff --git a/grapher/Models/Charts/ChartState/ChartStateManager.cs b/grapher/Models/Charts/ChartState/ChartStateManager.cs new file mode 100644 index 0000000..54d2e81 --- /dev/null +++ b/grapher/Models/Charts/ChartState/ChartStateManager.cs @@ -0,0 +1,78 @@ +using grapher.Models.Calculations; +using grapher.Models.Serialized; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Charts.ChartState +{ + public class ChartStateManager + { + public ChartStateManager( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChat, + AccelData accelData, + AccelCalculator accelCalculator) + { + CombinedState = new CombinedState( + sensitivityChart, + velocityChart, + gainChat, + accelData, + accelCalculator); + + XYOneGraphState = new XYOneGraphState( + sensitivityChart, + velocityChart, + gainChat, + accelData, + accelCalculator); + + XYTwoGraphState = new XYTwoGraphState( + sensitivityChart, + velocityChart, + gainChat, + accelData, + accelCalculator); + } + + private CombinedState CombinedState { get; } + + private XYOneGraphState XYOneGraphState { get; } + + private XYTwoGraphState XYTwoGraphState { get; } + + + public ChartState DetermineState(DriverSettings settings) + { + ChartState chartState; + + if (settings.combineMagnitudes) + { + if (settings.sensitivity.x != settings.sensitivity.y) + { + chartState = XYOneGraphState; + } + else + { + chartState = CombinedState; + } + } + else + { + chartState = XYTwoGraphState; + } + + chartState.Settings = settings; + return chartState; + } + + public ChartState InitialState() + { + return CombinedState; + } + } +} diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs new file mode 100644 index 0000000..17cd68a --- /dev/null +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -0,0 +1,46 @@ +using grapher.Models.Calculations; +using grapher.Models.Serialized; + +namespace grapher.Models.Charts.ChartState +{ + public class CombinedState : ChartState + { + public CombinedState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData, + AccelCalculator accelCalculator) + : base( + sensitivityChart, + velocityChart, + gainChart, + accelData, + accelCalculator) + { } + + public override void Activate() + { + SensitivityChart.SetCombined(); + VelocityChart.SetCombined(); + GainChart.SetCombined(); + } + + public override void MakeDots(int x, int y, double timeInMs) + { + Data.CalculateDots(x, y, timeInMs); + } + + public override void Bind() + { + SensitivityChart.Bind(Data.Combined.AccelPoints); + VelocityChart.Bind(Data.Combined.VelocityPoints); + GainChart.Bind(Data.Combined.GainPoints); + } + + public override void Calculate(ManagedAccel accel, DriverSettings settings) + { + Calculator.Calculate(Data.Combined, accel, settings.sensitivity.x, Calculator.MagnitudesCombined); + } + } +} diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs new file mode 100644 index 0000000..bbc0c28 --- /dev/null +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -0,0 +1,48 @@ +using grapher.Models.Calculations; +using grapher.Models.Serialized; + +namespace grapher.Models.Charts.ChartState +{ + public class XYOneGraphState : ChartState + { + public XYOneGraphState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData, + AccelCalculator accelCalculator) + : base( + sensitivityChart, + velocityChart, + gainChart, + accelData, + accelCalculator) + { + TwoDotsPerGraph = true; + } + + public override void Activate() + { + SensitivityChart.SetCombined(); + VelocityChart.SetCombined(); + GainChart.SetCombined(); + } + + public override void MakeDots(int x, int y, double timeInMs) + { + Data.CalculateDotsCombinedDiffSens(x, y, timeInMs, Settings); + } + + public override void Bind() + { + SensitivityChart.BindXYCombined(Data.X.AccelPoints, Data.Y.AccelPoints); + VelocityChart.BindXYCombined(Data.X.VelocityPoints, Data.Y.VelocityPoints); + GainChart.BindXYCombined(Data.X.GainPoints, Data.Y.GainPoints); + } + + public override void Calculate(ManagedAccel accel, DriverSettings settings) + { + Calculator.CalculateCombinedDiffSens(Data, accel, settings, Calculator.MagnitudesCombined); + } + } +} diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs new file mode 100644 index 0000000..69dc335 --- /dev/null +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -0,0 +1,76 @@ +using grapher.Models.Calculations; +using grapher.Models.Serialized; +using System; + +namespace grapher.Models.Charts.ChartState +{ + public class XYTwoGraphState : ChartState + { + private DriverSettings _settings; + + public XYTwoGraphState( + ChartXY sensitivityChart, + ChartXY velocityChart, + ChartXY gainChart, + AccelData accelData, + AccelCalculator accelCalculator) + : base( + sensitivityChart, + velocityChart, + gainChart, + accelData, + accelCalculator) + { } + + public override DriverSettings Settings + { + get { return _settings; } + set + { + _settings = value; + ShouldStripSens = AccelCalculator.ShouldStripSens(ref value); + if (ShouldStripSens) + { + Sensitivity = AccelCalculator.GetSens(ref value); + } + } + } + + private bool ShouldStripSens { get; set; } + + private (double, double) Sensitivity { get; set; } + + public override void Activate() + { + SensitivityChart.SetSeparate(); + VelocityChart.SetSeparate(); + GainChart.SetSeparate(); + } + + public override void MakeDots(int x, int y, double timeInMs) + { + double xCalc = x; + double yCalc = y; + + if (ShouldStripSens) + { + (xCalc, yCalc) = AccelCalculator.StripSens(xCalc, yCalc, Sensitivity.Item1, Sensitivity.Item2); + } + + Data.CalculateDotsXY((int)Math.Round(xCalc), (int)Math.Round(yCalc), timeInMs); + } + + public override void Bind() + { + SensitivityChart.BindXY(Data.X.AccelPoints, Data.Y.AccelPoints); + VelocityChart.BindXY(Data.X.VelocityPoints, Data.Y.VelocityPoints); + GainChart.BindXY(Data.X.GainPoints, Data.Y.GainPoints); + } + + public override void Calculate(ManagedAccel accel, DriverSettings settings) + { + Calculator.Calculate(Data.X, accel, settings.sensitivity.x, Calculator.MagnitudesX); + Calculator.Calculate(Data.Y, accel, settings.sensitivity.y, Calculator.MagnitudesY); + } + } +} diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 1360409..fdd0258 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -117,12 +117,17 @@ namespace grapher chart.Titles[0].Font = new System.Drawing.Font(chart.Titles[0].Font.Name, 9.0f, System.Drawing.FontStyle.Italic); } - public static void DrawPoint(Chart chart, PointData point) + public static void DrawPoint(Chart chart, PointData pointOne, PointData pointTwo = null) { if (chart.Visible) { - point.Get(out var x, out var y); + pointOne.Get(out var x, out var y); chart.Series[1].Points.DataBindXY(x, y); + if (pointTwo != null) + { + pointTwo.Get(out x, out y); + chart.Series[3].Points.DataBindXY(x, y); + } chart.Update(); } } @@ -134,11 +139,18 @@ namespace grapher YPointData = y; } - public void DrawLastMovementValue() + public void DrawLastMovementValue(bool twoDotsPerGraph = false) { if(Combined) { - DrawPoint(ChartX, CombinedPointData); + if (twoDotsPerGraph) + { + DrawPoint(ChartX, XPointData, YPointData); + } + else + { + DrawPoint(ChartX, CombinedPointData); + } } else { @@ -164,6 +176,12 @@ namespace grapher ChartY.Series[0].Points.DataBindXY(dataY.Keys, dataY.Values); } + public void BindXYCombined(IDictionary dataX, IDictionary dataY) + { + ChartX.Series[0].Points.DataBindXY(dataX.Keys, dataX.Values); + ChartX.Series[2].Points.DataBindXY(dataY.Keys, dataY.Values); + } + public void SetCombined() { if (!Combined) |