From e48f9ba06680e9447eb82e44d38eacc664850ac5 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 12:58:03 -0700 Subject: Allow zooming on graph --- grapher/Form1.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'grapher') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 495640e..3e627fe 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -44,6 +44,23 @@ namespace grapher } this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); + + this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; + + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; + + this.AccelerationChart.ChartAreas[0].CursorY.Interval = 0.001; + + this.AccelerationChart.ChartAreas[0].CursorX.AutoScroll = true; + this.AccelerationChart.ChartAreas[0].CursorY.AutoScroll = true; + + this.AccelerationChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + this.AccelerationChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + + this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; + this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; } public static double Magnitude(int x, int y) -- cgit v1.2.3 From 46027296f75691cf150aa279a374da3adabf8c44 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 14:21:33 -0700 Subject: Added skeleton for input fields --- grapher/Form1.Designer.cs | 245 ++++++++++++++++++++++++++++++++++++++++++---- grapher/Form1.cs | 25 +++++ 2 files changed, 253 insertions(+), 17 deletions(-) (limited to 'grapher') diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index b39c887..296749c 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -28,49 +28,260 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea11 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend11 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series11 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.textBox4 = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.textBox5 = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.textBox6 = new System.Windows.Forms.TextBox(); + this.textBox7 = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.textBox8 = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.textBox9 = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); this.SuspendLayout(); // // AccelerationChart // - chartArea1.AxisX.Title = "Speed (counts/ms)"; - chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea1.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend1); - this.AccelerationChart.Location = new System.Drawing.Point(0, 0); + chartArea11.AxisX.Title = "Speed (counts/ms)"; + chartArea11.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea11.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea11); + legend11.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend11); + this.AccelerationChart.Location = new System.Drawing.Point(162, 0); this.AccelerationChart.Name = "AccelerationChart"; - series1.ChartArea = "ChartArea1"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series1.Legend = "Legend1"; - series1.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series1); - this.AccelerationChart.Size = new System.Drawing.Size(800, 312); + series11.ChartArea = "ChartArea1"; + series11.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series11.Legend = "Legend1"; + series11.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series11); + this.AccelerationChart.Size = new System.Drawing.Size(801, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Items.AddRange(new object[] { + "Off", + "Linear", + "Classic", + "Natural", + "Logarithmic", + "Sigmoid", + "Power"}); + this.comboBox1.Location = new System.Drawing.Point(15, 86); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(132, 21); + this.comboBox1.TabIndex = 2; + this.comboBox1.Text = "Acceleration Type"; + this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(96, 15); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(51, 20); + this.textBox1.TabIndex = 3; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(15, 18); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(54, 13); + this.label1.TabIndex = 4; + this.label1.Text = "Sensitivity"; + this.label1.Click += new System.EventHandler(this.label1_Click); + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(96, 45); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(51, 20); + this.textBox2.TabIndex = 5; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(22, 48); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(47, 13); + this.label2.TabIndex = 6; + this.label2.Text = "Rotation"; + // + // textBox3 + // + this.textBox3.Location = new System.Drawing.Point(96, 113); + this.textBox3.Name = "textBox3"; + this.textBox3.Size = new System.Drawing.Size(51, 20); + this.textBox3.TabIndex = 7; + this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(15, 116); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(66, 13); + this.label4.TabIndex = 9; + this.label4.Text = "Acceleration"; + // + // textBox4 + // + this.textBox4.Location = new System.Drawing.Point(96, 140); + this.textBox4.Name = "textBox4"; + this.textBox4.Size = new System.Drawing.Size(51, 20); + this.textBox4.TabIndex = 10; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(25, 143); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(26, 13); + this.label3.TabIndex = 11; + this.label3.Text = "Cap"; + // + // textBox5 + // + this.textBox5.Location = new System.Drawing.Point(96, 167); + this.textBox5.Name = "textBox5"; + this.textBox5.Size = new System.Drawing.Size(24, 20); + this.textBox5.TabIndex = 12; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(25, 173); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(41, 13); + this.label5.TabIndex = 13; + this.label5.Text = "Weight"; + // + // textBox6 + // + this.textBox6.Location = new System.Drawing.Point(126, 167); + this.textBox6.Name = "textBox6"; + this.textBox6.Size = new System.Drawing.Size(21, 20); + this.textBox6.TabIndex = 14; + // + // textBox7 + // + this.textBox7.Location = new System.Drawing.Point(96, 219); + this.textBox7.Name = "textBox7"; + this.textBox7.Size = new System.Drawing.Size(51, 20); + this.textBox7.TabIndex = 15; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(12, 222); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(78, 13); + this.label6.TabIndex = 16; + this.label6.Text = "Limit/Exponent"; + this.label6.Click += new System.EventHandler(this.label6_Click); + // + // textBox8 + // + this.textBox8.Location = new System.Drawing.Point(96, 245); + this.textBox8.Name = "textBox8"; + this.textBox8.Size = new System.Drawing.Size(51, 20); + this.textBox8.TabIndex = 17; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(22, 248); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(47, 13); + this.label7.TabIndex = 18; + this.label7.Text = "Midpoint"; + // + // textBox9 + // + this.textBox9.Location = new System.Drawing.Point(96, 193); + this.textBox9.Name = "textBox9"; + this.textBox9.Size = new System.Drawing.Size(51, 20); + this.textBox9.TabIndex = 19; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(25, 200); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(35, 13); + this.label8.TabIndex = 20; + this.label8.Text = "Offset"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 310); + this.ClientSize = new System.Drawing.Size(963, 310); + this.Controls.Add(this.label8); + this.Controls.Add(this.textBox9); + this.Controls.Add(this.label7); + this.Controls.Add(this.textBox8); + this.Controls.Add(this.label6); + this.Controls.Add(this.textBox7); + this.Controls.Add(this.textBox6); + this.Controls.Add(this.label5); + this.Controls.Add(this.textBox5); + this.Controls.Add(this.label3); + this.Controls.Add(this.textBox4); + this.Controls.Add(this.label4); + this.Controls.Add(this.textBox3); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.label1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.comboBox1); this.Controls.Add(this.AccelerationChart); this.Name = "RawAcceleration"; this.Text = "Raw Acceleration Graph"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox textBox4; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox textBox5; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox textBox6; + private System.Windows.Forms.TextBox textBox7; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox textBox8; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.TextBox textBox9; + private System.Windows.Forms.Label label8; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 3e627fe..6e81984 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -77,5 +77,30 @@ namespace grapher { } + + private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void textBox3_TextChanged(object sender, EventArgs e) + { + + } + + private void label6_Click(object sender, EventArgs e) + { + + } } } -- cgit v1.2.3 From 7d0f8a2028ef8977c68c92c9c0bba4272cc10773 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 17:31:08 -0700 Subject: Rename elements and add write button --- grapher/Form1.Designer.cs | 211 ++++++++++++++++++++++++---------------------- grapher/Form1.cs | 100 +++++++++++++--------- 2 files changed, 169 insertions(+), 142 deletions(-) (limited to 'grapher') diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 296749c..ebf92f0 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -28,54 +28,55 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea11 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend11 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series11 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); - this.comboBox1 = new System.Windows.Forms.ComboBox(); - this.textBox1 = new System.Windows.Forms.TextBox(); + this.accelTypeDrop = new System.Windows.Forms.ComboBox(); + this.sensitivityBox = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); - this.textBox2 = new System.Windows.Forms.TextBox(); + this.rotationBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); - this.textBox3 = new System.Windows.Forms.TextBox(); + this.accelerationBox = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); - this.textBox4 = new System.Windows.Forms.TextBox(); + this.capBox = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); - this.textBox5 = new System.Windows.Forms.TextBox(); + this.weightBoxFirst = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); - this.textBox6 = new System.Windows.Forms.TextBox(); - this.textBox7 = new System.Windows.Forms.TextBox(); + this.weightBoxSecond = new System.Windows.Forms.TextBox(); + this.limitBox = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); - this.textBox8 = new System.Windows.Forms.TextBox(); + this.midpointBox = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); - this.textBox9 = new System.Windows.Forms.TextBox(); + this.offsetBox = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); + this.writeButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); this.SuspendLayout(); // // AccelerationChart // - chartArea11.AxisX.Title = "Speed (counts/ms)"; - chartArea11.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea11.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea11); - legend11.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend11); + chartArea2.AxisX.Title = "Speed (counts/ms)"; + chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea2.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend2); this.AccelerationChart.Location = new System.Drawing.Point(162, 0); this.AccelerationChart.Name = "AccelerationChart"; - series11.ChartArea = "ChartArea1"; - series11.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series11.Legend = "Legend1"; - series11.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series11); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series2); this.AccelerationChart.Size = new System.Drawing.Size(801, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; // - // comboBox1 + // accelTypeDrop // - this.comboBox1.FormattingEnabled = true; - this.comboBox1.Items.AddRange(new object[] { + this.accelTypeDrop.FormattingEnabled = true; + this.accelTypeDrop.Items.AddRange(new object[] { "Off", "Linear", "Classic", @@ -83,19 +84,18 @@ "Logarithmic", "Sigmoid", "Power"}); - this.comboBox1.Location = new System.Drawing.Point(15, 86); - this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(132, 21); - this.comboBox1.TabIndex = 2; - this.comboBox1.Text = "Acceleration Type"; - this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); + this.accelTypeDrop.Location = new System.Drawing.Point(15, 86); + this.accelTypeDrop.Name = "accelTypeDrop"; + this.accelTypeDrop.Size = new System.Drawing.Size(132, 21); + this.accelTypeDrop.TabIndex = 2; + this.accelTypeDrop.Text = "Acceleration Type"; // - // textBox1 + // sensitivityBox // - this.textBox1.Location = new System.Drawing.Point(96, 15); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(51, 20); - this.textBox1.TabIndex = 3; + this.sensitivityBox.Location = new System.Drawing.Point(96, 15); + this.sensitivityBox.Name = "sensitivityBox"; + this.sensitivityBox.Size = new System.Drawing.Size(51, 20); + this.sensitivityBox.TabIndex = 3; // // label1 // @@ -105,14 +105,13 @@ this.label1.Size = new System.Drawing.Size(54, 13); this.label1.TabIndex = 4; this.label1.Text = "Sensitivity"; - this.label1.Click += new System.EventHandler(this.label1_Click); // - // textBox2 + // rotationBox // - this.textBox2.Location = new System.Drawing.Point(96, 45); - this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(51, 20); - this.textBox2.TabIndex = 5; + this.rotationBox.Location = new System.Drawing.Point(96, 45); + this.rotationBox.Name = "rotationBox"; + this.rotationBox.Size = new System.Drawing.Size(51, 20); + this.rotationBox.TabIndex = 5; // // label2 // @@ -123,13 +122,12 @@ this.label2.TabIndex = 6; this.label2.Text = "Rotation"; // - // textBox3 + // accelerationBox // - this.textBox3.Location = new System.Drawing.Point(96, 113); - this.textBox3.Name = "textBox3"; - this.textBox3.Size = new System.Drawing.Size(51, 20); - this.textBox3.TabIndex = 7; - this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged); + this.accelerationBox.Location = new System.Drawing.Point(96, 113); + this.accelerationBox.Name = "accelerationBox"; + this.accelerationBox.Size = new System.Drawing.Size(51, 20); + this.accelerationBox.TabIndex = 7; // // label4 // @@ -140,12 +138,12 @@ this.label4.TabIndex = 9; this.label4.Text = "Acceleration"; // - // textBox4 + // capBox // - this.textBox4.Location = new System.Drawing.Point(96, 140); - this.textBox4.Name = "textBox4"; - this.textBox4.Size = new System.Drawing.Size(51, 20); - this.textBox4.TabIndex = 10; + this.capBox.Location = new System.Drawing.Point(96, 140); + this.capBox.Name = "capBox"; + this.capBox.Size = new System.Drawing.Size(51, 20); + this.capBox.TabIndex = 10; // // label3 // @@ -156,12 +154,12 @@ this.label3.TabIndex = 11; this.label3.Text = "Cap"; // - // textBox5 + // weightBoxFirst // - this.textBox5.Location = new System.Drawing.Point(96, 167); - this.textBox5.Name = "textBox5"; - this.textBox5.Size = new System.Drawing.Size(24, 20); - this.textBox5.TabIndex = 12; + this.weightBoxFirst.Location = new System.Drawing.Point(96, 167); + this.weightBoxFirst.Name = "weightBoxFirst"; + this.weightBoxFirst.Size = new System.Drawing.Size(24, 20); + this.weightBoxFirst.TabIndex = 12; // // label5 // @@ -172,19 +170,19 @@ this.label5.TabIndex = 13; this.label5.Text = "Weight"; // - // textBox6 + // weightBoxSecond // - this.textBox6.Location = new System.Drawing.Point(126, 167); - this.textBox6.Name = "textBox6"; - this.textBox6.Size = new System.Drawing.Size(21, 20); - this.textBox6.TabIndex = 14; + this.weightBoxSecond.Location = new System.Drawing.Point(126, 167); + this.weightBoxSecond.Name = "weightBoxSecond"; + this.weightBoxSecond.Size = new System.Drawing.Size(21, 20); + this.weightBoxSecond.TabIndex = 14; // - // textBox7 + // limitBox // - this.textBox7.Location = new System.Drawing.Point(96, 219); - this.textBox7.Name = "textBox7"; - this.textBox7.Size = new System.Drawing.Size(51, 20); - this.textBox7.TabIndex = 15; + this.limitBox.Location = new System.Drawing.Point(96, 219); + this.limitBox.Name = "limitBox"; + this.limitBox.Size = new System.Drawing.Size(51, 20); + this.limitBox.TabIndex = 15; // // label6 // @@ -194,14 +192,13 @@ this.label6.Size = new System.Drawing.Size(78, 13); this.label6.TabIndex = 16; this.label6.Text = "Limit/Exponent"; - this.label6.Click += new System.EventHandler(this.label6_Click); // - // textBox8 + // midpointBox // - this.textBox8.Location = new System.Drawing.Point(96, 245); - this.textBox8.Name = "textBox8"; - this.textBox8.Size = new System.Drawing.Size(51, 20); - this.textBox8.TabIndex = 17; + this.midpointBox.Location = new System.Drawing.Point(96, 245); + this.midpointBox.Name = "midpointBox"; + this.midpointBox.Size = new System.Drawing.Size(51, 20); + this.midpointBox.TabIndex = 17; // // label7 // @@ -212,12 +209,12 @@ this.label7.TabIndex = 18; this.label7.Text = "Midpoint"; // - // textBox9 + // offsetBox // - this.textBox9.Location = new System.Drawing.Point(96, 193); - this.textBox9.Name = "textBox9"; - this.textBox9.Size = new System.Drawing.Size(51, 20); - this.textBox9.TabIndex = 19; + this.offsetBox.Location = new System.Drawing.Point(96, 193); + this.offsetBox.Name = "offsetBox"; + this.offsetBox.Size = new System.Drawing.Size(51, 20); + this.offsetBox.TabIndex = 19; // // label8 // @@ -228,29 +225,40 @@ this.label8.TabIndex = 20; this.label8.Text = "Offset"; // + // writeButton + // + this.writeButton.Location = new System.Drawing.Point(28, 271); + this.writeButton.Name = "writeButton"; + this.writeButton.Size = new System.Drawing.Size(102, 23); + this.writeButton.TabIndex = 21; + this.writeButton.Text = "Write To Driver"; + this.writeButton.UseVisualStyleBackColor = true; + this.writeButton.Click += new System.EventHandler(this.writeButton_Click); + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(963, 310); + this.Controls.Add(this.writeButton); this.Controls.Add(this.label8); - this.Controls.Add(this.textBox9); + this.Controls.Add(this.offsetBox); this.Controls.Add(this.label7); - this.Controls.Add(this.textBox8); + this.Controls.Add(this.midpointBox); this.Controls.Add(this.label6); - this.Controls.Add(this.textBox7); - this.Controls.Add(this.textBox6); + this.Controls.Add(this.limitBox); + this.Controls.Add(this.weightBoxSecond); this.Controls.Add(this.label5); - this.Controls.Add(this.textBox5); + this.Controls.Add(this.weightBoxFirst); this.Controls.Add(this.label3); - this.Controls.Add(this.textBox4); + this.Controls.Add(this.capBox); this.Controls.Add(this.label4); - this.Controls.Add(this.textBox3); + this.Controls.Add(this.accelerationBox); this.Controls.Add(this.label2); - this.Controls.Add(this.textBox2); + this.Controls.Add(this.rotationBox); this.Controls.Add(this.label1); - this.Controls.Add(this.textBox1); - this.Controls.Add(this.comboBox1); + this.Controls.Add(this.sensitivityBox); + this.Controls.Add(this.accelTypeDrop); this.Controls.Add(this.AccelerationChart); this.Name = "RawAcceleration"; this.Text = "Raw Acceleration Graph"; @@ -264,24 +272,25 @@ #endregion private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; - private System.Windows.Forms.ComboBox comboBox1; - private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.ComboBox accelTypeDrop; + private System.Windows.Forms.TextBox sensitivityBox; private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.TextBox rotationBox; private System.Windows.Forms.Label label2; - private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.TextBox accelerationBox; private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox textBox4; + private System.Windows.Forms.TextBox capBox; private System.Windows.Forms.Label label3; - private System.Windows.Forms.TextBox textBox5; + private System.Windows.Forms.TextBox weightBoxFirst; private System.Windows.Forms.Label label5; - private System.Windows.Forms.TextBox textBox6; - private System.Windows.Forms.TextBox textBox7; + private System.Windows.Forms.TextBox weightBoxSecond; + private System.Windows.Forms.TextBox limitBox; private System.Windows.Forms.Label label6; - private System.Windows.Forms.TextBox textBox8; + private System.Windows.Forms.TextBox midpointBox; private System.Windows.Forms.Label label7; - private System.Windows.Forms.TextBox textBox9; + private System.Windows.Forms.TextBox offsetBox; private System.Windows.Forms.Label label8; + private System.Windows.Forms.Button writeButton; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 6e81984..3312269 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -12,37 +12,14 @@ namespace grapher { public partial class RawAcceleration : Form { + #region Constructor + public RawAcceleration() { InitializeComponent(); - var managedAccel = new ManagedAccel(5, 0, 0.3, 1.25, 15); - var orderedPoints = new SortedDictionary(); - - for (int i = 0; i < 100; i++) - { - for (int j = 0; j <= i; j++) - { - var output = managedAccel.Accelerate(i, j, 1); - - var inMagnitude = Magnitude(i,j); - var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : 0; - - if (!orderedPoints.ContainsKey(inMagnitude)) - { - orderedPoints.Add(inMagnitude, ratio); - } - } - } - - var series = this.AccelerationChart.Series.FirstOrDefault(); - series.Points.Clear(); - - foreach (var point in orderedPoints) - { - series.Points.AddXY(point.Key, point.Value); - } - + ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); + UpdateGraph(); + this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; @@ -62,6 +39,33 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; } + #endregion Constructor + + #region Properties + + public ManagedAccel ManagedAcceleration { get; set; } + + private int AccelerationType { get; set; } + + private Tuple Sensitivity { get; set; } + + private double Rotation { get; set; } + + private Tuple Weight { get; set; } + + private double Cap { get; set; } + + private double Offset { get; set; } + + private double Acceleration { get; set; } + + private double LimitOrExponent { get; set; } + + private double Midpoint { get; set; } + + #endregion Properties + + #region Methods public static double Magnitude(int x, int y) { @@ -78,29 +82,43 @@ namespace grapher } - private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + private void UpdateGraph() { + var orderedPoints = new SortedDictionary(); - } + for (int i = 0; i < 100; i++) + { + for (int j = 0; j <= i; j++) + { + var output = ManagedAcceleration.Accelerate(i, j, 1); - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { + var inMagnitude = Magnitude(i,j); + var outMagnitude = Magnitude(output.Item1, output.Item2); + var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : 0; - } + if (!orderedPoints.ContainsKey(inMagnitude)) + { + orderedPoints.Add(inMagnitude, ratio); + } + } + } - private void label1_Click(object sender, EventArgs e) - { + var series = this.AccelerationChart.Series.FirstOrDefault(); + series.Points.Clear(); + foreach (var point in orderedPoints) + { + series.Points.AddXY(point.Key, point.Value); + } } - private void textBox3_TextChanged(object sender, EventArgs e) - { - - } + #endregion Methods - private void label6_Click(object sender, EventArgs e) + private void writeButton_Click(object sender, EventArgs e) { - + ManagedAcceleration.UpdateAccel(5, 0, 1.3, 9, 15); + ManagedAcceleration.WriteToDriver(); + UpdateGraph(); } } } -- cgit v1.2.3 From 93d4d0fe6a356953b5dd78f60393f2a70a73afb3 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 18:14:27 -0700 Subject: Take new data for most fields by pressing enter --- grapher/Form1.Designer.cs | 35 +++++++++++-------- grapher/Form1.cs | 87 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 106 insertions(+), 16 deletions(-) (limited to 'grapher') diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index ebf92f0..d2aae7d 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -28,9 +28,9 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea10 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend10 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series10 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBox = new System.Windows.Forms.TextBox(); @@ -56,19 +56,19 @@ // // AccelerationChart // - chartArea2.AxisX.Title = "Speed (counts/ms)"; - chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea2.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea2); - legend2.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend2); + chartArea10.AxisX.Title = "Speed (counts/ms)"; + chartArea10.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea10.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea10); + legend10.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend10); this.AccelerationChart.Location = new System.Drawing.Point(162, 0); this.AccelerationChart.Name = "AccelerationChart"; - series2.ChartArea = "ChartArea1"; - series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series2.Legend = "Legend1"; - series2.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series2); + series10.ChartArea = "ChartArea1"; + series10.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series10.Legend = "Legend1"; + series10.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series10); this.AccelerationChart.Size = new System.Drawing.Size(801, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; @@ -96,6 +96,7 @@ this.sensitivityBox.Name = "sensitivityBox"; this.sensitivityBox.Size = new System.Drawing.Size(51, 20); this.sensitivityBox.TabIndex = 3; + this.sensitivityBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.sensitivityBox_KeyDown); // // label1 // @@ -112,6 +113,7 @@ this.rotationBox.Name = "rotationBox"; this.rotationBox.Size = new System.Drawing.Size(51, 20); this.rotationBox.TabIndex = 5; + this.rotationBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rotationBox_KeyDown); // // label2 // @@ -128,6 +130,7 @@ this.accelerationBox.Name = "accelerationBox"; this.accelerationBox.Size = new System.Drawing.Size(51, 20); this.accelerationBox.TabIndex = 7; + this.accelerationBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.accelerationBox_KeyDown); // // label4 // @@ -144,6 +147,7 @@ this.capBox.Name = "capBox"; this.capBox.Size = new System.Drawing.Size(51, 20); this.capBox.TabIndex = 10; + this.capBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.capBox_KeyDown); // // label3 // @@ -183,6 +187,7 @@ this.limitBox.Name = "limitBox"; this.limitBox.Size = new System.Drawing.Size(51, 20); this.limitBox.TabIndex = 15; + this.limitBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.limitBox_KeyDown); // // label6 // @@ -199,6 +204,7 @@ this.midpointBox.Name = "midpointBox"; this.midpointBox.Size = new System.Drawing.Size(51, 20); this.midpointBox.TabIndex = 17; + this.midpointBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.midpointBox_KeyDown); // // label7 // @@ -215,6 +221,7 @@ this.offsetBox.Name = "offsetBox"; this.offsetBox.Size = new System.Drawing.Size(51, 20); this.offsetBox.TabIndex = 19; + this.offsetBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.offsetBox_KeyDown); // // label8 // diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 3312269..431dd53 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -38,6 +38,10 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; + + Acceleration = 0; + LimitOrExponent = 1.01; + Midpoint = 0; } #endregion Constructor @@ -47,7 +51,7 @@ namespace grapher private int AccelerationType { get; set; } - private Tuple Sensitivity { get; set; } + private double Sensitivity { get; set; } private double Rotation { get; set; } @@ -116,9 +120,88 @@ namespace grapher private void writeButton_Click(object sender, EventArgs e) { - ManagedAcceleration.UpdateAccel(5, 0, 1.3, 9, 15); + ManagedAcceleration.UpdateAccel(5, 0, Acceleration, LimitOrExponent, Midpoint); ManagedAcceleration.WriteToDriver(); UpdateGraph(); } + + private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Sensitivity = data; + } + } + + private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) + { + bool validEntry = false; + data = 0.0; + + if (e.KeyCode == Keys.Enter) + { + try + { + data = Convert.ToDouble(((TextBox)sender).Text); + validEntry = true; + } + catch + { + } + + e.Handled = true; + e.SuppressKeyPress = true; + } + + return validEntry; + } + + private void accelerationBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Acceleration = data; + } + } + + private void rotationBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Rotation = data; + } + } + + private void capBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Cap = data; + } + } + + private void offsetBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Offset = data; + } + } + + private void limitBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + LimitOrExponent = data; + } + } + + private void midpointBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Midpoint = data; + } + } } } -- cgit v1.2.3 From 953fd6e30faae4f8eecfe2fde2b47cf42da51ca8 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 18:50:43 -0700 Subject: Take all variables through GUI --- grapher/Form1.cs | 96 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 26 deletions(-) (limited to 'grapher') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 431dd53..d1244f3 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -17,7 +17,18 @@ namespace grapher public RawAcceleration() { InitializeComponent(); + ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); + AccelerationType = 5; + Sensitivity = new VectorXY(1); + Rotation = 0; + Weight = new VectorXY(1); + Cap = new VectorXY(0); + Offset = 0; + Acceleration = 0; + LimitOrExponent = 1.01; + Midpoint = 0; + UpdateGraph(); this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); @@ -38,11 +49,8 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; - - Acceleration = 0; - LimitOrExponent = 1.01; - Midpoint = 0; } + #endregion Constructor #region Properties @@ -51,13 +59,13 @@ namespace grapher private int AccelerationType { get; set; } - private double Sensitivity { get; set; } + private VectorXY Sensitivity { get; set; } private double Rotation { get; set; } - private Tuple Weight { get; set; } + private VectorXY Weight { get; set; } - private double Cap { get; set; } + private VectorXY Cap { get; set; } private double Offset { get; set; } @@ -98,7 +106,7 @@ namespace grapher var inMagnitude = Magnitude(i,j); var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : 0; + var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.X; if (!orderedPoints.ContainsKey(inMagnitude)) { @@ -116,23 +124,6 @@ namespace grapher } } - #endregion Methods - - private void writeButton_Click(object sender, EventArgs e) - { - ManagedAcceleration.UpdateAccel(5, 0, Acceleration, LimitOrExponent, Midpoint); - ManagedAcceleration.WriteToDriver(); - UpdateGraph(); - } - - private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Sensitivity = data; - } - } - private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) { bool validEntry = false; @@ -156,6 +147,32 @@ namespace grapher return validEntry; } + private void writeButton_Click(object sender, EventArgs e) + { + ManagedAcceleration.UpdateAccel( + AccelerationType, + Sensitivity.X, + Sensitivity.Y, + Weight.X, + Weight.Y, + Cap.X, + Cap.Y, + Offset, + Acceleration, + LimitOrExponent, + Midpoint); + ManagedAcceleration.WriteToDriver(); + UpdateGraph(); + } + + private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Sensitivity.SetBoth(data); + } + } + private void accelerationBox_KeyDown(object sender, KeyEventArgs e) { if (TryHandleWithEnter(e, sender, out double data)) @@ -176,7 +193,7 @@ namespace grapher { if (TryHandleWithEnter(e, sender, out double data)) { - Cap = data; + Cap.SetBoth(data); } } @@ -203,5 +220,32 @@ namespace grapher Midpoint = data; } } + + #endregion Methods + + public class VectorXY + { + public VectorXY(double x) + { + X = x; + Y = x; + } + + public VectorXY(double x, double y) + { + X = x; + Y = y; + } + + public double X { get; set; } + + public double Y { get; set; } + + public void SetBoth(double value) + { + X = value; + Y = value; + } + } } } -- cgit v1.2.3 From 621ab8d23d10c892a18c39234b24266fd90b90fa Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 19:35:57 -0700 Subject: Separate classes into files, add Field class for text box state --- grapher/Field.cs | 130 ++++++++++++++++++++++++++++++++++++++++++++++ grapher/Form1.Designer.cs | 29 +++++------ grapher/Form1.cs | 39 ++------------ grapher/VectorXY.cs | 33 ++++++++++++ grapher/grapher.csproj | 2 + 5 files changed, 182 insertions(+), 51 deletions(-) create mode 100644 grapher/Field.cs create mode 100644 grapher/VectorXY.cs (limited to 'grapher') diff --git a/grapher/Field.cs b/grapher/Field.cs new file mode 100644 index 0000000..641bb2a --- /dev/null +++ b/grapher/Field.cs @@ -0,0 +1,130 @@ +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 Enums + + public enum FieldState + { + Undefined, + Default, + Typing, + Entered, + Unavailable, + } + + #endregion Enums + + + #region Constructors + + public Field(string defaultText, TextBox box, double defaultData) + { + DefaultText = defaultText; + Box = box; + Data = defaultData; + State = FieldState.Undefined; + box.KeyDown += KeyDown; + + SetToDefault(); + } + + #endregion Constructors + + #region Properties + + TextBox Box { get; } + + public double Data { get; private set; } + + public string DefaultText { get; } + + public FieldState State { get; private set; } + + #endregion Properties + + #region Methods + + public void SetToDefault() + { + if (State != FieldState.Default) + { + Box.BackColor = Color.AntiqueWhite; + Box.ForeColor = Color.Gray; + Box.Text = DefaultText; + State = FieldState.Default; + } + } + + public void SetToTyping() + { + if (State != FieldState.Typing) + { + Box.BackColor = Color.White; + Box.ForeColor = Color.Black; + State = FieldState.Typing; + } + } + + public void SetToEntered() + { + if (State != FieldState.Entered) + { + Box.BackColor = Color.White; + Box.ForeColor = Color.DarkGray; + State = FieldState.Entered; + } + } + + public void SetToUnavailable() + { + if (State != FieldState.Unavailable) + { + Box.BackColor = Color.LightGray; + Box.ForeColor = Color.LightGray; + Box.Text = string.Empty; + } + } + + public void KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Data = data; + } + } + + private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) + { + bool validEntry = false; + data = 0.0; + + if (e.KeyCode == Keys.Enter) + { + try + { + data = Convert.ToDouble(((TextBox)sender).Text); + validEntry = true; + } + catch + { + } + + e.Handled = true; + e.SuppressKeyPress = true; + } + + return validEntry; + } + + #endregion Methods + } +} diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index d2aae7d..978f3da 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -28,9 +28,9 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea10 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend10 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series10 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea12 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend12 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series12 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBox = new System.Windows.Forms.TextBox(); @@ -56,19 +56,19 @@ // // AccelerationChart // - chartArea10.AxisX.Title = "Speed (counts/ms)"; - chartArea10.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea10.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea10); - legend10.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend10); + chartArea12.AxisX.Title = "Speed (counts/ms)"; + chartArea12.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea12.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea12); + legend12.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend12); this.AccelerationChart.Location = new System.Drawing.Point(162, 0); this.AccelerationChart.Name = "AccelerationChart"; - series10.ChartArea = "ChartArea1"; - series10.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series10.Legend = "Legend1"; - series10.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series10); + series12.ChartArea = "ChartArea1"; + series12.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series12.Legend = "Legend1"; + series12.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series12); this.AccelerationChart.Size = new System.Drawing.Size(801, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; @@ -130,7 +130,6 @@ this.accelerationBox.Name = "accelerationBox"; this.accelerationBox.Size = new System.Drawing.Size(51, 20); this.accelerationBox.TabIndex = 7; - this.accelerationBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.accelerationBox_KeyDown); // // label4 // diff --git a/grapher/Form1.cs b/grapher/Form1.cs index d1244f3..fbf5dfb 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -25,7 +25,7 @@ namespace grapher Weight = new VectorXY(1); Cap = new VectorXY(0); Offset = 0; - Acceleration = 0; + Acceleration = new Field("0.0", this.accelerationBox, 0); LimitOrExponent = 1.01; Midpoint = 0; @@ -69,7 +69,7 @@ namespace grapher private double Offset { get; set; } - private double Acceleration { get; set; } + private Field Acceleration { get; set; } private double LimitOrExponent { get; set; } @@ -158,7 +158,7 @@ namespace grapher Cap.X, Cap.Y, Offset, - Acceleration, + Acceleration.Data, LimitOrExponent, Midpoint); ManagedAcceleration.WriteToDriver(); @@ -173,14 +173,6 @@ namespace grapher } } - private void accelerationBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Acceleration = data; - } - } - private void rotationBox_KeyDown(object sender, KeyEventArgs e) { if (TryHandleWithEnter(e, sender, out double data)) @@ -222,30 +214,5 @@ namespace grapher } #endregion Methods - - public class VectorXY - { - public VectorXY(double x) - { - X = x; - Y = x; - } - - public VectorXY(double x, double y) - { - X = x; - Y = y; - } - - public double X { get; set; } - - public double Y { get; set; } - - public void SetBoth(double value) - { - X = value; - Y = value; - } - } } } diff --git a/grapher/VectorXY.cs b/grapher/VectorXY.cs new file mode 100644 index 0000000..53c9e68 --- /dev/null +++ b/grapher/VectorXY.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher +{ + public class VectorXY + { + public VectorXY(double x) + { + X = x; + Y = x; + } + + public VectorXY(double x, double y) + { + X = x; + Y = y; + } + + public double X { get; set; } + + public double Y { get; set; } + + public void SetBoth(double value) + { + X = value; + Y = value; + } + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index f67ced1..9c29da4 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -47,6 +47,7 @@ + Form @@ -55,6 +56,7 @@ + Form1.cs -- cgit v1.2.3 From 769deb7d9f8fca973432e74d2a6fac8697091fc2 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 20:10:18 -0700 Subject: All single-value boxes use fields --- grapher/Field.cs | 58 +++++++++++++++++++++++++++++++++++------------ grapher/Form1.Designer.cs | 4 ---- grapher/Form1.cs | 56 ++++++++++----------------------------------- 3 files changed, 56 insertions(+), 62 deletions(-) (limited to 'grapher') diff --git a/grapher/Field.cs b/grapher/Field.cs index 641bb2a..4be87ba 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -26,12 +26,13 @@ namespace grapher #region Constructors - public Field(string defaultText, TextBox box, double defaultData) + public Field(string defaultText, TextBox box, Form containingForm, double defaultData) { DefaultText = defaultText; Box = box; Data = defaultData; State = FieldState.Undefined; + ContainingForm = containingForm; box.KeyDown += KeyDown; SetToDefault(); @@ -43,6 +44,8 @@ namespace grapher TextBox Box { get; } + Form ContainingForm { get; } + public double Data { get; private set; } public string DefaultText { get; } @@ -57,11 +60,13 @@ namespace grapher { if (State != FieldState.Default) { - Box.BackColor = Color.AntiqueWhite; + Box.BackColor = Color.White; Box.ForeColor = Color.Gray; - Box.Text = DefaultText; State = FieldState.Default; } + + Box.Text = DefaultText; + ContainingForm.ActiveControl = null; } public void SetToTyping() @@ -72,16 +77,20 @@ namespace grapher Box.ForeColor = Color.Black; State = FieldState.Typing; } + + Box.Text = string.Empty; } public void SetToEntered() { if (State != FieldState.Entered) { - Box.BackColor = Color.White; + Box.BackColor = Color.AntiqueWhite; Box.ForeColor = Color.DarkGray; State = FieldState.Entered; } + + ContainingForm.ActiveControl = null; } public void SetToUnavailable() @@ -96,33 +105,54 @@ namespace grapher public void KeyDown(object sender, KeyEventArgs e) { - if (TryHandleWithEnter(e, sender, out double data)) + switch(State) { - Data = data; + 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; + break; + default: + break; } } - private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) + private void HandleTyping(object sender, KeyEventArgs e) { - bool validEntry = false; - data = 0.0; - if (e.KeyCode == Keys.Enter) { try { - data = Convert.ToDouble(((TextBox)sender).Text); - validEntry = true; + Data = Convert.ToDouble(((TextBox)sender).Text); } catch { + Box.Text = Data.ToString(); } e.Handled = true; e.SuppressKeyPress = true; - } - return validEntry; + SetToEntered(); + } } #endregion Methods diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 978f3da..fcfa239 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -113,7 +113,6 @@ this.rotationBox.Name = "rotationBox"; this.rotationBox.Size = new System.Drawing.Size(51, 20); this.rotationBox.TabIndex = 5; - this.rotationBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rotationBox_KeyDown); // // label2 // @@ -186,7 +185,6 @@ this.limitBox.Name = "limitBox"; this.limitBox.Size = new System.Drawing.Size(51, 20); this.limitBox.TabIndex = 15; - this.limitBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.limitBox_KeyDown); // // label6 // @@ -203,7 +201,6 @@ this.midpointBox.Name = "midpointBox"; this.midpointBox.Size = new System.Drawing.Size(51, 20); this.midpointBox.TabIndex = 17; - this.midpointBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.midpointBox_KeyDown); // // label7 // @@ -220,7 +217,6 @@ this.offsetBox.Name = "offsetBox"; this.offsetBox.Size = new System.Drawing.Size(51, 20); this.offsetBox.TabIndex = 19; - this.offsetBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.offsetBox_KeyDown); // // label8 // diff --git a/grapher/Form1.cs b/grapher/Form1.cs index fbf5dfb..ef0dd3a 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -21,13 +21,13 @@ namespace grapher ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); AccelerationType = 5; Sensitivity = new VectorXY(1); - Rotation = 0; + Rotation = new Field("0.0", rotationBox, this, 0); Weight = new VectorXY(1); Cap = new VectorXY(0); - Offset = 0; - Acceleration = new Field("0.0", this.accelerationBox, 0); - LimitOrExponent = 1.01; - Midpoint = 0; + Offset = new Field("0.0", offsetBox, this, 0); + Acceleration = new Field("0.0", accelerationBox, this, 0); + LimitOrExponent = new Field("2.0", limitBox, this, 2); + Midpoint = new Field("0.0", midpointBox, this, 0); UpdateGraph(); @@ -61,19 +61,19 @@ namespace grapher private VectorXY Sensitivity { get; set; } - private double Rotation { get; set; } + private Field Rotation { get; set; } private VectorXY Weight { get; set; } private VectorXY Cap { get; set; } - private double Offset { get; set; } + private Field Offset { get; set; } private Field Acceleration { get; set; } - private double LimitOrExponent { get; set; } + private Field LimitOrExponent { get; set; } - private double Midpoint { get; set; } + private Field Midpoint { get; set; } #endregion Properties @@ -157,10 +157,10 @@ namespace grapher Weight.Y, Cap.X, Cap.Y, - Offset, + Offset.Data, Acceleration.Data, - LimitOrExponent, - Midpoint); + LimitOrExponent.Data, + Midpoint.Data); ManagedAcceleration.WriteToDriver(); UpdateGraph(); } @@ -173,14 +173,6 @@ namespace grapher } } - private void rotationBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Rotation = data; - } - } - private void capBox_KeyDown(object sender, KeyEventArgs e) { if (TryHandleWithEnter(e, sender, out double data)) @@ -189,30 +181,6 @@ namespace grapher } } - private void offsetBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Offset = data; - } - } - - private void limitBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - LimitOrExponent = data; - } - } - - private void midpointBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Midpoint = data; - } - } - #endregion Methods } } -- cgit v1.2.3 From 36abeecf953e0efcd1ec9dcafa4bd1c554e362f5 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 21:03:02 -0700 Subject: Add FieldXY --- grapher/Field.cs | 19 ++++- grapher/FieldXY.cs | 82 ++++++++++++++++++++ grapher/Form1.Designer.cs | 192 +++++++++++++++++++++++++++++++--------------- grapher/Form1.cs | 38 +++------ grapher/grapher.csproj | 1 + 5 files changed, 242 insertions(+), 90 deletions(-) create mode 100644 grapher/FieldXY.cs (limited to 'grapher') diff --git a/grapher/Field.cs b/grapher/Field.cs index 4be87ba..3f4b170 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -26,14 +26,15 @@ namespace grapher #region Constructors - public Field(string defaultText, TextBox box, Form containingForm, double defaultData) + public Field(TextBox box, Form containingForm, double defaultData) { - DefaultText = defaultText; + DefaultText = defaultData.ToString("N1"); Box = box; Data = defaultData; + DefaultData = defaultData; State = FieldState.Undefined; ContainingForm = containingForm; - box.KeyDown += KeyDown; + box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown); SetToDefault(); } @@ -52,6 +53,8 @@ namespace grapher public FieldState State { get; private set; } + private double DefaultData { get; } + #endregion Properties #region Methods @@ -65,6 +68,7 @@ namespace grapher State = FieldState.Default; } + Data = DefaultData; Box.Text = DefaultText; ContainingForm.ActiveControl = null; } @@ -93,6 +97,14 @@ namespace grapher ContainingForm.ActiveControl = null; } + public void SetToEntered(double value) + { + SetToEntered(); + + Data = value; + Box.Text = Data.ToString("N2"); + } + public void SetToUnavailable() { if (State != FieldState.Unavailable) @@ -129,6 +141,7 @@ namespace grapher break; case FieldState.Unavailable: Box.Text = string.Empty; + ContainingForm.ActiveControl = null; break; default: break; diff --git a/grapher/FieldXY.cs b/grapher/FieldXY.cs new file mode 100644 index 0000000..f06cc4f --- /dev/null +++ b/grapher/FieldXY.cs @@ -0,0 +1,82 @@ +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 FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData) + { + XField = new Field(xBox, containingForm, defaultData); + YField = new Field(yBox, containingForm, defaultData); + LockCheckBox = lockCheckBox; + DefaultData = defaultData; + LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); + SetLocked(); + } + public double X + { + get => XField.Data; + } + + public double Y + { + get + { + if (Locked) + { + return X; + } + else + { + return YField.Data; + } + } + } + + public CheckBox LockCheckBox { get; } + + private Field XField { get; } + + private Field YField { get; } + + private double DefaultData { get; } + + private bool Locked { get; set; } + + private void CheckChanged(object sender, EventArgs e) + { + if (LockCheckBox.CheckState == CheckState.Checked) + { + SetUnlocked(); + } + else + { + SetLocked(); + } + } + + private void SetLocked() + { + Locked = true; + YField.SetToUnavailable(); + } + + private void SetUnlocked() + { + Locked = false; + if (XField.State == Field.FieldState.Default) + { + YField.SetToDefault(); + } + else + { + YField.SetToEntered(XField.Data); + } + } + } +} diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index fcfa239..c7be8c7 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -28,18 +28,18 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea12 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend12 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series12 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); - this.sensitivityBox = new System.Windows.Forms.TextBox(); + this.sensitivityBoxX = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.rotationBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.accelerationBox = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); - this.capBox = new System.Windows.Forms.TextBox(); + this.capBoxX = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.weightBoxFirst = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); @@ -51,25 +51,31 @@ this.offsetBox = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.writeButton = new System.Windows.Forms.Button(); + this.sensitivityBoxY = new System.Windows.Forms.TextBox(); + this.capBoxY = new System.Windows.Forms.TextBox(); + this.sensXYLock = new System.Windows.Forms.CheckBox(); + this.capXYLock = new System.Windows.Forms.CheckBox(); + this.weightXYLock = new System.Windows.Forms.CheckBox(); + this.LockXYLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); this.SuspendLayout(); // // AccelerationChart // - chartArea12.AxisX.Title = "Speed (counts/ms)"; - chartArea12.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea12.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea12); - legend12.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend12); - this.AccelerationChart.Location = new System.Drawing.Point(162, 0); + chartArea2.AxisX.Title = "Speed (counts/ms)"; + chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea2.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend2); + this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series12.ChartArea = "ChartArea1"; - series12.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series12.Legend = "Legend1"; - series12.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series12); - this.AccelerationChart.Size = new System.Drawing.Size(801, 312); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series2); + this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; // @@ -84,24 +90,23 @@ "Logarithmic", "Sigmoid", "Power"}); - this.accelTypeDrop.Location = new System.Drawing.Point(15, 86); + this.accelTypeDrop.Location = new System.Drawing.Point(14, 89); this.accelTypeDrop.Name = "accelTypeDrop"; - this.accelTypeDrop.Size = new System.Drawing.Size(132, 21); + this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); this.accelTypeDrop.TabIndex = 2; this.accelTypeDrop.Text = "Acceleration Type"; // - // sensitivityBox + // sensitivityBoxX // - this.sensitivityBox.Location = new System.Drawing.Point(96, 15); - this.sensitivityBox.Name = "sensitivityBox"; - this.sensitivityBox.Size = new System.Drawing.Size(51, 20); - this.sensitivityBox.TabIndex = 3; - this.sensitivityBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.sensitivityBox_KeyDown); + this.sensitivityBoxX.Location = new System.Drawing.Point(95, 37); + this.sensitivityBoxX.Name = "sensitivityBoxX"; + this.sensitivityBoxX.Size = new System.Drawing.Size(32, 20); + this.sensitivityBoxX.TabIndex = 3; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(15, 18); + this.label1.Location = new System.Drawing.Point(14, 40); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(54, 13); this.label1.TabIndex = 4; @@ -109,15 +114,15 @@ // // rotationBox // - this.rotationBox.Location = new System.Drawing.Point(96, 45); + this.rotationBox.Location = new System.Drawing.Point(95, 63); this.rotationBox.Name = "rotationBox"; - this.rotationBox.Size = new System.Drawing.Size(51, 20); + this.rotationBox.Size = new System.Drawing.Size(70, 20); this.rotationBox.TabIndex = 5; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(22, 48); + this.label2.Location = new System.Drawing.Point(24, 66); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(47, 13); this.label2.TabIndex = 6; @@ -125,32 +130,31 @@ // // accelerationBox // - this.accelerationBox.Location = new System.Drawing.Point(96, 113); + this.accelerationBox.Location = new System.Drawing.Point(96, 116); this.accelerationBox.Name = "accelerationBox"; - this.accelerationBox.Size = new System.Drawing.Size(51, 20); + this.accelerationBox.Size = new System.Drawing.Size(70, 20); this.accelerationBox.TabIndex = 7; // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(15, 116); + this.label4.Location = new System.Drawing.Point(14, 119); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(66, 13); this.label4.TabIndex = 9; this.label4.Text = "Acceleration"; // - // capBox + // capBoxX // - this.capBox.Location = new System.Drawing.Point(96, 140); - this.capBox.Name = "capBox"; - this.capBox.Size = new System.Drawing.Size(51, 20); - this.capBox.TabIndex = 10; - this.capBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.capBox_KeyDown); + this.capBoxX.Location = new System.Drawing.Point(95, 142); + this.capBoxX.Name = "capBoxX"; + this.capBoxX.Size = new System.Drawing.Size(32, 20); + this.capBoxX.TabIndex = 10; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(25, 143); + this.label3.Location = new System.Drawing.Point(30, 145); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(26, 13); this.label3.TabIndex = 11; @@ -158,15 +162,15 @@ // // weightBoxFirst // - this.weightBoxFirst.Location = new System.Drawing.Point(96, 167); + this.weightBoxFirst.Location = new System.Drawing.Point(95, 168); this.weightBoxFirst.Name = "weightBoxFirst"; - this.weightBoxFirst.Size = new System.Drawing.Size(24, 20); + this.weightBoxFirst.Size = new System.Drawing.Size(32, 20); this.weightBoxFirst.TabIndex = 12; // // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(25, 173); + this.label5.Location = new System.Drawing.Point(24, 171); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(41, 13); this.label5.TabIndex = 13; @@ -174,22 +178,22 @@ // // weightBoxSecond // - this.weightBoxSecond.Location = new System.Drawing.Point(126, 167); + this.weightBoxSecond.Location = new System.Drawing.Point(134, 168); this.weightBoxSecond.Name = "weightBoxSecond"; - this.weightBoxSecond.Size = new System.Drawing.Size(21, 20); + this.weightBoxSecond.Size = new System.Drawing.Size(32, 20); this.weightBoxSecond.TabIndex = 14; // // limitBox // - this.limitBox.Location = new System.Drawing.Point(96, 219); + this.limitBox.Location = new System.Drawing.Point(95, 220); this.limitBox.Name = "limitBox"; - this.limitBox.Size = new System.Drawing.Size(51, 20); + this.limitBox.Size = new System.Drawing.Size(70, 20); this.limitBox.TabIndex = 15; // // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(12, 222); + this.label6.Location = new System.Drawing.Point(14, 223); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(78, 13); this.label6.TabIndex = 16; @@ -197,15 +201,15 @@ // // midpointBox // - this.midpointBox.Location = new System.Drawing.Point(96, 245); + this.midpointBox.Location = new System.Drawing.Point(95, 246); this.midpointBox.Name = "midpointBox"; - this.midpointBox.Size = new System.Drawing.Size(51, 20); + this.midpointBox.Size = new System.Drawing.Size(70, 20); this.midpointBox.TabIndex = 17; // // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(22, 248); + this.label7.Location = new System.Drawing.Point(21, 249); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(47, 13); this.label7.TabIndex = 18; @@ -213,15 +217,15 @@ // // offsetBox // - this.offsetBox.Location = new System.Drawing.Point(96, 193); + this.offsetBox.Location = new System.Drawing.Point(95, 194); this.offsetBox.Name = "offsetBox"; - this.offsetBox.Size = new System.Drawing.Size(51, 20); + this.offsetBox.Size = new System.Drawing.Size(70, 20); this.offsetBox.TabIndex = 19; // // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(25, 200); + this.label8.Location = new System.Drawing.Point(30, 197); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(35, 13); this.label8.TabIndex = 20; @@ -229,7 +233,7 @@ // // writeButton // - this.writeButton.Location = new System.Drawing.Point(28, 271); + this.writeButton.Location = new System.Drawing.Point(47, 272); this.writeButton.Name = "writeButton"; this.writeButton.Size = new System.Drawing.Size(102, 23); this.writeButton.TabIndex = 21; @@ -237,11 +241,73 @@ this.writeButton.UseVisualStyleBackColor = true; this.writeButton.Click += new System.EventHandler(this.writeButton_Click); // + // sensitivityBoxY + // + this.sensitivityBoxY.Location = new System.Drawing.Point(133, 37); + this.sensitivityBoxY.Name = "sensitivityBoxY"; + this.sensitivityBoxY.Size = new System.Drawing.Size(32, 20); + this.sensitivityBoxY.TabIndex = 22; + // + // capBoxY + // + this.capBoxY.Location = new System.Drawing.Point(135, 142); + this.capBoxY.Name = "capBoxY"; + this.capBoxY.Size = new System.Drawing.Size(31, 20); + this.capBoxY.TabIndex = 23; + // + // sensXYLock + // + this.sensXYLock.AutoSize = true; + this.sensXYLock.Checked = true; + this.sensXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.sensXYLock.Location = new System.Drawing.Point(188, 40); + this.sensXYLock.Name = "sensXYLock"; + this.sensXYLock.Size = new System.Drawing.Size(15, 14); + this.sensXYLock.TabIndex = 24; + this.sensXYLock.UseVisualStyleBackColor = true; + // + // capXYLock + // + this.capXYLock.AutoSize = true; + this.capXYLock.Checked = true; + this.capXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.capXYLock.Location = new System.Drawing.Point(188, 145); + this.capXYLock.Name = "capXYLock"; + this.capXYLock.Size = new System.Drawing.Size(15, 14); + this.capXYLock.TabIndex = 25; + this.capXYLock.UseVisualStyleBackColor = true; + // + // weightXYLock + // + this.weightXYLock.AutoSize = true; + this.weightXYLock.Checked = true; + this.weightXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.weightXYLock.Location = new System.Drawing.Point(188, 171); + this.weightXYLock.Name = "weightXYLock"; + this.weightXYLock.Size = new System.Drawing.Size(15, 14); + this.weightXYLock.TabIndex = 26; + this.weightXYLock.UseVisualStyleBackColor = true; + // + // LockXYLabel + // + this.LockXYLabel.AutoSize = true; + this.LockXYLabel.Location = new System.Drawing.Point(165, 21); + this.LockXYLabel.Name = "LockXYLabel"; + this.LockXYLabel.Size = new System.Drawing.Size(60, 13); + this.LockXYLabel.TabIndex = 27; + this.LockXYLabel.Text = "Lock X && Y"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(963, 310); + this.ClientSize = new System.Drawing.Size(963, 312); + this.Controls.Add(this.LockXYLabel); + this.Controls.Add(this.weightXYLock); + this.Controls.Add(this.capXYLock); + this.Controls.Add(this.sensXYLock); + this.Controls.Add(this.capBoxY); + this.Controls.Add(this.sensitivityBoxY); this.Controls.Add(this.writeButton); this.Controls.Add(this.label8); this.Controls.Add(this.offsetBox); @@ -253,13 +319,13 @@ this.Controls.Add(this.label5); this.Controls.Add(this.weightBoxFirst); this.Controls.Add(this.label3); - this.Controls.Add(this.capBox); + this.Controls.Add(this.capBoxX); this.Controls.Add(this.label4); this.Controls.Add(this.accelerationBox); this.Controls.Add(this.label2); this.Controls.Add(this.rotationBox); this.Controls.Add(this.label1); - this.Controls.Add(this.sensitivityBox); + this.Controls.Add(this.sensitivityBoxX); this.Controls.Add(this.accelTypeDrop); this.Controls.Add(this.AccelerationChart); this.Name = "RawAcceleration"; @@ -275,13 +341,13 @@ private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; private System.Windows.Forms.ComboBox accelTypeDrop; - private System.Windows.Forms.TextBox sensitivityBox; + private System.Windows.Forms.TextBox sensitivityBoxX; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox rotationBox; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox accelerationBox; private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox capBox; + private System.Windows.Forms.TextBox capBoxX; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox weightBoxFirst; private System.Windows.Forms.Label label5; @@ -293,6 +359,12 @@ private System.Windows.Forms.TextBox offsetBox; private System.Windows.Forms.Label label8; private System.Windows.Forms.Button writeButton; + private System.Windows.Forms.TextBox sensitivityBoxY; + private System.Windows.Forms.TextBox capBoxY; + private System.Windows.Forms.CheckBox sensXYLock; + private System.Windows.Forms.CheckBox capXYLock; + private System.Windows.Forms.CheckBox weightXYLock; + private System.Windows.Forms.Label LockXYLabel; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index ef0dd3a..2bc4da7 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -20,14 +20,14 @@ namespace grapher ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); AccelerationType = 5; - Sensitivity = new VectorXY(1); - Rotation = new Field("0.0", rotationBox, this, 0); - Weight = new VectorXY(1); - Cap = new VectorXY(0); - Offset = new Field("0.0", offsetBox, this, 0); - Acceleration = new Field("0.0", accelerationBox, this, 0); - LimitOrExponent = new Field("2.0", limitBox, this, 2); - Midpoint = new Field("0.0", midpointBox, this, 0); + Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); + Rotation = new Field(rotationBox, this, 0); + Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); + Cap = new FieldXY(capBoxX, capBoxY, capXYLock, this, 0); + Offset = new Field(offsetBox, this, 0); + Acceleration = new Field(accelerationBox, this, 0); + LimitOrExponent = new Field(limitBox, this, 2); + Midpoint = new Field(midpointBox, this, 0); UpdateGraph(); @@ -59,13 +59,13 @@ namespace grapher private int AccelerationType { get; set; } - private VectorXY Sensitivity { get; set; } + private FieldXY Sensitivity { get; set; } private Field Rotation { get; set; } - private VectorXY Weight { get; set; } + private FieldXY Weight { get; set; } - private VectorXY Cap { get; set; } + private FieldXY Cap { get; set; } private Field Offset { get; set; } @@ -165,22 +165,6 @@ namespace grapher UpdateGraph(); } - private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Sensitivity.SetBoth(data); - } - } - - private void capBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Cap.SetBoth(data); - } - } - #endregion Methods } } diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 9c29da4..7b0849f 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -48,6 +48,7 @@ + Form -- cgit v1.2.3 From c30c1382668e716a245255083a48d8c6a9f3db36 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 21:09:48 -0700 Subject: Fix a few bugs around fieldXY --- grapher/Field.cs | 6 +++++- grapher/FieldXY.cs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'grapher') diff --git a/grapher/Field.cs b/grapher/Field.cs index 3f4b170..0f65e3e 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -79,6 +79,7 @@ namespace grapher { Box.BackColor = Color.White; Box.ForeColor = Color.Black; + State = FieldState.Typing; } @@ -91,6 +92,7 @@ namespace grapher { Box.BackColor = Color.AntiqueWhite; Box.ForeColor = Color.DarkGray; + State = FieldState.Entered; } @@ -112,6 +114,8 @@ namespace grapher Box.BackColor = Color.LightGray; Box.ForeColor = Color.LightGray; Box.Text = string.Empty; + + State = FieldState.Unavailable; } } @@ -158,9 +162,9 @@ namespace grapher } catch { - Box.Text = Data.ToString(); } + Box.Text = Data.ToString("N2"); e.Handled = true; e.SuppressKeyPress = true; diff --git a/grapher/FieldXY.cs b/grapher/FieldXY.cs index f06cc4f..60da3a4 100644 --- a/grapher/FieldXY.cs +++ b/grapher/FieldXY.cs @@ -52,11 +52,11 @@ namespace grapher { if (LockCheckBox.CheckState == CheckState.Checked) { - SetUnlocked(); + SetLocked(); } else { - SetLocked(); + SetUnlocked(); } } -- cgit v1.2.3 From d7e1121eb62b9842f9d19bddaf3e633d3dbe0924 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 21:26:13 -0700 Subject: Adde accel type switch --- grapher/Form1.Designer.cs | 29 +++++++++++++++-------------- grapher/Form1.cs | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) (limited to 'grapher') diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index c7be8c7..09a4da3 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -28,9 +28,9 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); @@ -62,19 +62,19 @@ // // AccelerationChart // - chartArea2.AxisX.Title = "Speed (counts/ms)"; - chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea2.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea2); - legend2.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend2); + chartArea1.AxisX.Title = "Speed (counts/ms)"; + chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea1.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend1); this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series2.ChartArea = "ChartArea1"; - series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series2.Legend = "Legend1"; - series2.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series2); + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series1.Legend = "Legend1"; + series1.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series1); this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; @@ -95,6 +95,7 @@ this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); this.accelTypeDrop.TabIndex = 2; this.accelTypeDrop.Text = "Acceleration Type"; + this.accelTypeDrop.SelectedIndexChanged += new System.EventHandler(this.accelTypeDrop_SelectedIndexChanged); // // sensitivityBoxX // diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 2bc4da7..8dd4b8b 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -166,5 +166,33 @@ namespace grapher } #endregion Methods + + private void accelTypeDrop_SelectedIndexChanged(object sender, EventArgs e) + { + switch(this.accelTypeDrop.SelectedItem.ToString()) + { + case ("Linear"): + AccelerationType = 1; + break; + case ("Classic"): + AccelerationType = 2; + break; + case ("Natural"): + AccelerationType = 3; + break; + case ("Logarithmic"): + AccelerationType = 4; + break; + case ("Sigmoid"): + AccelerationType = 5; + break; + case ("Power"): + AccelerationType = 6; + break; + default: + AccelerationType = 0; + break; + } + } } } -- cgit v1.2.3 From 20ea6f85cb0af56c13dabbfc3f65383af8793c7c Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 00:32:48 -0700 Subject: Fix small bugs, add AccelOptions class --- grapher/AccelOptions.cs | 68 +++++++++++++++++++++++++++++++++++++++++++++++ grapher/Field.cs | 40 +++++++++++++++++++++++++--- grapher/Form1.Designer.cs | 13 +++------ grapher/Form1.cs | 3 ++- grapher/grapher.csproj | 1 + 5 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 grapher/AccelOptions.cs (limited to 'grapher') diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs new file mode 100644 index 0000000..3aa6ef6 --- /dev/null +++ b/grapher/AccelOptions.cs @@ -0,0 +1,68 @@ +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 string Off = "Off"; + public const string Linear = "Linear"; + public const string Classic = "Classic"; + public const string Natural = "Natural"; + public const string Logarithmic = "Logarithmic"; + public const string Sigmoid = "Sigmoid"; + public const string Power = "Power"; + + /// + /// Holds mapping from acceleration type to identifying integer. + /// Must match order in tagged_union in rawaccel.hpp (which is 1-indexed, meaning 0 is off.) + /// + public static readonly Dictionary TypeToIndex = new Dictionary + { + { Off, 0 }, + { Linear, 1 }, + { Classic, 2 }, + { Natural, 3 }, + { Logarithmic, 4 }, + { Sigmoid, 5 }, + { Power, 6 }, + }; + + public AccelOptions(ComboBox accelDropdown) + { + AccelDropdown = accelDropdown; + AccelDropdown.Items.Clear(); + AccelDropdown.Items.AddRange(TypeToIndex.Keys.ToArray()); + } + + public ComboBox AccelDropdown { get; } + + public int AccelerationIndex { get; private set; } + + private void OnIndexChanged(object sender, EventArgs e) + { + var AccelerationType = AccelDropdown.SelectedItem.ToString(); + AccelerationIndex = TypeToIndex[AccelerationType]; + + /* + switch (AccelerationType) + { + case Linear: + LayoutLinear(); + default: + LayoutDefault(); + break; + } + */ + } + + private void LayoutDefault() + { + + } + } +} diff --git a/grapher/Field.cs b/grapher/Field.cs index 0f65e3e..6e1c6d2 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -28,13 +28,14 @@ namespace grapher public Field(TextBox box, Form containingForm, double defaultData) { - DefaultText = defaultData.ToString("N1"); + DefaultText = DecimalString(defaultData); Box = box; Data = defaultData; DefaultData = defaultData; State = FieldState.Undefined; ContainingForm = containingForm; box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown); + box.Leave += new System.EventHandler(FocusLeave); SetToDefault(); } @@ -53,6 +54,8 @@ namespace grapher public FieldState State { get; private set; } + public FieldState PreviousState { get; private set; } + private double DefaultData { get; } #endregion Properties @@ -66,6 +69,7 @@ namespace grapher Box.BackColor = Color.White; Box.ForeColor = Color.Gray; State = FieldState.Default; + PreviousState = FieldState.Default; } Data = DefaultData; @@ -80,6 +84,7 @@ namespace grapher Box.BackColor = Color.White; Box.ForeColor = Color.Black; + PreviousState = State; State = FieldState.Typing; } @@ -93,6 +98,7 @@ namespace grapher Box.BackColor = Color.AntiqueWhite; Box.ForeColor = Color.DarkGray; + PreviousState = State; State = FieldState.Entered; } @@ -104,7 +110,7 @@ namespace grapher SetToEntered(); Data = value; - Box.Text = Data.ToString("N2"); + Box.Text = DecimalString(Data); } public void SetToUnavailable() @@ -115,6 +121,7 @@ namespace grapher Box.ForeColor = Color.LightGray; Box.Text = string.Empty; + PreviousState = State; State = FieldState.Unavailable; } } @@ -152,6 +159,22 @@ namespace grapher } } + private void FocusLeave(object sender, EventArgs e) + { + if (State == FieldState.Typing) + { + if (PreviousState == FieldState.Default) + { + SetToDefault(); + } + else if (PreviousState == FieldState.Entered) + { + SetToEntered(); + Box.Text = DecimalString(Data); + } + } + } + private void HandleTyping(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) @@ -164,12 +187,23 @@ namespace grapher { } - Box.Text = Data.ToString("N2"); + Box.Text = DecimalString(Data); e.Handled = true; e.SuppressKeyPress = true; SetToEntered(); } + else if (e.KeyCode == Keys.Escape) + { + ContainingForm.ActiveControl = null; + e.Handled = true; + e.SuppressKeyPress = true; + } + } + + private static string DecimalString(double value) + { + return value.ToString("N2"); } #endregion Methods diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 09a4da3..b2bc052 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -1,4 +1,6 @@ -namespace grapher +using System.Linq; + +namespace grapher { partial class RawAcceleration { @@ -82,14 +84,7 @@ // accelTypeDrop // this.accelTypeDrop.FormattingEnabled = true; - this.accelTypeDrop.Items.AddRange(new object[] { - "Off", - "Linear", - "Classic", - "Natural", - "Logarithmic", - "Sigmoid", - "Power"}); + this.accelTypeDrop.Items.AddRange(AccelOptions.TypeToIndex.Keys.ToArray()); this.accelTypeDrop.Location = new System.Drawing.Point(14, 89); this.accelTypeDrop.Name = "accelTypeDrop"; this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 8dd4b8b..e35f097 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,7 +19,7 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); - AccelerationType = 5; + AccelerationType = 0; Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); Rotation = new Field(rotationBox, this, 0); Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); @@ -151,6 +151,7 @@ namespace grapher { ManagedAcceleration.UpdateAccel( AccelerationType, + Rotation.Data, Sensitivity.X, Sensitivity.Y, Weight.X, diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 7b0849f..d8ce5d3 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -47,6 +47,7 @@ + -- cgit v1.2.3 From 3cbec32cfa91bad661bc126b517faf78458a27a6 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 01:13:24 -0700 Subject: Fully use acceloptions --- grapher/AccelOptions.cs | 101 ++++++++++++++++++++++++++++++++++++++++++++-- grapher/Form1.Designer.cs | 101 ++++++++++++++++++++++++---------------------- grapher/Form1.cs | 37 +++++------------ grapher/Option.cs | 39 ++++++++++++++++++ grapher/grapher.csproj | 1 + 5 files changed, 200 insertions(+), 79 deletions(-) create mode 100644 grapher/Option.cs (limited to 'grapher') diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs index 3aa6ef6..093ebe7 100644 --- a/grapher/AccelOptions.cs +++ b/grapher/AccelOptions.cs @@ -32,37 +32,132 @@ namespace grapher { Power, 6 }, }; - public AccelOptions(ComboBox accelDropdown) + public AccelOptions( + ComboBox accelDropdown, + Option constOptionOne, + Option constOptionTwo, + Option constOptionThree + ) { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); AccelDropdown.Items.AddRange(TypeToIndex.Keys.ToArray()); + AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); + + ConstOptionOne = constOptionOne; + ConstOptionTwo = constOptionTwo; + ConstOptionThree = constOptionThree; } public ComboBox AccelDropdown { get; } public int AccelerationIndex { get; private set; } + public Option ConstOptionOne { get; } + + public Option ConstOptionTwo { get; } + + public Option ConstOptionThree { get; } + private void OnIndexChanged(object sender, EventArgs e) { var AccelerationType = AccelDropdown.SelectedItem.ToString(); AccelerationIndex = TypeToIndex[AccelerationType]; - /* switch (AccelerationType) { case Linear: LayoutLinear(); + break; + case Classic: + LayoutClassic(); + break; + case Natural: + LayoutNatural(); + break; + case Logarithmic: + LayoutLogarithmic(); + break; + case Sigmoid: + LayoutSigmoid(); + break; + case Power: + LayoutPower(); + break; default: LayoutDefault(); break; } - */ } private void LayoutDefault() { + ConstOptionOne.Show(); + ConstOptionTwo.Show(); + ConstOptionThree.Hide(); + + ConstOptionOne.SetName("Acceleration"); + ConstOptionTwo.SetName("Limit\\Exponent"); + } + + private void LayoutLinear() + { + ConstOptionOne.Show(); + ConstOptionTwo.Hide(); + ConstOptionThree.Hide(); + + ConstOptionOne.SetName("Acceleration"); + } + + private void LayoutClassic() + { + ConstOptionOne.Show(); + ConstOptionTwo.Show(); + ConstOptionThree.Hide(); + + ConstOptionOne.SetName("Acceleration"); + ConstOptionTwo.SetName("Exponent"); + } + + private void LayoutNatural() + { + ConstOptionOne.Show(); + ConstOptionTwo.Show(); + ConstOptionThree.Hide(); + + ConstOptionOne.SetName("Acceleration"); + ConstOptionOne.SetName("Limit"); + } + + private void LayoutLogarithmic() + { + ConstOptionOne.Show(); + ConstOptionTwo.Hide(); + ConstOptionThree.Hide(); + + ConstOptionOne.SetName("Acceleration"); + } + + + private void LayoutSigmoid() + { + ConstOptionOne.Show(); + ConstOptionTwo.Show(); + ConstOptionThree.Show(); + + ConstOptionOne.SetName("Acceleration"); + ConstOptionTwo.SetName("Limit"); + ConstOptionThree.SetName("Midpoint"); + } + + private void LayoutPower() + { + ConstOptionOne.Show(); + ConstOptionTwo.Show(); + ConstOptionThree.Hide(); + ConstOptionOne.SetName("Scale"); + ConstOptionTwo.SetName("Exponent"); } } } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index b2bc052..ac936d3 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -30,9 +30,9 @@ namespace grapher /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); @@ -40,16 +40,16 @@ namespace grapher this.rotationBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.accelerationBox = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); + this.constantOneLabel = new System.Windows.Forms.Label(); this.capBoxX = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.weightBoxFirst = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.weightBoxSecond = new System.Windows.Forms.TextBox(); this.limitBox = new System.Windows.Forms.TextBox(); - this.label6 = new System.Windows.Forms.Label(); + this.constantTwoLabel = new System.Windows.Forms.Label(); this.midpointBox = new System.Windows.Forms.TextBox(); - this.label7 = new System.Windows.Forms.Label(); + this.constantThreeLabel = new System.Windows.Forms.Label(); this.offsetBox = new System.Windows.Forms.TextBox(); this.label8 = new System.Windows.Forms.Label(); this.writeButton = new System.Windows.Forms.Button(); @@ -64,19 +64,19 @@ namespace grapher // // AccelerationChart // - chartArea1.AxisX.Title = "Speed (counts/ms)"; - chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea1.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend1); + chartArea3.AxisX.Title = "Speed (counts/ms)"; + chartArea3.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea3.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea3); + legend3.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend3); this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series1.ChartArea = "ChartArea1"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series1.Legend = "Legend1"; - series1.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series1); + series3.ChartArea = "ChartArea1"; + series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series3.Legend = "Legend1"; + series3.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series3); this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; @@ -84,13 +84,11 @@ namespace grapher // accelTypeDrop // this.accelTypeDrop.FormattingEnabled = true; - this.accelTypeDrop.Items.AddRange(AccelOptions.TypeToIndex.Keys.ToArray()); this.accelTypeDrop.Location = new System.Drawing.Point(14, 89); this.accelTypeDrop.Name = "accelTypeDrop"; this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); this.accelTypeDrop.TabIndex = 2; this.accelTypeDrop.Text = "Acceleration Type"; - this.accelTypeDrop.SelectedIndexChanged += new System.EventHandler(this.accelTypeDrop_SelectedIndexChanged); // // sensitivityBoxX // @@ -131,14 +129,15 @@ namespace grapher this.accelerationBox.Size = new System.Drawing.Size(70, 20); this.accelerationBox.TabIndex = 7; // - // label4 + // constantOneLabel // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(14, 119); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(66, 13); - this.label4.TabIndex = 9; - this.label4.Text = "Acceleration"; + this.constantOneLabel.AutoSize = true; + this.constantOneLabel.Location = new System.Drawing.Point(14, 119); + this.constantOneLabel.Name = "constantOneLabel"; + this.constantOneLabel.Size = new System.Drawing.Size(66, 13); + this.constantOneLabel.TabIndex = 9; + this.constantOneLabel.Text = "Acceleration"; + this.constantOneLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // capBoxX // @@ -150,11 +149,13 @@ namespace grapher // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(30, 145); + this.label3.Location = new System.Drawing.Point(24, 146); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(26, 13); this.label3.TabIndex = 11; this.label3.Text = "Cap"; + this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label3.Click += new System.EventHandler(this.label3_Click); // // weightBoxFirst // @@ -171,6 +172,7 @@ namespace grapher this.label5.Size = new System.Drawing.Size(41, 13); this.label5.TabIndex = 13; this.label5.Text = "Weight"; + this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // weightBoxSecond // @@ -186,14 +188,15 @@ namespace grapher this.limitBox.Size = new System.Drawing.Size(70, 20); this.limitBox.TabIndex = 15; // - // label6 + // constantTwoLabel // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(14, 223); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(78, 13); - this.label6.TabIndex = 16; - this.label6.Text = "Limit/Exponent"; + this.constantTwoLabel.AutoSize = true; + this.constantTwoLabel.Location = new System.Drawing.Point(14, 223); + this.constantTwoLabel.Name = "constantTwoLabel"; + this.constantTwoLabel.Size = new System.Drawing.Size(78, 13); + this.constantTwoLabel.TabIndex = 16; + this.constantTwoLabel.Text = "Limit/Exponent"; + this.constantTwoLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // midpointBox // @@ -202,14 +205,15 @@ namespace grapher this.midpointBox.Size = new System.Drawing.Size(70, 20); this.midpointBox.TabIndex = 17; // - // label7 + // constantThreeLabel // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(21, 249); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(47, 13); - this.label7.TabIndex = 18; - this.label7.Text = "Midpoint"; + this.constantThreeLabel.AutoSize = true; + this.constantThreeLabel.Location = new System.Drawing.Point(21, 249); + this.constantThreeLabel.Name = "constantThreeLabel"; + this.constantThreeLabel.Size = new System.Drawing.Size(47, 13); + this.constantThreeLabel.TabIndex = 18; + this.constantThreeLabel.Text = "Midpoint"; + this.constantThreeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // offsetBox // @@ -221,11 +225,12 @@ namespace grapher // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(30, 197); + this.label8.Location = new System.Drawing.Point(24, 197); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(35, 13); this.label8.TabIndex = 20; this.label8.Text = "Offset"; + this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // writeButton // @@ -307,16 +312,16 @@ namespace grapher this.Controls.Add(this.writeButton); this.Controls.Add(this.label8); this.Controls.Add(this.offsetBox); - this.Controls.Add(this.label7); + this.Controls.Add(this.constantThreeLabel); this.Controls.Add(this.midpointBox); - this.Controls.Add(this.label6); + this.Controls.Add(this.constantTwoLabel); this.Controls.Add(this.limitBox); this.Controls.Add(this.weightBoxSecond); this.Controls.Add(this.label5); this.Controls.Add(this.weightBoxFirst); this.Controls.Add(this.label3); this.Controls.Add(this.capBoxX); - this.Controls.Add(this.label4); + this.Controls.Add(this.constantOneLabel); this.Controls.Add(this.accelerationBox); this.Controls.Add(this.label2); this.Controls.Add(this.rotationBox); @@ -342,16 +347,16 @@ namespace grapher private System.Windows.Forms.TextBox rotationBox; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox accelerationBox; - private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label constantOneLabel; private System.Windows.Forms.TextBox capBoxX; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox weightBoxFirst; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox weightBoxSecond; private System.Windows.Forms.TextBox limitBox; - private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label constantTwoLabel; private System.Windows.Forms.TextBox midpointBox; - private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label constantThreeLabel; private System.Windows.Forms.TextBox offsetBox; private System.Windows.Forms.Label label8; private System.Windows.Forms.Button writeButton; diff --git a/grapher/Form1.cs b/grapher/Form1.cs index e35f097..ecb6ead 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,7 +19,11 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); - AccelerationType = 0; + AccelerationOptions = new AccelOptions( + accelTypeDrop, + new Option(accelerationBox, constantOneLabel), + new Option(limitBox, constantTwoLabel), + new Option(midpointBox, constantThreeLabel)); Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); Rotation = new Field(rotationBox, this, 0); Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); @@ -57,7 +61,7 @@ namespace grapher public ManagedAccel ManagedAcceleration { get; set; } - private int AccelerationType { get; set; } + private AccelOptions AccelerationOptions { get; set; } private FieldXY Sensitivity { get; set; } @@ -150,7 +154,7 @@ namespace grapher private void writeButton_Click(object sender, EventArgs e) { ManagedAcceleration.UpdateAccel( - AccelerationType, + AccelerationOptions.AccelerationIndex, Rotation.Data, Sensitivity.X, Sensitivity.Y, @@ -168,32 +172,9 @@ namespace grapher #endregion Methods - private void accelTypeDrop_SelectedIndexChanged(object sender, EventArgs e) + private void label3_Click(object sender, EventArgs e) { - switch(this.accelTypeDrop.SelectedItem.ToString()) - { - case ("Linear"): - AccelerationType = 1; - break; - case ("Classic"): - AccelerationType = 2; - break; - case ("Natural"): - AccelerationType = 3; - break; - case ("Logarithmic"): - AccelerationType = 4; - break; - case ("Sigmoid"): - AccelerationType = 5; - break; - case ("Power"): - AccelerationType = 6; - break; - default: - AccelerationType = 0; - break; - } + } } } diff --git a/grapher/Option.cs b/grapher/Option.cs new file mode 100644 index 0000000..6c7bcda --- /dev/null +++ b/grapher/Option.cs @@ -0,0 +1,39 @@ +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(TextBox box, Label label) + { + Box = box; + Label = label; + } + + public TextBox Box { get; } + + public Label Label { get; } + + public void SetName(string name) + { + Label.Text = name; + } + + public void Hide() + { + Box.Hide(); + Label.Hide(); + } + + public void Show() + { + Box.Show(); + Label.Show(); + } + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index d8ce5d3..3d0f50a 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -56,6 +56,7 @@ Form1.cs + -- cgit v1.2.3 From f315e8160e984df93be6667929db34749aa25cfa Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 02:00:20 -0700 Subject: Use class heirarchy for layout types --- grapher/AccelOptions.cs | 156 +++++++-------------------------------- grapher/Form1.cs | 9 ++- grapher/Layouts/ClassicLayout.cs | 19 +++++ grapher/Layouts/DefaultLayout.cs | 20 +++++ grapher/Layouts/LayoutBase.cs | 52 +++++++++++++ grapher/Layouts/LinearLayout.cs | 19 +++++ grapher/Layouts/LogLayout.cs | 19 +++++ grapher/Layouts/NaturalLayout.cs | 19 +++++ grapher/Layouts/PowerLayout.cs | 19 +++++ grapher/Layouts/SigmoidLayout.cs | 19 +++++ grapher/Option.cs | 9 +++ grapher/grapher.csproj | 8 ++ 12 files changed, 234 insertions(+), 134 deletions(-) create mode 100644 grapher/Layouts/ClassicLayout.cs create mode 100644 grapher/Layouts/DefaultLayout.cs create mode 100644 grapher/Layouts/LayoutBase.cs create mode 100644 grapher/Layouts/LinearLayout.cs create mode 100644 grapher/Layouts/LogLayout.cs create mode 100644 grapher/Layouts/NaturalLayout.cs create mode 100644 grapher/Layouts/PowerLayout.cs create mode 100644 grapher/Layouts/SigmoidLayout.cs (limited to 'grapher') diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs index 093ebe7..0235bc7 100644 --- a/grapher/AccelOptions.cs +++ b/grapher/AccelOptions.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Layouts; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,155 +10,48 @@ namespace grapher { public class AccelOptions { - public const string Off = "Off"; - public const string Linear = "Linear"; - public const string Classic = "Classic"; - public const string Natural = "Natural"; - public const string Logarithmic = "Logarithmic"; - public const string Sigmoid = "Sigmoid"; - public const string Power = "Power"; + public const int PossibleOptionsCount = 3; - /// - /// Holds mapping from acceleration type to identifying integer. - /// Must match order in tagged_union in rawaccel.hpp (which is 1-indexed, meaning 0 is off.) - /// - public static readonly Dictionary TypeToIndex = new Dictionary + public static readonly Dictionary AccelerationTypes = new List { - { Off, 0 }, - { Linear, 1 }, - { Classic, 2 }, - { Natural, 3 }, - { Logarithmic, 4 }, - { Sigmoid, 5 }, - { Power, 6 }, - }; + new DefaultLayout(), + new LinearLayout(), + new ClassicLayout(), + new NaturalLayout(), + new LogLayout(), + new SigmoidLayout(), + new PowerLayout(), + }.ToDictionary(k => k.Name); public AccelOptions( ComboBox accelDropdown, - Option constOptionOne, - Option constOptionTwo, - Option constOptionThree - ) + Option[] options) { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); - AccelDropdown.Items.AddRange(TypeToIndex.Keys.ToArray()); + AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); - ConstOptionOne = constOptionOne; - ConstOptionTwo = constOptionTwo; - ConstOptionThree = constOptionThree; - } - - public ComboBox AccelDropdown { get; } - - public int AccelerationIndex { get; private set; } - - public Option ConstOptionOne { get; } - - public Option ConstOptionTwo { get; } - - public Option ConstOptionThree { get; } - - private void OnIndexChanged(object sender, EventArgs e) - { - var AccelerationType = AccelDropdown.SelectedItem.ToString(); - AccelerationIndex = TypeToIndex[AccelerationType]; - - switch (AccelerationType) + if (options.Length > PossibleOptionsCount) { - case Linear: - LayoutLinear(); - break; - case Classic: - LayoutClassic(); - break; - case Natural: - LayoutNatural(); - break; - case Logarithmic: - LayoutLogarithmic(); - break; - case Sigmoid: - LayoutSigmoid(); - break; - case Power: - LayoutPower(); - break; - default: - LayoutDefault(); - break; + throw new Exception("Layout given too many options."); } - } - - private void LayoutDefault() - { - ConstOptionOne.Show(); - ConstOptionTwo.Show(); - ConstOptionThree.Hide(); - - ConstOptionOne.SetName("Acceleration"); - ConstOptionTwo.SetName("Limit\\Exponent"); - } - - private void LayoutLinear() - { - ConstOptionOne.Show(); - ConstOptionTwo.Hide(); - ConstOptionThree.Hide(); - ConstOptionOne.SetName("Acceleration"); - } - - private void LayoutClassic() - { - ConstOptionOne.Show(); - ConstOptionTwo.Show(); - ConstOptionThree.Hide(); - - ConstOptionOne.SetName("Acceleration"); - ConstOptionTwo.SetName("Exponent"); - } - - private void LayoutNatural() - { - ConstOptionOne.Show(); - ConstOptionTwo.Show(); - ConstOptionThree.Hide(); - - ConstOptionOne.SetName("Acceleration"); - ConstOptionOne.SetName("Limit"); - } - - private void LayoutLogarithmic() - { - ConstOptionOne.Show(); - ConstOptionTwo.Hide(); - ConstOptionThree.Hide(); - - ConstOptionOne.SetName("Acceleration"); + Options = options; } + public ComboBox AccelDropdown { get; } - private void LayoutSigmoid() - { - ConstOptionOne.Show(); - ConstOptionTwo.Show(); - ConstOptionThree.Show(); + public int AccelerationIndex { get; private set; } - ConstOptionOne.SetName("Acceleration"); - ConstOptionTwo.SetName("Limit"); - ConstOptionThree.SetName("Midpoint"); - } + public Option[] Options { get; } - private void LayoutPower() + private void OnIndexChanged(object sender, EventArgs e) { - ConstOptionOne.Show(); - ConstOptionTwo.Show(); - ConstOptionThree.Hide(); - - ConstOptionOne.SetName("Scale"); - ConstOptionTwo.SetName("Exponent"); + var AccelerationTypeString = AccelDropdown.SelectedItem.ToString(); + var AccelerationType = AccelerationTypes[AccelerationTypeString]; + AccelerationIndex = AccelerationType.Index; + AccelerationType.Layout(Options); } } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index ecb6ead..93e0768 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -21,9 +21,12 @@ namespace grapher ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); AccelerationOptions = new AccelOptions( accelTypeDrop, - new Option(accelerationBox, constantOneLabel), - new Option(limitBox, constantTwoLabel), - new Option(midpointBox, constantThreeLabel)); + new Option[] + { + new Option(accelerationBox, constantOneLabel), + new Option(limitBox, constantTwoLabel), + new Option(midpointBox, constantThreeLabel) + }); Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); Rotation = new Field(rotationBox, this, 0); Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs new file mode 100644 index 0000000..a8fc2bd --- /dev/null +++ b/grapher/Layouts/ClassicLayout.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class ClassicLayout : LayoutBase + { + public ClassicLayout() + { + Name = "Classic"; + Index = 2; + Show = new bool[] { true, true, false }; + OptionNames = new string[] { Acceleration, Exponent, string.Empty }; + } + } +} diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs new file mode 100644 index 0000000..2ad3c0e --- /dev/null +++ b/grapher/Layouts/DefaultLayout.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Layouts +{ + public class DefaultLayout : LayoutBase + { + public DefaultLayout() + { + Name = "Off"; + Index = 0; + Show = new bool[] { true, true, true }; + OptionNames = new string[] { Acceleration, $"{Limit}\\{Exponent}", Midpoint }; + } + } +} diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs new file mode 100644 index 0000000..9c60008 --- /dev/null +++ b/grapher/Layouts/LayoutBase.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public abstract class LayoutBase + { + public const string Acceleration = "Acceleration"; + public const string Scale = "Scale"; + public const string Exponent = "Exponent"; + public const string Limit = "Limit"; + public const string Midpoint = "Midpoint"; + + public LayoutBase() + { + Show = new bool[] { false, false, false }; + OptionNames = new string[] { string.Empty, string.Empty, string.Empty }; + } + + /// + /// Gets or sets mapping from acceleration type to identifying integer. + /// Must match order in tagged_union in rawaccel.hpp (which is 1-indexed, meaning 0 is off.) + /// + public int Index { get; internal set; } + + public string Name { get; internal set; } + + internal bool[] Show { get; set; } + + internal string[] OptionNames { get; set; } + + public void Layout(Option[] options) + { + // Relies on AccelOptions to keep lengths correct. + for (int i = 0; i< options.Length; i++) + { + if (Show[i]) + { + options[i].Show(OptionNames[i]); + } + else + { + options[i].Hide(); + } + } + + } + } +} diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs new file mode 100644 index 0000000..b500b6b --- /dev/null +++ b/grapher/Layouts/LinearLayout.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class LinearLayout : LayoutBase + { + public LinearLayout() + { + Name = "Linear"; + Index = 1; + Show = new bool[] { true, false, false }; + OptionNames = new string[] { Acceleration, string.Empty, string.Empty }; + } + } +} diff --git a/grapher/Layouts/LogLayout.cs b/grapher/Layouts/LogLayout.cs new file mode 100644 index 0000000..7c7fd9e --- /dev/null +++ b/grapher/Layouts/LogLayout.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class LogLayout : LayoutBase + { + public LogLayout() + { + Name = "Logarithmic"; + Index = 4; + Show = new bool[] { true, false, false }; + OptionNames = new string[] { Acceleration, string.Empty, string.Empty }; + } + } +} diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs new file mode 100644 index 0000000..180a7c0 --- /dev/null +++ b/grapher/Layouts/NaturalLayout.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class NaturalLayout : LayoutBase + { + public NaturalLayout() + { + Name = "Natural"; + Index = 3; + Show = new bool[] { true, true, false }; + OptionNames = new string[] { Acceleration, Limit, string.Empty }; + } + } +} diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs new file mode 100644 index 0000000..6d4f5d7 --- /dev/null +++ b/grapher/Layouts/PowerLayout.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class PowerLayout : LayoutBase + { + public PowerLayout() + { + Name = "Power"; + Index = 6; + Show = new bool[] { true, true, false }; + OptionNames = new string[] { Scale, Exponent, string.Empty }; + } + } +} diff --git a/grapher/Layouts/SigmoidLayout.cs b/grapher/Layouts/SigmoidLayout.cs new file mode 100644 index 0000000..88d6c61 --- /dev/null +++ b/grapher/Layouts/SigmoidLayout.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Layouts +{ + public class SigmoidLayout : LayoutBase + { + public SigmoidLayout() + { + Name = "Sigmoid"; + Index = 5; + Show = new bool[] { true, true, true }; + OptionNames = new string[] { Acceleration, Limit, Midpoint }; + } + } +} diff --git a/grapher/Option.cs b/grapher/Option.cs index 6c7bcda..17e624b 100644 --- a/grapher/Option.cs +++ b/grapher/Option.cs @@ -22,6 +22,7 @@ namespace grapher public void SetName(string name) { Label.Text = name; + Label.Left = Convert.ToInt32((Box.Left / 2.0) - (Label.Width / 2.0)); } public void Hide() @@ -35,5 +36,13 @@ namespace grapher Box.Show(); Label.Show(); } + + public void Show(string name) + { + SetName(name); + + Box.Show(); + Label.Show(); + } } } diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 3d0f50a..91518ce 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -56,6 +56,14 @@ Form1.cs + + + + + + + + -- cgit v1.2.3 From 49bd00c71b223d12f1d85d5c1bae635d450403fd Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 20:15:12 -0700 Subject: Use options instead of fields --- grapher/Field.cs | 2 +- grapher/FieldXY.cs | 7 +-- grapher/Form1.Designer.cs | 136 +++++++++++++++++++++++----------------------- grapher/Form1.cs | 94 ++++++++++++++------------------ grapher/Option.cs | 14 ++--- grapher/OptionXY.cs | 51 +++++++++++++++++ grapher/grapher.csproj | 1 + 7 files changed, 170 insertions(+), 135 deletions(-) create mode 100644 grapher/OptionXY.cs (limited to 'grapher') diff --git a/grapher/Field.cs b/grapher/Field.cs index 6e1c6d2..7ce4c6e 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -44,7 +44,7 @@ namespace grapher #region Properties - TextBox Box { get; } + public TextBox Box { get; } Form ContainingForm { get; } diff --git a/grapher/FieldXY.cs b/grapher/FieldXY.cs index 60da3a4..23c5de1 100644 --- a/grapher/FieldXY.cs +++ b/grapher/FieldXY.cs @@ -14,7 +14,6 @@ namespace grapher XField = new Field(xBox, containingForm, defaultData); YField = new Field(yBox, containingForm, defaultData); LockCheckBox = lockCheckBox; - DefaultData = defaultData; LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); SetLocked(); } @@ -40,11 +39,9 @@ namespace grapher public CheckBox LockCheckBox { get; } - private Field XField { get; } + public Field XField { get; } - private Field YField { get; } - - private double DefaultData { get; } + public Field YField { get; } private bool Locked { get; set; } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index ac936d3..decdeeb 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -30,28 +30,28 @@ namespace grapher /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); + this.sensitivityLabel = new System.Windows.Forms.Label(); this.rotationBox = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); + this.rotationLabel = new System.Windows.Forms.Label(); this.accelerationBox = new System.Windows.Forms.TextBox(); this.constantOneLabel = new System.Windows.Forms.Label(); this.capBoxX = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); + this.capLabel = new System.Windows.Forms.Label(); this.weightBoxFirst = new System.Windows.Forms.TextBox(); - this.label5 = new System.Windows.Forms.Label(); + this.weightLabel = new System.Windows.Forms.Label(); this.weightBoxSecond = new System.Windows.Forms.TextBox(); this.limitBox = new System.Windows.Forms.TextBox(); this.constantTwoLabel = new System.Windows.Forms.Label(); this.midpointBox = new System.Windows.Forms.TextBox(); this.constantThreeLabel = new System.Windows.Forms.Label(); this.offsetBox = new System.Windows.Forms.TextBox(); - this.label8 = new System.Windows.Forms.Label(); + this.offsetLabel = new System.Windows.Forms.Label(); this.writeButton = new System.Windows.Forms.Button(); this.sensitivityBoxY = new System.Windows.Forms.TextBox(); this.capBoxY = new System.Windows.Forms.TextBox(); @@ -64,19 +64,19 @@ namespace grapher // // AccelerationChart // - chartArea3.AxisX.Title = "Speed (counts/ms)"; - chartArea3.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea3.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea3); - legend3.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend3); + chartArea1.AxisX.Title = "Speed (counts/ms)"; + chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea1.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend1); this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series3.ChartArea = "ChartArea1"; - series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series3.Legend = "Legend1"; - series3.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series3); + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series1.Legend = "Legend1"; + series1.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series1); this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; @@ -97,14 +97,14 @@ namespace grapher this.sensitivityBoxX.Size = new System.Drawing.Size(32, 20); this.sensitivityBoxX.TabIndex = 3; // - // label1 + // sensitivityLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(14, 40); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(54, 13); - this.label1.TabIndex = 4; - this.label1.Text = "Sensitivity"; + this.sensitivityLabel.AutoSize = true; + this.sensitivityLabel.Location = new System.Drawing.Point(14, 40); + this.sensitivityLabel.Name = "sensitivityLabel"; + this.sensitivityLabel.Size = new System.Drawing.Size(54, 13); + this.sensitivityLabel.TabIndex = 4; + this.sensitivityLabel.Text = "Sensitivity"; // // rotationBox // @@ -113,14 +113,14 @@ namespace grapher this.rotationBox.Size = new System.Drawing.Size(70, 20); this.rotationBox.TabIndex = 5; // - // label2 + // rotationLabel // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(24, 66); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(47, 13); - this.label2.TabIndex = 6; - this.label2.Text = "Rotation"; + this.rotationLabel.AutoSize = true; + this.rotationLabel.Location = new System.Drawing.Point(24, 66); + this.rotationLabel.Name = "rotationLabel"; + this.rotationLabel.Size = new System.Drawing.Size(47, 13); + this.rotationLabel.TabIndex = 6; + this.rotationLabel.Text = "Rotation"; // // accelerationBox // @@ -146,16 +146,16 @@ namespace grapher this.capBoxX.Size = new System.Drawing.Size(32, 20); this.capBoxX.TabIndex = 10; // - // label3 + // capLabel // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(24, 146); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(26, 13); - this.label3.TabIndex = 11; - this.label3.Text = "Cap"; - this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.label3.Click += new System.EventHandler(this.label3_Click); + this.capLabel.AutoSize = true; + this.capLabel.Location = new System.Drawing.Point(24, 146); + this.capLabel.Name = "capLabel"; + this.capLabel.Size = new System.Drawing.Size(26, 13); + this.capLabel.TabIndex = 11; + this.capLabel.Text = "Cap"; + this.capLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.capLabel.Click += new System.EventHandler(this.label3_Click); // // weightBoxFirst // @@ -164,15 +164,15 @@ namespace grapher this.weightBoxFirst.Size = new System.Drawing.Size(32, 20); this.weightBoxFirst.TabIndex = 12; // - // label5 + // weightLabel // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(24, 171); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(41, 13); - this.label5.TabIndex = 13; - this.label5.Text = "Weight"; - this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.weightLabel.AutoSize = true; + this.weightLabel.Location = new System.Drawing.Point(24, 171); + this.weightLabel.Name = "weightLabel"; + this.weightLabel.Size = new System.Drawing.Size(41, 13); + this.weightLabel.TabIndex = 13; + this.weightLabel.Text = "Weight"; + this.weightLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // weightBoxSecond // @@ -222,15 +222,15 @@ namespace grapher this.offsetBox.Size = new System.Drawing.Size(70, 20); this.offsetBox.TabIndex = 19; // - // label8 + // offsetLabel // - this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(24, 197); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(35, 13); - this.label8.TabIndex = 20; - this.label8.Text = "Offset"; - this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.offsetLabel.AutoSize = true; + this.offsetLabel.Location = new System.Drawing.Point(24, 197); + this.offsetLabel.Name = "offsetLabel"; + this.offsetLabel.Size = new System.Drawing.Size(35, 13); + this.offsetLabel.TabIndex = 20; + this.offsetLabel.Text = "Offset"; + this.offsetLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // writeButton // @@ -310,22 +310,22 @@ namespace grapher this.Controls.Add(this.capBoxY); this.Controls.Add(this.sensitivityBoxY); this.Controls.Add(this.writeButton); - this.Controls.Add(this.label8); + this.Controls.Add(this.offsetLabel); this.Controls.Add(this.offsetBox); this.Controls.Add(this.constantThreeLabel); this.Controls.Add(this.midpointBox); this.Controls.Add(this.constantTwoLabel); this.Controls.Add(this.limitBox); this.Controls.Add(this.weightBoxSecond); - this.Controls.Add(this.label5); + this.Controls.Add(this.weightLabel); this.Controls.Add(this.weightBoxFirst); - this.Controls.Add(this.label3); + this.Controls.Add(this.capLabel); this.Controls.Add(this.capBoxX); this.Controls.Add(this.constantOneLabel); this.Controls.Add(this.accelerationBox); - this.Controls.Add(this.label2); + this.Controls.Add(this.rotationLabel); this.Controls.Add(this.rotationBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.sensitivityLabel); this.Controls.Add(this.sensitivityBoxX); this.Controls.Add(this.accelTypeDrop); this.Controls.Add(this.AccelerationChart); @@ -343,22 +343,22 @@ namespace grapher private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; private System.Windows.Forms.ComboBox accelTypeDrop; private System.Windows.Forms.TextBox sensitivityBoxX; - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label sensitivityLabel; private System.Windows.Forms.TextBox rotationBox; - private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label rotationLabel; private System.Windows.Forms.TextBox accelerationBox; private System.Windows.Forms.Label constantOneLabel; private System.Windows.Forms.TextBox capBoxX; - private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label capLabel; private System.Windows.Forms.TextBox weightBoxFirst; - private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label weightLabel; private System.Windows.Forms.TextBox weightBoxSecond; private System.Windows.Forms.TextBox limitBox; private System.Windows.Forms.Label constantTwoLabel; private System.Windows.Forms.TextBox midpointBox; private System.Windows.Forms.Label constantThreeLabel; private System.Windows.Forms.TextBox offsetBox; - private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label offsetLabel; private System.Windows.Forms.Button writeButton; private System.Windows.Forms.TextBox sensitivityBoxY; private System.Windows.Forms.TextBox capBoxY; diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 93e0768..b1ab2fa 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,22 +19,31 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); + Sensitivity = new OptionXY(new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1), sensitivityLabel); + Rotation = new Option(new Field(rotationBox, this, 0), rotationLabel); + Weight = new OptionXY(new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1), weightLabel); + Cap = new OptionXY(new FieldXY(capBoxX, capBoxY, capXYLock, this, 0), capLabel); + Offset = new Option(new Field(offsetBox, this, 0), offsetLabel); + + Sensitivity.SetName("Sensitivity"); + Rotation.SetName("Rotation"); + Weight.SetName("Weight"); + Cap.SetName("Cap"); + Offset.SetName("Offset"); + + // The name and layout of these options is handled by AccelerationOptions object. + Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); + LimitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); + Midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); + AccelerationOptions = new AccelOptions( accelTypeDrop, new Option[] { - new Option(accelerationBox, constantOneLabel), - new Option(limitBox, constantTwoLabel), - new Option(midpointBox, constantThreeLabel) + Acceleration, + LimitOrExponent, + Midpoint, }); - Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); - Rotation = new Field(rotationBox, this, 0); - Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); - Cap = new FieldXY(capBoxX, capBoxY, capXYLock, this, 0); - Offset = new Field(offsetBox, this, 0); - Acceleration = new Field(accelerationBox, this, 0); - LimitOrExponent = new Field(limitBox, this, 2); - Midpoint = new Field(midpointBox, this, 0); UpdateGraph(); @@ -66,21 +75,21 @@ namespace grapher private AccelOptions AccelerationOptions { get; set; } - private FieldXY Sensitivity { get; set; } + private OptionXY Sensitivity { get; set; } - private Field Rotation { get; set; } + private Option Rotation { get; set; } - private FieldXY Weight { get; set; } + private OptionXY Weight { get; set; } - private FieldXY Cap { get; set; } + private OptionXY Cap { get; set; } - private Field Offset { get; set; } + private Option Offset { get; set; } - private Field Acceleration { get; set; } + private Option Acceleration { get; set; } - private Field LimitOrExponent { get; set; } + private Option LimitOrExponent { get; set; } - private Field Midpoint { get; set; } + private Option Midpoint { get; set; } #endregion Properties @@ -113,7 +122,7 @@ namespace grapher var inMagnitude = Magnitude(i,j); var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.X; + var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.Fields.X; if (!orderedPoints.ContainsKey(inMagnitude)) { @@ -131,44 +140,21 @@ namespace grapher } } - private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) - { - bool validEntry = false; - data = 0.0; - - if (e.KeyCode == Keys.Enter) - { - try - { - data = Convert.ToDouble(((TextBox)sender).Text); - validEntry = true; - } - catch - { - } - - e.Handled = true; - e.SuppressKeyPress = true; - } - - return validEntry; - } - private void writeButton_Click(object sender, EventArgs e) { ManagedAcceleration.UpdateAccel( AccelerationOptions.AccelerationIndex, - Rotation.Data, - Sensitivity.X, - Sensitivity.Y, - Weight.X, - Weight.Y, - Cap.X, - Cap.Y, - Offset.Data, - Acceleration.Data, - LimitOrExponent.Data, - Midpoint.Data); + Rotation.Field.Data, + Sensitivity.Fields.X, + Sensitivity.Fields.Y, + Weight.Fields.X, + Weight.Fields.Y, + Cap.Fields.X, + Cap.Fields.Y, + Offset.Field.Data, + Acceleration.Field.Data, + LimitOrExponent.Field.Data, + Midpoint.Field.Data); ManagedAcceleration.WriteToDriver(); UpdateGraph(); } diff --git a/grapher/Option.cs b/grapher/Option.cs index 17e624b..a2a4f89 100644 --- a/grapher/Option.cs +++ b/grapher/Option.cs @@ -9,31 +9,31 @@ namespace grapher { public class Option { - public Option(TextBox box, Label label) + public Option(Field field, Label label) { - Box = box; + Field = field; Label = label; } - public TextBox Box { get; } + public Field Field { get; } public Label Label { get; } public void SetName(string name) { Label.Text = name; - Label.Left = Convert.ToInt32((Box.Left / 2.0) - (Label.Width / 2.0)); + Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); } public void Hide() { - Box.Hide(); + Field.Box.Hide(); Label.Hide(); } public void Show() { - Box.Show(); + Field.Box.Show(); Label.Show(); } @@ -41,7 +41,7 @@ namespace grapher { SetName(name); - Box.Show(); + Field.Box.Show(); Label.Show(); } } diff --git a/grapher/OptionXY.cs b/grapher/OptionXY.cs new file mode 100644 index 0000000..c65d1cf --- /dev/null +++ b/grapher/OptionXY.cs @@ -0,0 +1,51 @@ +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 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.XField.Box.Hide(); + Fields.YField.Box.Hide(); + Label.Hide(); + } + + public void Show() + { + Fields.XField.Box.Show(); + Fields.YField.Box.Show(); + Label.Show(); + } + + public void Show(string name) + { + SetName(name); + + Fields.XField.Box.Show(); + Fields.YField.Box.Show(); + Label.Show(); + } + + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 91518ce..04d2eaa 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -65,6 +65,7 @@ + -- cgit v1.2.3 From 498e5c1a2fabed3ba5f1c00768d7050c5738e76e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Fri, 31 Jul 2020 10:46:23 -0700 Subject: Small refactoring, use new struct to store magnitudes --- grapher/AccelerationSettings.cs | 13 +++++++++ grapher/Field.cs | 2 +- grapher/Form1.Designer.cs | 28 +++++++++--------- grapher/Form1.cs | 64 +++++++++++++++++++++++++++-------------- grapher/Option.cs | 11 +++++++ grapher/OptionXY.cs | 33 ++++++++++++++++++++- grapher/grapher.csproj | 1 + 7 files changed, 114 insertions(+), 38 deletions(-) create mode 100644 grapher/AccelerationSettings.cs (limited to 'grapher') diff --git a/grapher/AccelerationSettings.cs b/grapher/AccelerationSettings.cs new file mode 100644 index 0000000..83d48db --- /dev/null +++ b/grapher/AccelerationSettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher +{ + public class AccelerationSettings + { + public sensitivity + } +} diff --git a/grapher/Field.cs b/grapher/Field.cs index 7ce4c6e..5ef057d 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -46,7 +46,7 @@ namespace grapher public TextBox Box { get; } - Form ContainingForm { get; } + private Form ContainingForm { get; } public double Data { get; private set; } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index decdeeb..4e89ca8 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -30,9 +30,9 @@ namespace grapher /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); @@ -64,19 +64,19 @@ namespace grapher // // AccelerationChart // - chartArea1.AxisX.Title = "Speed (counts/ms)"; - chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea1.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend1); + chartArea2.AxisX.Title = "Speed (counts/ms)"; + chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea2.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend2); this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series1.ChartArea = "ChartArea1"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series1.Legend = "Legend1"; - series1.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series1); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series2); this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; diff --git a/grapher/Form1.cs b/grapher/Form1.cs index b1ab2fa..c6ac407 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Drawing; @@ -12,24 +13,27 @@ namespace grapher { public partial class RawAcceleration : Form { + public struct MagnitudeData + { + public double magnitude; + public int x; + public int y; + } + #region Constructor + public static ReadOnlyCollection Magnitudes = GetMagnitudes(); + public RawAcceleration() { InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); - Sensitivity = new OptionXY(new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1), sensitivityLabel); - Rotation = new Option(new Field(rotationBox, this, 0), rotationLabel); - Weight = new OptionXY(new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1), weightLabel); - Cap = new OptionXY(new FieldXY(capBoxX, capBoxY, capXYLock, this, 0), capLabel); - Offset = new Option(new Field(offsetBox, this, 0), offsetLabel); - - Sensitivity.SetName("Sensitivity"); - Rotation.SetName("Rotation"); - Weight.SetName("Weight"); - Cap.SetName("Cap"); - Offset.SetName("Offset"); + Sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity"); + Rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); + Weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight"); + Cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap"); + Offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); // The name and layout of these options is handled by AccelerationOptions object. Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); @@ -95,6 +99,26 @@ namespace grapher #region Methods + public static ReadOnlyCollection GetMagnitudes() + { + var magnitudes = new List(); + 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); @@ -114,20 +138,16 @@ namespace grapher { var orderedPoints = new SortedDictionary(); - for (int i = 0; i < 100; i++) + foreach (var magnitudeData in Magnitudes) { - for (int j = 0; j <= i; j++) - { - var output = ManagedAcceleration.Accelerate(i, j, 1); + var output = ManagedAcceleration.Accelerate(magnitudeData.x, magnitudeData.y, 1); - var inMagnitude = Magnitude(i,j); - var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.Fields.X; + var outMagnitude = Magnitude(output.Item1, output.Item2); + var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X; - if (!orderedPoints.ContainsKey(inMagnitude)) - { - orderedPoints.Add(inMagnitude, ratio); - } + if (!orderedPoints.ContainsKey(magnitudeData.magnitude)) + { + orderedPoints.Add(magnitudeData.magnitude, ratio); } } diff --git a/grapher/Option.cs b/grapher/Option.cs index a2a4f89..8e3ecdf 100644 --- a/grapher/Option.cs +++ b/grapher/Option.cs @@ -15,6 +15,17 @@ namespace grapher 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; } diff --git a/grapher/OptionXY.cs b/grapher/OptionXY.cs index c65d1cf..de7fad9 100644 --- a/grapher/OptionXY.cs +++ b/grapher/OptionXY.cs @@ -8,12 +8,43 @@ using System.Windows.Forms; namespace grapher { public class OptionXY - { public OptionXY(FieldXY fields, Label label) + { + 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; } diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 04d2eaa..207de79 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -47,6 +47,7 @@ + -- cgit v1.2.3 From 827f860b80b5195315ac5b2b8dffb32cf532e0d1 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Fri, 31 Jul 2020 10:56:26 -0700 Subject: Add class for storing settings from file --- grapher/AccelerationSettings.cs | 24 +++++++++++++++++++++++- grapher/Form1.Designer.cs | 1 - grapher/Form1.cs | 5 ----- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'grapher') diff --git a/grapher/AccelerationSettings.cs b/grapher/AccelerationSettings.cs index 83d48db..dd026e8 100644 --- a/grapher/AccelerationSettings.cs +++ b/grapher/AccelerationSettings.cs @@ -8,6 +8,28 @@ namespace grapher { public class AccelerationSettings { - public sensitivity + public double SensitivityX { get; } + + public double SensitivityY { get; } + + public double Rotation { get; } + + public double Offset { get; } + + public double WeightX { get; } + + public double WeightY { get; } + + public double CapX { get; } + + public double CapY { get; } + + public int AccelerationType { get; } + + public double Acceleration { get; } + + public double LimitOrExponent { get; } + + public double Midpoint { get; } } } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 4e89ca8..667abf1 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -155,7 +155,6 @@ namespace grapher this.capLabel.TabIndex = 11; this.capLabel.Text = "Cap"; this.capLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.capLabel.Click += new System.EventHandler(this.label3_Click); // // weightBoxFirst // diff --git a/grapher/Form1.cs b/grapher/Form1.cs index c6ac407..e0953eb 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -180,10 +180,5 @@ namespace grapher } #endregion Methods - - private void label3_Click(object sender, EventArgs e) - { - - } } } -- cgit v1.2.3