summaryrefslogtreecommitdiff
path: root/grapher/Models
diff options
context:
space:
mode:
Diffstat (limited to 'grapher/Models')
-rw-r--r--grapher/Models/AccelGUI.cs96
-rw-r--r--grapher/Models/AccelGUIFactory.cs317
-rw-r--r--grapher/Models/Calculations/AccelCalculator.cs25
-rw-r--r--grapher/Models/Calculations/AccelChartData.cs12
-rw-r--r--grapher/Models/Calculations/AccelData.cs10
-rw-r--r--grapher/Models/Charts/AccelCharts.cs35
-rw-r--r--grapher/Models/Charts/ChartXY.cs8
-rw-r--r--grapher/Models/Charts/EstimatedPoints.cs8
-rw-r--r--grapher/Models/Fields/Field.cs61
-rw-r--r--grapher/Models/Fields/FieldXY.cs32
-rw-r--r--grapher/Models/Mouse/MouseWatcher.cs15
-rw-r--r--grapher/Models/Mouse/PointData.cs12
-rw-r--r--grapher/Models/Options/AccelOptionSet.cs164
-rw-r--r--grapher/Models/Options/AccelOptions.cs91
-rw-r--r--grapher/Models/Options/AccelTypeOptions.cs191
-rw-r--r--grapher/Models/Options/ActiveValueLabel.cs26
-rw-r--r--grapher/Models/Options/ActiveValueLabelXY.cs28
-rw-r--r--grapher/Models/Options/ApplyOptions.cs184
-rw-r--r--grapher/Models/Options/CapOptions.cs99
-rw-r--r--grapher/Models/Options/Option.cs77
-rw-r--r--grapher/Models/Options/OptionXY.cs17
-rw-r--r--grapher/Models/Serialized/DriverSettings.cs16
-rw-r--r--grapher/Models/Serialized/GUISettings.cs8
-rw-r--r--grapher/Models/Serialized/RawAccelSettings.cs19
-rw-r--r--grapher/Models/Serialized/SettingsManager.cs12
25 files changed, 1292 insertions, 271 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs
index a7d5d49..e9e925f 100644
--- a/grapher/Models/AccelGUI.cs
+++ b/grapher/Models/AccelGUI.cs
@@ -17,53 +17,40 @@ namespace grapher
public class AccelGUI
{
- #region constructors
+ #region Constructors
public AccelGUI(
RawAcceleration accelForm,
AccelCalculator accelCalculator,
AccelCharts accelCharts,
SettingsManager settings,
- AccelOptions accelOptions,
+ ApplyOptions applyOptions,
OptionXY sensitivity,
Option rotation,
- OptionXY weight,
- CapOptions cap,
- OffsetOptions offset,
- Option acceleration,
- Option limtOrExp,
- Option midpoint,
Button writeButton,
Label mouseMoveLabel,
- ToolStripMenuItem scaleMenuItem,
- ToolStripMenuItem autoWriteMenuItem)
+ ToolStripMenuItem scaleMenuItem)
{
AccelForm = accelForm;
AccelCalculator = accelCalculator;
AccelCharts = accelCharts;
- AccelerationOptions = accelOptions;
+ ApplyOptions = applyOptions;
Sensitivity = sensitivity;
Rotation = rotation;
- Weight = weight;
- Cap = cap;
- Offset = offset;
- Acceleration = acceleration;
- LimitOrExponent = limtOrExp;
- Midpoint = midpoint;
WriteButton = writeButton;
ScaleMenuItem = scaleMenuItem;
Settings = settings;
Settings.Startup();
- UpdateGraph();
+ RefreshOnRead();
MouseWatcher = new MouseWatcher(AccelForm, mouseMoveLabel, AccelCharts);
ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick);
}
- #endregion constructors
+ #endregion Constructors
- #region properties
+ #region Properties
public RawAcceleration AccelForm { get; }
@@ -73,33 +60,21 @@ namespace grapher
public SettingsManager Settings { get; }
- public AccelOptions AccelerationOptions { get; }
+ public ApplyOptions ApplyOptions { get; }
public OptionXY Sensitivity { get; }
public Option Rotation { get; }
- public OptionXY Weight { get; }
-
- public CapOptions Cap { get; }
-
- public OffsetOptions Offset { get; }
-
- public Option Acceleration { get; }
-
- public Option LimitOrExponent { get; }
-
- public Option Midpoint { get; }
-
public Button WriteButton { get; }
public MouseWatcher MouseWatcher { get; }
public ToolStripMenuItem ScaleMenuItem { get; }
- #endregion properties
+ #endregion Properties
- #region methods
+ #region Methods
public void UpdateActiveSettingsFromFields()
{
@@ -111,29 +86,9 @@ namespace grapher
x = Sensitivity.Fields.X,
y = Sensitivity.Fields.Y
},
- combineMagnitudes = true,
- modes = new Vec2<AccelMode>
- {
- x = (AccelMode)AccelerationOptions.AccelerationIndex
- },
- args = new Vec2<AccelArgs>
- {
- x = new AccelArgs
- {
- offset = Offset.Offset,
- legacy_offset = Offset.LegacyOffset,
- weight = Weight.Fields.X,
- gainCap = Cap.VelocityGainCap,
- scaleCap = Cap.SensitivityCapX,
- accel = Acceleration.Field.Data,
- rate = Acceleration.Field.Data,
- powerScale = Acceleration.Field.Data,
- limit = LimitOrExponent.Field.Data,
- exponent = LimitOrExponent.Field.Data,
- powerExponent = LimitOrExponent.Field.Data,
- midpoint = Midpoint.Field.Data
- }
- },
+ combineMagnitudes = ApplyOptions.IsWhole,
+ modes = ApplyOptions.GetModes(),
+ args = ApplyOptions.GetArgs(),
minimumTime = .4
};
@@ -144,7 +99,14 @@ namespace grapher
UpdateGraph();
});
});
-
+ RefreshOnRead();
+ }
+
+ public void RefreshOnRead()
+ {
+ AccelCharts.RefreshXY(Settings.RawAccelSettings.AccelerationSettings.combineMagnitudes);
+ UpdateGraph();
+ UpdateShownActiveValues();
}
public void UpdateGraph()
@@ -154,29 +116,23 @@ namespace grapher
Settings.ActiveAccel,
Settings.RawAccelSettings.AccelerationSettings);
AccelCharts.Bind();
- UpdateActiveValueLabels();
}
- public void UpdateActiveValueLabels()
+ public void UpdateShownActiveValues()
{
var settings = Settings.RawAccelSettings.AccelerationSettings;
-
+
Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y);
Rotation.SetActiveValue(settings.rotation);
- AccelerationOptions.SetActiveValue((int)settings.modes.x);
- Offset.SetActiveValue(settings.args.x.offset, settings.args.y.offset);
- Weight.SetActiveValues(settings.args.x.weight, settings.args.x.weight);
- Acceleration.SetActiveValue(settings.args.x.accel); // rate, powerscale
- LimitOrExponent.SetActiveValue(settings.args.x.limit); //exp, powerexp
- Midpoint.SetActiveValue(settings.args.x.midpoint);
- //Cap.SetActiveValues(Settings.ActiveAccel.GainCap, Settings.ActiveAccel.CapX, Settings.ActiveAccel.CapY, Settings.ActiveAccel.GainCapEnabled);
+ ApplyOptions.SetActiveValues(settings);
}
private void OnScaleMenuItemClick(object sender, EventArgs e)
{
UpdateGraph();
}
- #endregion methods
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs
new file mode 100644
index 0000000..230b64d
--- /dev/null
+++ b/grapher/Models/AccelGUIFactory.cs
@@ -0,0 +1,317 @@
+using grapher.Models.Calculations;
+using grapher.Models.Options;
+using grapher.Models.Serialized;
+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.Models
+{
+ public static class AccelGUIFactory
+ {
+ #region Methods
+
+ public static AccelGUI Construct(
+ RawAcceleration form,
+ ManagedAccel activeAccel,
+ Chart accelerationChart,
+ Chart accelerationChartY,
+ Chart velocityChart,
+ Chart velocityChartY,
+ Chart gainChart,
+ Chart gainChartY,
+ ComboBox accelTypeDropX,
+ ComboBox accelTypeDropY,
+ Button writeButton,
+ ToolStripMenuItem showVelocityGainToolStripMenuItem,
+ ToolStripMenuItem wholeVectorToolStripMenuItem,
+ ToolStripMenuItem byVectorComponentToolStripMenuItem,
+ ToolStripMenuItem velocityGainCapToolStripMenuItem,
+ ToolStripMenuItem legacyCapToolStripMenuItem,
+ ToolStripMenuItem gainOffsetToolStripMenuItem,
+ ToolStripMenuItem legacyOffsetToolStripMenuItem,
+ ToolStripMenuItem autoWriteMenuItem,
+ ToolStripMenuItem scaleMenuItem,
+ ToolStripTextBox dpiTextBox,
+ ToolStripTextBox pollRateTextBox,
+ TextBox sensitivityBoxX,
+ TextBox sensitivityBoxY,
+ TextBox rotationBox,
+ TextBox weightBoxX,
+ TextBox weightBoxY,
+ TextBox capBoxX,
+ TextBox capBoxY,
+ TextBox offsetBoxX,
+ TextBox offsetBoxY,
+ TextBox accelerationBoxX,
+ TextBox accelerationBoxY,
+ TextBox limitBoxX,
+ TextBox limitBoxY,
+ TextBox midpointBoxX,
+ TextBox midpointBoxY,
+ CheckBox sensXYLock,
+ CheckBox byComponentXYLock,
+ Label sensitivityLabel,
+ Label rotationLabel,
+ Label weightLabelX,
+ Label weightLabelY,
+ Label capLabelX,
+ Label capLabelY,
+ Label offsetLabelX,
+ Label offsetLabelY,
+ Label constantOneLabelX,
+ Label constantOneLabelY,
+ Label constantTwoLabelX,
+ Label constantTwoLabelY,
+ Label constantThreeLabelX,
+ Label constantThreeLabelY,
+ Label activeValueTitle,
+ Label sensitivityActiveXLabel,
+ Label sensitivityActiveYLabel,
+ Label rotationActiveLabel,
+ Label weightActiveXLabel,
+ Label weightActiveYLabel,
+ Label capActiveXLabel,
+ Label capActiveYLabel,
+ Label offsetActiveLabelX,
+ Label offsetActiveLabelY,
+ Label accelerationActiveLabelX,
+ Label accelerationActiveLabelY,
+ Label limitExpActiveLabelX,
+ Label limitExpActiveLabelY,
+ Label midpointActiveLabelX,
+ Label midpointActiveLabelY,
+ Label accelTypeActiveLabelX,
+ Label accelTypeActiveLabelY,
+ Label optionSetXTitle,
+ Label optionSetYTitle,
+ Label mouseLabel)
+ {
+ var accelCharts = new AccelCharts(
+ form,
+ new ChartXY(accelerationChart, accelerationChartY),
+ new ChartXY(velocityChart, velocityChartY),
+ new ChartXY(gainChart, gainChartY),
+ showVelocityGainToolStripMenuItem);
+
+ var sensitivity = new OptionXY(
+ sensitivityBoxX,
+ sensitivityBoxY,
+ sensXYLock,
+ form,
+ 1,
+ sensitivityLabel,
+ new ActiveValueLabelXY(
+ new ActiveValueLabel(sensitivityActiveXLabel, activeValueTitle),
+ new ActiveValueLabel(sensitivityActiveYLabel, activeValueTitle)),
+ "Sensitivity");
+
+ var rotation = new Option(
+ rotationBox,
+ form,
+ 0,
+ rotationLabel,
+ 0,
+ new ActiveValueLabel(rotationActiveLabel, activeValueTitle),
+ "Rotation");
+
+ var optionSetYLeft = rotation.Left + rotation.Width;
+
+ var weightX = new Option(
+ weightBoxX,
+ form,
+ 1,
+ weightLabelX,
+ 0,
+ new ActiveValueLabel(weightActiveXLabel, activeValueTitle),
+ "Weight");
+
+ var weightY = new Option(
+ weightBoxY,
+ form,
+ 1,
+ weightLabelY,
+ optionSetYLeft,
+ new ActiveValueLabel(weightActiveYLabel, activeValueTitle),
+ "Weight");
+
+ var capX = new Option(
+ capBoxX,
+ form,
+ 0,
+ capLabelX,
+ 0,
+ new ActiveValueLabel(capActiveXLabel, activeValueTitle),
+ "Cap");
+
+ var capY = new Option(
+ capBoxY,
+ form,
+ 0,
+ capLabelY,
+ optionSetYLeft,
+ new ActiveValueLabel(capActiveYLabel, activeValueTitle),
+ "Cap");
+
+ var offsetX = new Option(
+ offsetBoxX,
+ form,
+ 0,
+ offsetLabelX,
+ 0,
+ new ActiveValueLabel(offsetActiveLabelX, activeValueTitle),
+ "Offset");
+
+ var offsetY = new Option(
+ offsetBoxY,
+ form,
+ 0,
+ offsetLabelY,
+ optionSetYLeft,
+ new ActiveValueLabel(offsetActiveLabelY, activeValueTitle),
+ "Offset");
+
+ var offsetOptionsX = new OffsetOptions(
+ gainOffsetToolStripMenuItem,
+ legacyOffsetToolStripMenuItem,
+ offsetX);
+
+ var offsetOptionsY = new OffsetOptions(
+ gainOffsetToolStripMenuItem,
+ legacyOffsetToolStripMenuItem,
+ offsetY);
+
+ // The name and layout of these options is handled by AccelerationOptions object.
+ var accelerationX = new Option(
+ new Field(accelerationBoxX, form, 0),
+ constantOneLabelX,
+ new ActiveValueLabel(accelerationActiveLabelX, activeValueTitle),
+ 0);
+
+ var accelerationY = new Option(
+ new Field(accelerationBoxY, form, 0),
+ constantOneLabelY,
+ new ActiveValueLabel(accelerationActiveLabelY, activeValueTitle),
+ optionSetYLeft);
+
+ var limitOrExponentX = new Option(
+ new Field(limitBoxX, form, 2),
+ constantTwoLabelX,
+ new ActiveValueLabel(limitExpActiveLabelX, activeValueTitle),
+ 0);
+
+ var limitOrExponentY = new Option(
+ new Field(limitBoxY, form, 2),
+ constantTwoLabelY,
+ new ActiveValueLabel(limitExpActiveLabelY, activeValueTitle),
+ optionSetYLeft);
+
+ var midpointX = new Option(
+ new Field(midpointBoxX, form, 0),
+ constantThreeLabelX,
+ new ActiveValueLabel(midpointActiveLabelX, activeValueTitle),
+ 0);
+
+ var midpointY = new Option(
+ new Field(midpointBoxY, form, 0),
+ constantThreeLabelY,
+ new ActiveValueLabel(midpointActiveLabelY, activeValueTitle),
+ optionSetYLeft);
+
+ var accelerationOptionsX = new AccelTypeOptions(
+ accelTypeDropX,
+ new Option[]
+ {
+ offsetX,
+ accelerationX,
+ limitOrExponentX,
+ midpointX,
+ capX,
+ weightX
+ },
+ writeButton,
+ new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitle));
+
+ var accelerationOptionsY = new AccelTypeOptions(
+ accelTypeDropY,
+ new Option[]
+ {
+ offsetY,
+ accelerationY,
+ limitOrExponentY,
+ midpointY,
+ capY,
+ weightY
+ },
+ writeButton,
+ new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitle));
+
+ var capOptionsX = new CapOptions(
+ velocityGainCapToolStripMenuItem,
+ legacyCapToolStripMenuItem,
+ capX);
+
+ var capOptionsY = new CapOptions(
+ velocityGainCapToolStripMenuItem,
+ legacyCapToolStripMenuItem,
+ capY);
+
+ var optionsSetX = new AccelOptionSet(
+ optionSetXTitle,
+ rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
+ accelerationOptionsX,
+ accelerationX,
+ capOptionsX,
+ weightX,
+ offsetOptionsX,
+ limitOrExponentX,
+ midpointX);
+
+ var optionsSetY = new AccelOptionSet(
+ optionSetYTitle,
+ rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
+ accelerationOptionsY,
+ accelerationY,
+ capOptionsY,
+ weightY,
+ offsetOptionsY,
+ limitOrExponentY,
+ midpointY);
+
+ var applyOptions = new ApplyOptions(
+ wholeVectorToolStripMenuItem,
+ byVectorComponentToolStripMenuItem,
+ byComponentXYLock,
+ optionsSetX,
+ optionsSetY);
+
+ var accelCalculator = new AccelCalculator(
+ new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI),
+ new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate));
+
+ var settings = new SettingsManager(
+ activeAccel,
+ accelCalculator.DPI,
+ accelCalculator.PollRate,
+ autoWriteMenuItem);
+
+ return new AccelGUI(
+ form,
+ accelCalculator,
+ accelCharts,
+ settings,
+ applyOptions,
+ sensitivity,
+ rotation,
+ writeButton,
+ mouseLabel,
+ scaleMenuItem);
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs
index 102de8d..4e44902 100644
--- a/grapher/Models/Calculations/AccelCalculator.cs
+++ b/grapher/Models/Calculations/AccelCalculator.cs
@@ -11,11 +11,7 @@ namespace grapher.Models.Calculations
{
public class AccelCalculator
{
- public const int DefaultDPI = 1200;
- public const int DefaultPollRate = 1000;
- public const int Resolution = 100;
- public const double MaxMultiplier = 85;
- public const double XYToCombinedRatio = 1.3;
+ #region Structs
public struct MagnitudeData
{
@@ -24,6 +20,9 @@ namespace grapher.Models.Calculations
public int y;
}
+ #endregion Structs
+
+ #region Constructors
public AccelCalculator(Field dpi, Field pollRate)
{
@@ -31,6 +30,10 @@ namespace grapher.Models.Calculations
PollRate = pollRate;
}
+ #endregion Constructors
+
+ #region Properties
+
public ReadOnlyCollection<MagnitudeData> MagnitudesCombined { get; private set; }
public ReadOnlyCollection<MagnitudeData> MagnitudesX { get; private set; }
@@ -47,6 +50,10 @@ namespace grapher.Models.Calculations
private int Increment { get; set; }
+ #endregion Fields
+
+ #region Methods
+
public void Calculate(AccelData data, ManagedAccel accel, DriverSettings settings)
{
ScaleByMouseSettings();
@@ -171,12 +178,14 @@ namespace grapher.Models.Calculations
public void ScaleByMouseSettings()
{
var dpiPollFactor = DPI.Data / PollRate.Data;
- CombinedMaxVelocity = dpiPollFactor * MaxMultiplier;
- Increment = (int) Math.Floor(CombinedMaxVelocity / Resolution);
- XYMaxVelocity = CombinedMaxVelocity * 1.5;
+ CombinedMaxVelocity = dpiPollFactor * Constants.MaxMultiplier;
+ Increment = (int)Math.Floor(CombinedMaxVelocity / Constants.Resolution);
+ XYMaxVelocity = CombinedMaxVelocity * Constants.XYToCombinedRatio;
MagnitudesCombined = GetMagnitudes();
MagnitudesX = GetMagnitudesX();
MagnitudesY = GetMagnitudesY();
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs
index 20142a7..6b29f16 100644
--- a/grapher/Models/Calculations/AccelChartData.cs
+++ b/grapher/Models/Calculations/AccelChartData.cs
@@ -8,6 +8,8 @@ namespace grapher.Models.Calculations
{
public class AccelChartData
{
+ #region Constructors
+
public AccelChartData()
{
AccelPoints = new SortedDictionary<double, double>();
@@ -17,6 +19,10 @@ namespace grapher.Models.Calculations
OutVelocityToPoints = new Dictionary<double, (double, double, double)>();
}
+ #endregion Constructors
+
+ #region Properties
+
public SortedDictionary<double, double> AccelPoints { get; }
public SortedDictionary<double, double> VelocityPoints { get; }
@@ -27,6 +33,10 @@ namespace grapher.Models.Calculations
public Dictionary<double, (double, double, double)> OutVelocityToPoints { get; }
+ #endregion Properties
+
+ #region Methods
+
public void Clear()
{
AccelPoints.Clear();
@@ -57,5 +67,7 @@ namespace grapher.Models.Calculations
return values;
}
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs
index 683c67e..3e1f987 100644
--- a/grapher/Models/Calculations/AccelData.cs
+++ b/grapher/Models/Calculations/AccelData.cs
@@ -10,6 +10,7 @@ namespace grapher.Models.Calculations
{
public class AccelData
{
+ #region Constructors
public AccelData(
EstimatedPoints combined,
@@ -25,6 +26,10 @@ namespace grapher.Models.Calculations
EstimatedY = y;
}
+ #endregion Constructors
+
+ #region Properties
+
public AccelChartData Combined { get; }
public AccelChartData X { get; }
@@ -37,6 +42,10 @@ namespace grapher.Models.Calculations
private EstimatedPoints EstimatedY { get; }
+ #endregion Properties
+
+ #region Methods
+
public void Clear()
{
Combined.Clear();
@@ -70,5 +79,6 @@ namespace grapher.Models.Calculations
EstimatedY.Gain.Set(inYVelocity, yGain);
}
+ #endregion Methods
}
}
diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs
index 1aa3909..5e4b3de 100644
--- a/grapher/Models/Charts/AccelCharts.cs
+++ b/grapher/Models/Charts/AccelCharts.cs
@@ -14,18 +14,14 @@ 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;
+ #region Constructors
public AccelCharts(
Form form,
ChartXY sensitivityChart,
ChartXY velocityChart,
ChartXY gainChart,
- ToolStripMenuItem enableVelocityAndGain,
- ICollection<CheckBox> checkBoxesXY)
+ ToolStripMenuItem enableVelocityAndGain)
{
Estimated = new EstimatedPoints();
EstimatedX = new EstimatedPoints();
@@ -37,7 +33,6 @@ namespace grapher
VelocityChart = velocityChart;
GainChart = gainChart;
EnableVelocityAndGain = enableVelocityAndGain;
- CheckBoxesXY = checkBoxesXY;
SensitivityChart.SetPointBinds(Estimated.Sensitivity, EstimatedX.Sensitivity, EstimatedY.Sensitivity);
VelocityChart.SetPointBinds(Estimated.Velocity, EstimatedX.Velocity, EstimatedY.Velocity);
@@ -45,9 +40,9 @@ namespace grapher
SensitivityChart.SetTop(0);
VelocityChart.SetHeight(SensitivityChart.Height);
- VelocityChart.SetTop(SensitivityChart.Height + ChartSeparationVertical);
+ VelocityChart.SetTop(SensitivityChart.Height + Constants.ChartSeparationVertical);
GainChart.SetHeight(SensitivityChart.Height);
- GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + ChartSeparationVertical);
+ GainChart.SetTop(VelocityChart.Top + VelocityChart.Height + Constants.ChartSeparationVertical);
Rectangle screenRectangle = ContaingForm.RectangleToScreen(ContaingForm.ClientRectangle);
FormBorderHeight = screenRectangle.Top - ContaingForm.Top;
@@ -60,6 +55,10 @@ namespace grapher
ShowCombined();
}
+ #endregion Constructors
+
+ #region Properties
+
public Form ContaingForm { get; }
public ChartXY SensitivityChart { get; }
@@ -78,12 +77,14 @@ namespace grapher
private EstimatedPoints EstimatedY { get; }
- private ICollection<CheckBox> CheckBoxesXY { get; }
-
private bool Combined { get; set; }
private int FormBorderHeight { get; }
+ #endregion Properties
+
+ #region Methods
+
public void MakeDots(int x, int y, double timeInMs)
{
if (Combined)
@@ -119,9 +120,9 @@ namespace grapher
}
}
- public void RefreshXY()
+ public void RefreshXY(bool isWhole)
{
- if (CheckBoxesXY.All(box => box.Checked))
+ if (isWhole)
{
ShowCombined();
}
@@ -152,10 +153,10 @@ namespace grapher
{
VelocityChart.Show();
GainChart.Show();
- ContaingForm.Height = SensitivityChart.Height +
- ChartSeparationVertical +
+ ContaingForm.Height = SensitivityChart.Height +
+ Constants.ChartSeparationVertical +
VelocityChart.Height +
- ChartSeparationVertical +
+ Constants.ChartSeparationVertical +
GainChart.Height +
FormBorderHeight;
}
@@ -199,5 +200,7 @@ namespace grapher
{
ContaingForm.Width = SensitivityChart.Left + SensitivityChart.Width;
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs
index 81874a2..6a65e41 100644
--- a/grapher/Models/Charts/ChartXY.cs
+++ b/grapher/Models/Charts/ChartXY.cs
@@ -15,12 +15,6 @@ namespace grapher
{
public class ChartXY
{
- #region Consts
-
- public const int ChartSeparationHorizontal = 10;
-
- #endregion Consts
-
#region Constructors
public ChartXY(Chart chartX, Chart chartY)
@@ -31,7 +25,7 @@ namespace grapher
ChartY.Top = ChartX.Top;
ChartY.Height = ChartX.Height;
ChartY.Width = ChartX.Width;
- ChartY.Left = ChartX.Left + ChartX.Width + ChartSeparationHorizontal;
+ ChartY.Left = ChartX.Left + ChartX.Width + Constants.ChartSeparationHorizontal;
SetupChart(ChartX);
SetupChart(ChartY);
diff --git a/grapher/Models/Charts/EstimatedPoints.cs b/grapher/Models/Charts/EstimatedPoints.cs
index fa0718b..9ff0e5b 100644
--- a/grapher/Models/Charts/EstimatedPoints.cs
+++ b/grapher/Models/Charts/EstimatedPoints.cs
@@ -9,6 +9,8 @@ namespace grapher.Models.Charts
{
public class EstimatedPoints
{
+ #region Constructors
+
public EstimatedPoints()
{
Sensitivity = new PointData();
@@ -16,10 +18,16 @@ namespace grapher.Models.Charts
Gain = new PointData();
}
+ #endregion Constructors
+
+ #region Properties
+
public PointData Sensitivity { get; }
public PointData Velocity { get; }
public PointData Gain { get; }
+
+ #endregion Properties
}
}
diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs
index 1810081..6f38314 100644
--- a/grapher/Models/Fields/Field.cs
+++ b/grapher/Models/Fields/Field.cs
@@ -10,13 +10,7 @@ namespace grapher
{
public class Field
{
- #region Constants
-
- public const string DefaultFormatString = "0.#########";
-
- #endregion Constants
-
- #region Enums
+ #region Enumerations
public enum FieldState
{
@@ -27,8 +21,7 @@ namespace grapher
Unavailable,
}
- #endregion Enums
-
+ #endregion Enumerations
#region Constructors
@@ -40,7 +33,7 @@ namespace grapher
DefaultData = defaultData;
State = FieldState.Undefined;
ContainingForm = containingForm;
- FormatString = DefaultFormatString;
+ FormatString = Constants.DefaultFieldFormatString;
box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown);
box.Leave += new System.EventHandler(FocusLeave);
@@ -65,6 +58,54 @@ namespace grapher
public FieldState PreviousState { get; private set; }
+ public int Top
+ {
+ get
+ {
+ return Box.Top;
+ }
+ set
+ {
+ Box.Top = value;
+ }
+ }
+
+ public int Height
+ {
+ get
+ {
+ return Box.Height;
+ }
+ set
+ {
+ Box.Height = value;
+ }
+ }
+
+ public int Left
+ {
+ get
+ {
+ return Box.Left;
+ }
+ set
+ {
+ Box.Left = value;
+ }
+ }
+
+ public int Width
+ {
+ get
+ {
+ return Box.Width;
+ }
+ set
+ {
+ Box.Width = value;
+ }
+ }
+
private double DefaultData { get; }
#endregion Properties
diff --git a/grapher/Models/Fields/FieldXY.cs b/grapher/Models/Fields/FieldXY.cs
index 609af9d..826be27 100644
--- a/grapher/Models/Fields/FieldXY.cs
+++ b/grapher/Models/Fields/FieldXY.cs
@@ -9,30 +9,32 @@ namespace grapher
{
public class FieldXY
{
- public const int DefaultSeparation = 4;
+ #region Constructors
- public const string ShortenedFormatString = "0.###";
-
- public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData, AccelCharts accelCharts)
+ 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;
+ YField.FormatString = Constants.ShortenedFormatString;
LockCheckBox = lockCheckBox;
LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged);
- AccelCharts = accelCharts;
- XField.Box.Width = (YField.Box.Left + YField.Box.Width - XField.Box.Left - DefaultSeparation) / 2;
+ XField.Box.Width = (YField.Box.Left + YField.Box.Width - XField.Box.Left - Constants.DefaultFieldSeparation) / 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;
+ YField.Box.Left = XField.Box.Left + XField.Box.Width + Constants.DefaultFieldSeparation;
CombinedWidth = DefaultWidthX + DefaultWidthY + YField.Box.Left - (XField.Box.Left + DefaultWidthX);
SetCombined();
}
+
+ #endregion Constructors
+
+ #region Properties
+
public double X
{
get => XField.Data;
@@ -59,8 +61,6 @@ namespace grapher
public Field YField { get; }
- private AccelCharts AccelCharts { get; }
-
private bool Combined { get; set; }
private int DefaultWidthX { get; }
@@ -69,6 +69,10 @@ namespace grapher
private int CombinedWidth { get; }
+ #endregion Properties
+
+ #region Methods
+
private void CheckChanged(object sender, EventArgs e)
{
if (LockCheckBox.CheckState == CheckState.Checked)
@@ -79,8 +83,6 @@ namespace grapher
{
SetSeparate();
}
-
- AccelCharts.RefreshXY();
}
public void SetCombined()
@@ -89,7 +91,7 @@ namespace grapher
YField.SetToUnavailable();
YField.Box.Hide();
XField.Box.Width = CombinedWidth;
- XField.FormatString = Field.DefaultFormatString;
+ XField.FormatString = Constants.DefaultFieldFormatString;
}
public void SetSeparate()
@@ -99,7 +101,7 @@ namespace grapher
XField.Box.Width = DefaultWidthX;
YField.Box.Width = DefaultWidthY;
- XField.FormatString = ShortenedFormatString;
+ XField.FormatString = Constants.ShortenedFormatString;
if (XField.State == Field.FieldState.Default)
{
@@ -131,5 +133,7 @@ namespace grapher
XField.Box.Hide();
YField.Box.Hide();
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs
index fea4e2d..6f6b776 100644
--- a/grapher/Models/Mouse/MouseWatcher.cs
+++ b/grapher/Models/Mouse/MouseWatcher.cs
@@ -11,6 +11,7 @@ namespace grapher.Models.Mouse
{
public class MouseWatcher
{
+ #region External
/// <summary>
/// Enumeration containing HID usage page flags.
/// </summary>
@@ -677,6 +678,10 @@ namespace grapher.Models.Mouse
[DllImport("user32.dll")]
public static extern int GetRawInputData(IntPtr hRawInput, RawInputCommand uiCommand, out RawInput pData, ref int pcbSize, int cbSizeHeader);
+ #endregion External
+
+ #region Constructors
+
public MouseWatcher(Form containingForm, Label display, AccelCharts accelCharts)
{
ContainingForm = containingForm;
@@ -695,6 +700,10 @@ namespace grapher.Models.Mouse
PollTime = 1;
}
+ #endregion Constructors
+
+ #region Properties
+
private Form ContainingForm { get; }
private Label Display { get; }
@@ -703,6 +712,10 @@ namespace grapher.Models.Mouse
private double PollTime { get; }
+ #endregion Properties
+
+ #region Methods
+
public void OnMouseMove(int x, int y, double timeInMs)
{
Display.Text = $"Last (x, y): ({x}, {y})";
@@ -723,5 +736,7 @@ namespace grapher.Models.Mouse
}
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Mouse/PointData.cs b/grapher/Models/Mouse/PointData.cs
index 12a6e73..3641c23 100644
--- a/grapher/Models/Mouse/PointData.cs
+++ b/grapher/Models/Mouse/PointData.cs
@@ -8,6 +8,8 @@ namespace grapher.Models.Mouse
{
public class PointData
{
+ #region Constructors
+
public PointData()
{
Lock = new Object();
@@ -15,6 +17,10 @@ namespace grapher.Models.Mouse
Y = new double[] { 0 };
}
+ #endregion Constructors
+
+ #region Properties
+
public Object Lock { get; }
private double[] X { get; set; }
@@ -29,6 +35,10 @@ namespace grapher.Models.Mouse
}
}
+ #endregion Properties
+
+ #region Methods
+
public void Get(out double[] x, out double[] y)
{
lock(Lock)
@@ -37,5 +47,7 @@ namespace grapher.Models.Mouse
y = Y;
}
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs
new file mode 100644
index 0000000..838917c
--- /dev/null
+++ b/grapher/Models/Options/AccelOptionSet.cs
@@ -0,0 +1,164 @@
+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.Options
+{
+ public class AccelOptionSet
+ {
+ public AccelOptionSet(
+ Label titleLabel,
+ int topAnchor,
+ AccelTypeOptions accelTypeOptions,
+ Option acceleration,
+ CapOptions cap,
+ Option weight,
+ OffsetOptions offset,
+ Option limitOrExp,
+ Option midpoint)
+ {
+ TitleLabel = titleLabel;
+ TopAnchor = topAnchor;
+ AccelTypeOptions = accelTypeOptions;
+ Acceleration = acceleration;
+ Cap = cap;
+ Weight = weight;
+ Offset = offset;
+ LimitOrExponent = limitOrExp;
+ Midpoint = midpoint;
+
+ AccelTypeOptions.ShowFullText();
+
+ TitleLabel.Top = TopAnchor;
+ IsTitleMode = true;
+ SetRegularMode();
+ }
+
+ public int TopAnchor { get; }
+
+ public Label TitleLabel { get; }
+
+ public AccelTypeOptions AccelTypeOptions { get; }
+
+ public Option Acceleration { get; }
+
+ public CapOptions Cap { get; }
+
+ public Option Weight { get; }
+
+ public OffsetOptions Offset { get; }
+
+ public Option LimitOrExponent { get; }
+
+ public Option Midpoint { get; }
+
+ public bool IsTitleMode { get; private set; }
+
+ public void SetRegularMode()
+ {
+ if (IsTitleMode)
+ {
+ IsTitleMode = false;
+
+ HideTitle();
+ AccelTypeOptions.Left = Acceleration.Left;
+ AccelTypeOptions.Width = Acceleration.Width;
+ AccelTypeOptions.ShowFullText();
+ }
+ }
+
+ public void SetTitleMode(string title)
+ {
+ TitleLabel.Text = title;
+
+ if (!IsTitleMode)
+ {
+ IsTitleMode = true;
+
+ AccelTypeOptions.Left = Acceleration.Field.Left;
+ AccelTypeOptions.Width = Acceleration.Field.Width;
+ AccelTypeOptions.ShowShortenedText();
+ DisplayTitle();
+ }
+ }
+
+ public void Hide()
+ {
+ TitleLabel.Hide();
+ AccelTypeOptions.Hide();
+ }
+
+ public void Show()
+ {
+ if (IsTitleMode)
+ {
+ TitleLabel.Show();
+ }
+
+ AccelTypeOptions.Show();
+ }
+
+ public void DisplayTitle()
+ {
+ TitleLabel.Show();
+
+ SetOptionsTop(TitleLabel.Top + TitleLabel.Height + Constants.OptionVerticalSeperation);
+ }
+
+ public void HideTitle()
+ {
+ TitleLabel.Hide();
+
+ SetOptionsTop(TopAnchor);
+ }
+
+ public void SetArgs(AccelArgs args)
+ {
+ args.accel = Acceleration.Field.Data;
+ args.rate = Acceleration.Field.Data;
+ args.powerScale = Acceleration.Field.Data;
+ args.gainCap = Cap.VelocityGainCap;
+ args.scaleCap = Cap.SensitivityCap;
+ args.limit = LimitOrExponent.Field.Data;
+ args.exponent = LimitOrExponent.Field.Data;
+ args.powerExponent = LimitOrExponent.Field.Data;
+ args.offset = Offset.Offset;
+ args.legacy_offset = Offset.LegacyOffset;
+ args.midpoint = Midpoint.Field.Data;
+ args.weight = Weight.Field.Data;
+ }
+
+ public AccelArgs GenerateArgs()
+ {
+ AccelArgs args = new AccelArgs();
+ SetArgs(args);
+ return args;
+ }
+
+ public void SetActiveValues(int mode, AccelArgs args)
+ {
+ AccelTypeOptions.SetActiveValue(mode);
+ Weight.SetActiveValue(args.weight);
+ Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0);
+ Offset.SetActiveValue(args.offset, args.legacy_offset);
+ Acceleration.SetActiveValue(args.accel);
+ LimitOrExponent.SetActiveValue(args.exponent);
+ Midpoint.SetActiveValue(args.midpoint);
+ }
+
+ private void SetOptionsTop(int top)
+ {
+ AccelTypeOptions.Top = top;
+ Acceleration.Top = AccelTypeOptions.Top + AccelTypeOptions.Height + Constants.OptionVerticalSeperation;
+ Cap.SnapTo(Acceleration);
+ Weight.SnapTo(Cap);
+ Offset.OffsetOption.SnapTo(Weight);
+ LimitOrExponent.SnapTo(Offset.OffsetOption);
+ Midpoint.SnapTo(LimitOrExponent);
+ }
+ }
+}
diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs
deleted file mode 100644
index 6b98274..0000000
--- a/grapher/Models/Options/AccelOptions.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-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
- {
- public const int PossibleOptionsCount = 4;
- public const int PossibleOptionsXYCount = 2;
-
- 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);
-
- 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 > 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;
- ActiveValueLabel = activeValueLabel;
-
- Layout("Off");
- }
-
- 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; }
-
- 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);
- }
- }
-}
diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs
new file mode 100644
index 0000000..5342f4b
--- /dev/null
+++ b/grapher/Models/Options/AccelTypeOptions.cs
@@ -0,0 +1,191 @@
+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 AccelTypeOptions
+ {
+ #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 AccelTypeOptions(
+ ComboBox accelDropdown,
+ Option[] options,
+ 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.");
+ }
+
+ Options = options;
+ WriteButton = writeButton;
+ ActiveValueLabel = activeValueLabel;
+
+ Layout("Off");
+ ShowingDefault = true;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public Button WriteButton { get; }
+
+ public ComboBox AccelDropdown { get; }
+
+ public int AccelerationIndex
+ {
+ get
+ {
+ return AccelerationType.Index;
+ }
+ }
+
+ public LayoutBase AccelerationType { get; private set; }
+
+ public ActiveValueLabel ActiveValueLabel { get; }
+
+ public Option[] Options { get; }
+
+ public int Top
+ {
+ get
+ {
+ return AccelDropdown.Top;
+ }
+ set
+ {
+ AccelDropdown.Top = value;
+ }
+ }
+
+ public int Height
+ {
+ get
+ {
+ return AccelDropdown.Height;
+ }
+ set
+ {
+ AccelDropdown.Height = value;
+ }
+ }
+
+ public int Left
+ {
+ get
+ {
+ return AccelDropdown.Left;
+ }
+ set
+ {
+ AccelDropdown.Left = value;
+ }
+ }
+
+ public int Width
+ {
+ get
+ {
+ return AccelDropdown.Width;
+ }
+ set
+ {
+ AccelDropdown.Width = value;
+ }
+ }
+
+ private bool ShowingDefault { get; set; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public void Hide()
+ {
+ AccelDropdown.Hide();
+
+ foreach(var option in Options)
+ {
+ option.Hide();
+ }
+ }
+
+ public void Show()
+ {
+ AccelDropdown.Show();
+ Layout();
+ }
+
+ public void SetActiveValue(int index)
+ {
+ var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name;
+ ActiveValueLabel.SetValue(name);
+ }
+
+ public void ShowFullText()
+ {
+ if (ShowingDefault)
+ {
+ AccelDropdown.Text = Constants.AccelDropDownDefaultFullText;
+ }
+ }
+
+ public void ShowShortenedText()
+ {
+ if (ShowingDefault)
+ {
+ AccelDropdown.Text = Constants.AccelDropDownDefaultShortText;
+ }
+ }
+
+ private void OnIndexChanged(object sender, EventArgs e)
+ {
+ var accelerationTypeString = AccelDropdown.SelectedItem.ToString();
+ Layout(accelerationTypeString);
+ ShowingDefault = false;
+ }
+
+ private void Layout(string type)
+ {
+ AccelerationType = AccelerationTypes[type];
+ Layout();
+ }
+
+ private void Layout()
+ {
+ AccelerationType.Layout(Options, WriteButton);
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Options/ActiveValueLabel.cs b/grapher/Models/Options/ActiveValueLabel.cs
index 138775a..d2b43ab 100644
--- a/grapher/Models/Options/ActiveValueLabel.cs
+++ b/grapher/Models/Options/ActiveValueLabel.cs
@@ -10,25 +10,37 @@ namespace grapher.Models.Options
{
public class ActiveValueLabel
{
- public const string DefaultFormatString = "0.######";
- public static readonly Color ActiveValueFontColor = Color.FromArgb(255, 65, 65, 65);
+ #region Constants
+
+
+ #endregion Constants
+
+ #region Fields
private string _prefix;
private string _value;
+ #endregion Fields
+
+ #region Constructors
+
public ActiveValueLabel(Label valueLabel, Label centeringLabel)
{
ValueLabel = valueLabel;
- ValueLabel.ForeColor = ActiveValueFontColor;
+ ValueLabel.ForeColor = Constants.ActiveValueFontColor;
Left = centeringLabel.Left;
Width = centeringLabel.Width;
ValueLabel.AutoSize = false;
ValueLabel.TextAlign = ContentAlignment.MiddleCenter;
- FormatString = DefaultFormatString;
+ FormatString = Constants.DefaultActiveValueFormatString;
Prefix = string.Empty;
}
+ #endregion Constructors
+
+ #region Properties
+
public Label ValueLabel { get; }
public string FormatString { get; set; }
@@ -79,6 +91,10 @@ namespace grapher.Models.Options
}
}
+ #endregion Properties
+
+ #region Methods
+
public void Hide()
{
ValueLabel.Hide();
@@ -103,5 +119,7 @@ namespace grapher.Models.Options
{
ValueLabel.Text = string.IsNullOrWhiteSpace(Prefix) ? Value: $"{Prefix}: {Value}";
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/ActiveValueLabelXY.cs b/grapher/Models/Options/ActiveValueLabelXY.cs
index 12506e9..c8caddf 100644
--- a/grapher/Models/Options/ActiveValueLabelXY.cs
+++ b/grapher/Models/Options/ActiveValueLabelXY.cs
@@ -8,8 +8,12 @@ namespace grapher.Models.Options
{
public class ActiveValueLabelXY
{
- public const int ActiveLabelXYSeparation = 2;
- public const string ShortenedFormatString = "0.###";
+ #region Constants
+
+
+ #endregion Constants
+
+ #region Constructors
public ActiveValueLabelXY(
ActiveValueLabel x,
@@ -19,16 +23,20 @@ namespace grapher.Models.Options
Y = y;
FullWidth = x.Width;
- ShortenedWidth = (FullWidth - ActiveLabelXYSeparation) / 2;
+ ShortenedWidth = (FullWidth - Constants.ActiveLabelXYSeparation) / 2;
- Y.Left = X.Left + ShortenedWidth + ActiveLabelXYSeparation;
+ Y.Left = X.Left + ShortenedWidth + Constants.ActiveLabelXYSeparation;
Y.Width = ShortenedWidth;
- Y.FormatString = ShortenedFormatString;
+ Y.FormatString = Constants.ShortenedFormatString;
Combined = false;
SetCombined();
}
+ #endregion Constructors
+
+ #region Properties
+
public ActiveValueLabel X { get; }
public ActiveValueLabel Y { get; }
@@ -39,6 +47,10 @@ namespace grapher.Models.Options
private int ShortenedWidth { get; }
+ #endregion Properties
+
+ #region Methods
+
public void SetValues(double x, double y)
{
X.SetValue(x);
@@ -58,7 +70,7 @@ namespace grapher.Models.Options
{
if (!Combined)
{
- X.FormatString = ActiveValueLabel.DefaultFormatString;
+ X.FormatString = Constants.DefaultActiveValueFormatString;
X.Width = FullWidth;
X.Prefix = string.Empty;
Y.Hide();
@@ -71,7 +83,7 @@ namespace grapher.Models.Options
{
if (Combined)
{
- X.FormatString = ShortenedFormatString;
+ X.FormatString = Constants.ShortenedFormatString;
X.Width = ShortenedWidth;
X.Prefix = "X";
Y.Prefix = "Y";
@@ -80,5 +92,7 @@ namespace grapher.Models.Options
Combined = false;
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs
new file mode 100644
index 0000000..bfbc1ef
--- /dev/null
+++ b/grapher/Models/Options/ApplyOptions.cs
@@ -0,0 +1,184 @@
+using grapher.Models.Serialized;
+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.Models.Options
+{
+ public class ApplyOptions
+ {
+ #region Constructors
+
+ public ApplyOptions(
+ ToolStripMenuItem wholeVectorMenuItem,
+ ToolStripMenuItem byComponentMenuItem,
+ CheckBox byComponentVectorXYLock,
+ AccelOptionSet optionSetX,
+ AccelOptionSet optionSetY)
+ {
+ WholeVectorMenuItem = wholeVectorMenuItem;
+ ByComponentVectorMenuItem = byComponentMenuItem;
+
+ WholeVectorMenuItem.Click += new System.EventHandler(OnWholeClicked);
+ ByComponentVectorMenuItem.Click += new System.EventHandler(OnByComponentClicked);
+
+ WholeVectorMenuItem.CheckedChanged += new System.EventHandler(OnWholeCheckedChange);
+ ByComponentVectorMenuItem.CheckedChanged += new System.EventHandler(OnByComponentCheckedChange);
+
+ ByComponentVectorXYLock = byComponentVectorXYLock;
+ OptionSetX = optionSetX;
+ OptionSetY = optionSetY;
+
+ ByComponentVectorXYLock.CheckedChanged += new System.EventHandler(OnByComponentXYLockChecked);
+ ByComponentVectorXYLock.Checked = true;
+
+ EnableWholeApplication();
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public ToolStripMenuItem WholeVectorMenuItem { get; }
+
+ public ToolStripMenuItem ByComponentVectorMenuItem { get; }
+
+ public CheckBox ByComponentVectorXYLock { get; }
+
+ public AccelOptionSet OptionSetX { get; }
+
+ public AccelOptionSet OptionSetY { get; }
+
+ public bool IsWhole { get; private set; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public Vec2<AccelMode> GetModes()
+ {
+ var xMode = (AccelMode)OptionSetX.AccelTypeOptions.AccelerationIndex;
+
+ return new Vec2<AccelMode>
+ {
+ x = xMode,
+ y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.AccelTypeOptions.AccelerationIndex
+ };
+ }
+
+ public Vec2<AccelArgs> GetArgs()
+ {
+ var xArgs = OptionSetX.GenerateArgs();
+
+ return new Vec2<AccelArgs>
+ {
+ x = xArgs,
+ y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs()
+ };
+
+ }
+
+ public void SetActiveValues(int xMode, int yMode, AccelArgs xArgs, AccelArgs yArgs, bool isWhole)
+ {
+ OptionSetX.SetActiveValues(xMode, xArgs);
+ OptionSetY.SetActiveValues(yMode, yArgs);
+ WholeVectorMenuItem.Checked = isWhole;
+ ByComponentVectorMenuItem.Checked = !isWhole;
+ }
+
+ public void SetActiveValues(DriverSettings settings)
+ {
+ SetActiveValues((int)settings.modes.x, (int)settings.modes.y, settings.args.x, settings.args.y, settings.combineMagnitudes);
+ }
+
+ public void OnWholeClicked(object sender, EventArgs e)
+ {
+ if (!WholeVectorMenuItem.Checked)
+ {
+ WholeVectorMenuItem.Checked = true;
+ ByComponentVectorMenuItem.Checked = false;
+ }
+ }
+
+ public void OnByComponentClicked(object sender, EventArgs e)
+ {
+ if (!ByComponentVectorMenuItem.Checked)
+ {
+ WholeVectorMenuItem.Checked = false;
+ ByComponentVectorMenuItem.Checked = true;
+ }
+ }
+
+ public void OnWholeCheckedChange(object sender, EventArgs e)
+ {
+ if (WholeVectorMenuItem.Checked)
+ {
+ EnableWholeApplication();
+ }
+ }
+
+ public void OnByComponentCheckedChange(object sender, EventArgs e)
+ {
+ EnableByComponentApplication();
+ }
+
+ public void ShowWholeSet()
+ {
+ OptionSetX.SetRegularMode();
+ OptionSetY.Hide();
+ }
+
+ public void ShowByComponentAsOneSet()
+ {
+ OptionSetX.SetTitleMode("X = Y");
+ OptionSetY.Hide();
+ }
+
+ public void ShowByComponentAsTwoSets()
+ {
+ OptionSetX.SetTitleMode("X");
+ OptionSetY.SetTitleMode("Y");
+ OptionSetY.Show();
+ }
+
+ public void ShowByComponentSet()
+ {
+ if (ByComponentVectorXYLock.Checked)
+ {
+ ShowByComponentAsOneSet();
+ }
+ else
+ {
+ ShowByComponentAsTwoSets();
+ }
+ }
+
+ private void OnByComponentXYLockChecked(object sender, EventArgs e)
+ {
+ if (!IsWhole)
+ {
+ ShowByComponentSet();
+ }
+ }
+
+ public void EnableWholeApplication()
+ {
+ IsWhole = true;
+ ByComponentVectorXYLock.Hide();
+ ShowWholeSet();
+ }
+
+ public void EnableByComponentApplication()
+ {
+ IsWhole = false;
+ ByComponentVectorXYLock.Show();
+ ShowByComponentSet();
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs
index 87bac88..6dc1116 100644
--- a/grapher/Models/Options/CapOptions.cs
+++ b/grapher/Models/Options/CapOptions.cs
@@ -10,20 +10,22 @@ namespace grapher
{
public class CapOptions
{
+ #region Constants
- public const string GainCapFormatString = "0.##";
+
+ #endregion Constants
+
+ #region Constructors
public CapOptions(
ToolStripMenuItem velocityGainCapCheck,
ToolStripMenuItem legacyCapCheck,
- OptionXY capOption,
- OptionXY weightOption)
+ Option capOption)
{
VelocityGainCapCheck = velocityGainCapCheck;
LegacyCapCheck = legacyCapCheck;
CapOption = capOption;
- WeightOption = weightOption;
LegacyCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick);
VelocityGainCapCheck.Click += new System.EventHandler(OnVelocityGainCapCheckClick);
@@ -34,20 +36,24 @@ namespace grapher
EnableVelocityGainCap();
}
+ #endregion Constructors
+
+ #region Properties
+
public ToolStripMenuItem LegacyCapCheck { get; }
public ToolStripMenuItem VelocityGainCapCheck { get; }
- public OptionXY CapOption { get; }
+ public Option CapOption { get; }
- public OptionXY WeightOption { get; }
+ public bool IsSensitivityGain { get; private set; }
- public double SensitivityCapX {
+ public double SensitivityCap {
get
{
if (IsSensitivityGain)
{
- return CapOption.Fields.X;
+ return CapOption.Field.Data;
}
else
{
@@ -56,49 +62,78 @@ namespace grapher
}
}
- public double SensitivityCapY {
+ public double VelocityGainCap {
get
{
if (IsSensitivityGain)
{
- return CapOption.Fields.Y;
+ return 0;
}
else
{
- return 0;
+ return CapOption.Field.Data;
}
}
}
- public double VelocityGainCap {
+ public int Top
+ {
+ get
+ {
+ return CapOption.Top;
+ }
+ set
+ {
+ CapOption.Top = value;
+ }
+ }
+
+ public int Height
+ {
get
{
- if (IsSensitivityGain)
- {
- return 0;
- }
- else
- {
- return CapOption.Fields.X;
- }
+ return CapOption.Height;
}
}
- public bool IsSensitivityGain { get; private set; }
- public void SetActiveValues(double gainCap, double sensCapX, double sensCapY, bool capGainEnabled)
+ #endregion Properties
+
+ #region Methods
+
+ public void Hide()
+ {
+ CapOption.Hide();
+ }
+
+ public void Show()
+ {
+ CapOption.Show();
+ }
+
+ public void SnapTo(Option option)
+ {
+ Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
+ }
+
+
+ public void SetActiveValues(double gainCap, double sensCap, bool capGainEnabled)
{
if (capGainEnabled)
{
- CapOption.ActiveValueLabels.X.FormatString = GainCapFormatString;
- CapOption.ActiveValueLabels.X.Prefix = "Gain";
- CapOption.SetActiveValues(gainCap, gainCap);
+ CapOption.ActiveValueLabel.FormatString = Constants.GainCapFormatString;
+ CapOption.ActiveValueLabel.Prefix = "Gain";
+ CapOption.SetActiveValue(gainCap);
+ LegacyCapCheck.Checked = true;
+ VelocityGainCapCheck.Checked = false;
}
else
{
- CapOption.ActiveValueLabels.X.FormatString = ActiveValueLabel.DefaultFormatString;
- CapOption.ActiveValueLabels.X.Prefix = string.Empty;
- CapOption.SetActiveValues(sensCapX, sensCapY);
+ CapOption.ActiveValueLabel.FormatString = Constants.DefaultActiveValueFormatString;
+ CapOption.ActiveValueLabel.Prefix = string.Empty;
+ CapOption.SetActiveValue(sensCap);
+ LegacyCapCheck.Checked = false;
+ VelocityGainCapCheck.Checked = true;
}
}
@@ -139,19 +174,15 @@ namespace grapher
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");
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs
index b0ef374..22b78d4 100644
--- a/grapher/Models/Options/Option.cs
+++ b/grapher/Models/Options/Option.cs
@@ -10,14 +10,22 @@ namespace grapher
{
public class Option
{
+ #region Constructors
+
public Option(
Field field,
Label label,
- ActiveValueLabel activeValueLabel)
+ ActiveValueLabel activeValueLabel,
+ int left)
{
Field = field;
Label = label;
ActiveValueLabel = activeValueLabel;
+ Left = left;
+
+ label.AutoSize = false;
+ label.Width = Field.Left - left - Constants.OptionLabelBoxSeperation;
+ label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
}
public Option(
@@ -25,11 +33,13 @@ namespace grapher
Form containingForm,
double defaultData,
Label label,
+ int left,
ActiveValueLabel activeValueLabel)
: this(
new Field(box, containingForm, defaultData),
label,
- activeValueLabel)
+ activeValueLabel,
+ left)
{
}
@@ -38,6 +48,7 @@ namespace grapher
Form containingForm,
double defaultData,
Label label,
+ int left,
ActiveValueLabel activeValueLabel,
string startingName)
: this(
@@ -45,22 +56,70 @@ namespace grapher
containingForm,
defaultData,
label,
+ left,
activeValueLabel)
{
SetName(startingName);
}
+ #endregion Constructors
+
+ #region Properties
+
public Field Field { get; }
public Label Label { get; }
public ActiveValueLabel ActiveValueLabel { get; }
+ public int Top
+ {
+ get
+ {
+ return Field.Top;
+ }
+ set
+ {
+ Field.Top = value;
+ Label.Top = value;
+ }
+ }
+
+ public int Height
+ {
+ get
+ {
+ return Field.Height;
+ }
+ }
+
+ public int Left
+ {
+ get
+ {
+ return Label.Left;
+ }
+ private set
+ {
+ Label.Left = value;
+ }
+ }
+ public int Width
+ {
+ get
+ {
+ return Field.Left + Field.Width - Label.Left;
+ }
+ }
+
+ #endregion Properties
+
+ #region Methods
+
public void SetName(string name)
{
Label.Text = name;
//Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); //Centered
- Label.Left = Convert.ToInt32(Field.Box.Left - Label.Width - 10); //Right-aligned
}
public void SetActiveValue(double value)
@@ -93,5 +152,17 @@ namespace grapher
Show();
}
+
+ public void SnapTo(Option option)
+ {
+ Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
+ }
+
+ public void SnapTo(CapOptions option)
+ {
+ Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
+ }
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/OptionXY.cs b/grapher/Models/Options/OptionXY.cs
index 8e22617..c1fd0b7 100644
--- a/grapher/Models/Options/OptionXY.cs
+++ b/grapher/Models/Options/OptionXY.cs
@@ -10,6 +10,7 @@ namespace grapher
{
public class OptionXY
{
+ #region Constructors
public OptionXY(FieldXY fields, Label label, ActiveValueLabelXY activeValueLabels)
{
Fields = fields;
@@ -24,9 +25,8 @@ namespace grapher
Form containingForm,
double defaultData,
Label label,
- AccelCharts accelCharts,
ActiveValueLabelXY activeValueLabels)
- : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label, activeValueLabels)
+ : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData), label, activeValueLabels)
{
}
@@ -38,8 +38,7 @@ namespace grapher
double defaultData,
Label label,
ActiveValueLabelXY activeValueLabels,
- string startingName,
- AccelCharts accelCharts):
+ string startingName):
this(
xBox,
yBox,
@@ -47,18 +46,25 @@ namespace grapher
containingForm,
defaultData,
label,
- accelCharts,
activeValueLabels)
{
SetName(startingName);
}
+ #endregion Constructors
+
+ #region Properties
+
public FieldXY Fields { get; }
public Label Label { get; }
public ActiveValueLabelXY ActiveValueLabels { get; }
+ #endregion Properties
+
+ #region Methods
+
public void SetName(string name)
{
Label.Text = name;
@@ -92,5 +98,6 @@ namespace grapher
Show();
}
+ #endregion Methods
}
}
diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs
index cdccf88..ecd4d51 100644
--- a/grapher/Models/Serialized/DriverSettings.cs
+++ b/grapher/Models/Serialized/DriverSettings.cs
@@ -4,11 +4,17 @@ using System.Threading;
namespace grapher.Models.Serialized
{
+ #region Enumerations
+
public enum AccelMode
{
linear, classic, natural, logarithmic, sigmoid, naturalgain, sigmoidgain, power, noaccel
}
+ #endregion Enumerations
+
+ #region Structs
+
[StructLayout(LayoutKind.Sequential)]
public struct AccelArgs
{
@@ -33,10 +39,14 @@ namespace grapher.Models.Serialized
public T y;
}
+ #endregion Structs
+
[StructLayout(LayoutKind.Sequential)]
[Serializable]
public class DriverSettings
{
+ #region Fields
+
private static readonly IntPtr UnmanagedSettingsHandle =
Marshal.AllocHGlobal(Marshal.SizeOf<DriverSettings>());
private static object UnmanagedSettingsLock = new object();
@@ -48,6 +58,10 @@ namespace grapher.Models.Serialized
public Vec2<double> sensitivity;
public double minimumTime;
+ #endregion Fields
+
+ #region Methods
+
public static DriverSettings GetActive()
{
DriverInterop.GetActiveSettings(UnmanagedSettingsHandle);
@@ -97,5 +111,7 @@ namespace grapher.Models.Serialized
*/
return true;
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs
index 7c8e9a4..253e71d 100644
--- a/grapher/Models/Serialized/GUISettings.cs
+++ b/grapher/Models/Serialized/GUISettings.cs
@@ -12,6 +12,8 @@ namespace grapher.Models.Serialized
[Serializable]
public class GUISettings
{
+ #region Constructors
+
public GUISettings() {}
public GUISettings(bool autoWrite, int dpi, int pollRate)
@@ -21,6 +23,10 @@ namespace grapher.Models.Serialized
PollRate = pollRate;
}
+ #endregion Constructors
+
+ #region Properties
+
[JsonProperty(Order = 1)]
public bool AutoWriteToDriverOnStartup { get; set; }
@@ -29,5 +35,7 @@ namespace grapher.Models.Serialized
[JsonProperty(Order = 3)]
public int PollRate { get; set; }
+
+ #endregion Properties
}
}
diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs
index 7aed917..7466e82 100644
--- a/grapher/Models/Serialized/RawAccelSettings.cs
+++ b/grapher/Models/Serialized/RawAccelSettings.cs
@@ -13,14 +13,19 @@ namespace grapher.Models.Serialized
[Serializable]
public class RawAccelSettings
{
- public const string DefaultSettingsFileName = @"settings.json";
+ #region Fields
+
public static readonly string ExecutingDirectory = AppDomain.CurrentDomain.BaseDirectory;
- public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, DefaultSettingsFileName);
+ public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, Constants.DefaultSettingsFileName);
public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Error,
};
+ #endregion Fields
+
+ #region Constructors
+
public RawAccelSettings() { }
public RawAccelSettings(
@@ -31,10 +36,18 @@ namespace grapher.Models.Serialized
GUISettings = guiSettings;
}
+ #endregion Constructors
+
+ #region Properties
+
public GUISettings GUISettings { get; set; }
public DriverSettings AccelerationSettings { get; set; }
+ #endregion Properties
+
+ #region Methods
+
public static RawAccelSettings Load()
{
return Load(DefaultSettingsFile);
@@ -75,5 +88,7 @@ namespace grapher.Models.Serialized
{
File.WriteAllText(file, JsonConvert.SerializeObject(this, Formatting.Indented));
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs
index c300bde..d7cf590 100644
--- a/grapher/Models/Serialized/SettingsManager.cs
+++ b/grapher/Models/Serialized/SettingsManager.cs
@@ -6,6 +6,8 @@ namespace grapher.Models.Serialized
{
public class SettingsManager
{
+ #region Constructors
+
public SettingsManager(
ManagedAccel activeAccel,
Field dpiField,
@@ -18,6 +20,10 @@ namespace grapher.Models.Serialized
AutoWriteMenuItem = autoWrite;
}
+ #endregion Constructors
+
+ #region Properties
+
public ManagedAccel ActiveAccel { get; }
public RawAccelSettings RawAccelSettings { get; private set; }
@@ -28,6 +34,10 @@ namespace grapher.Models.Serialized
private ToolStripMenuItem AutoWriteMenuItem { get; set; }
+ #endregion Properties
+
+ #region Methods
+
public void UpdateActiveSettings(DriverSettings settings, Action afterAccelSettingsUpdate = null)
{
settings.SendToDriverAndUpdate(ActiveAccel, () =>
@@ -84,5 +94,7 @@ namespace grapher.Models.Serialized
});
RawAccelSettings.Save();
}
+
+ #endregion Methods
}
}