From dc76635349577f9dd95ab347fb79652dad2abb30 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 30 Jun 2021 23:52:31 -0700 Subject: Better-written LUT panels --- grapher/Form1.Designer.cs | 106 ++++++++++++++---- grapher/Form1.cs | 10 +- grapher/Models/AccelGUIFactory.cs | 22 +++- grapher/Models/Options/AccelTypeOptions.cs | 3 + grapher/Models/Options/LUT/LUTPanelOptions.cs | 149 ++++++++++++++++++++++---- 5 files changed, 245 insertions(+), 45 deletions(-) diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index fc742ac..415b5e0 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -71,8 +71,8 @@ namespace grapher System.Windows.Forms.DataVisualization.Charting.Title title6 = new System.Windows.Forms.DataVisualization.Charting.Title(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RawAcceleration)); this.optionsPanel = new System.Windows.Forms.Panel(); - this.richTextBox2 = new System.Windows.Forms.RichTextBox(); - this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.YLutPointsBox = new System.Windows.Forms.RichTextBox(); + this.XLutPointsBox = new System.Windows.Forms.RichTextBox(); this.LUTPanelY = new System.Windows.Forms.Panel(); this.LUTPanelX = new System.Windows.Forms.Panel(); this.gainSwitchActiveLabelY = new System.Windows.Forms.Label(); @@ -192,6 +192,12 @@ namespace grapher this.GainChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.XLutApplyLabel = new System.Windows.Forms.Label(); + this.YLutApplyLabel = new System.Windows.Forms.Label(); + this.LutApplyActiveXLabel = new System.Windows.Forms.Label(); + this.XLutApplyDropdown = new System.Windows.Forms.ComboBox(); + this.YLutApplyDropdown = new System.Windows.Forms.ComboBox(); + this.LutApplyActiveYLabel = new System.Windows.Forms.Label(); this.optionsPanel.SuspendLayout(); this.DirectionalityPanel.SuspendLayout(); this.menuStrip1.SuspendLayout(); @@ -207,8 +213,14 @@ namespace grapher // optionsPanel // this.optionsPanel.AutoSize = true; - this.optionsPanel.Controls.Add(this.richTextBox2); - this.optionsPanel.Controls.Add(this.richTextBox1); + this.optionsPanel.Controls.Add(this.LutApplyActiveYLabel); + this.optionsPanel.Controls.Add(this.YLutApplyDropdown); + this.optionsPanel.Controls.Add(this.XLutApplyDropdown); + this.optionsPanel.Controls.Add(this.LutApplyActiveXLabel); + this.optionsPanel.Controls.Add(this.YLutApplyLabel); + this.optionsPanel.Controls.Add(this.XLutApplyLabel); + this.optionsPanel.Controls.Add(this.YLutPointsBox); + this.optionsPanel.Controls.Add(this.XLutPointsBox); this.optionsPanel.Controls.Add(this.LUTPanelY); this.optionsPanel.Controls.Add(this.LUTPanelX); this.optionsPanel.Controls.Add(this.gainSwitchActiveLabelY); @@ -297,21 +309,21 @@ namespace grapher this.optionsPanel.Size = new System.Drawing.Size(483, 956); this.optionsPanel.TabIndex = 34; // - // richTextBox2 + // YLutPointsBox // - this.richTextBox2.Location = new System.Drawing.Point(397, 447); - this.richTextBox2.Name = "richTextBox2"; - this.richTextBox2.Size = new System.Drawing.Size(73, 57); - this.richTextBox2.TabIndex = 161; - this.richTextBox2.Text = ""; + this.YLutPointsBox.Location = new System.Drawing.Point(397, 447); + this.YLutPointsBox.Name = "YLutPointsBox"; + this.YLutPointsBox.Size = new System.Drawing.Size(73, 57); + this.YLutPointsBox.TabIndex = 161; + this.YLutPointsBox.Text = ""; // - // richTextBox1 + // XLutPointsBox // - this.richTextBox1.Location = new System.Drawing.Point(317, 447); - this.richTextBox1.Name = "richTextBox1"; - this.richTextBox1.Size = new System.Drawing.Size(68, 57); - this.richTextBox1.TabIndex = 160; - this.richTextBox1.Text = ""; + this.XLutPointsBox.Location = new System.Drawing.Point(317, 447); + this.XLutPointsBox.Name = "XLutPointsBox"; + this.XLutPointsBox.Size = new System.Drawing.Size(68, 57); + this.XLutPointsBox.TabIndex = 160; + this.XLutPointsBox.Text = ""; // // LUTPanelY // @@ -1555,6 +1567,58 @@ namespace grapher title6.Text = "Sensitivity"; this.AccelerationChart.Titles.Add(title6); // + // XLutApplyLabel + // + this.XLutApplyLabel.AutoSize = true; + this.XLutApplyLabel.Location = new System.Drawing.Point(317, 511); + this.XLutApplyLabel.Name = "XLutApplyLabel"; + this.XLutApplyLabel.Size = new System.Drawing.Size(47, 13); + this.XLutApplyLabel.TabIndex = 162; + this.XLutApplyLabel.Text = "Apply as"; + // + // YLutApplyLabel + // + this.YLutApplyLabel.AutoSize = true; + this.YLutApplyLabel.Location = new System.Drawing.Point(397, 510); + this.YLutApplyLabel.Name = "YLutApplyLabel"; + this.YLutApplyLabel.Size = new System.Drawing.Size(47, 13); + this.YLutApplyLabel.TabIndex = 163; + this.YLutApplyLabel.Text = "Apply as"; + // + // LutApplyActiveXLabel + // + this.LutApplyActiveXLabel.AutoSize = true; + this.LutApplyActiveXLabel.Location = new System.Drawing.Point(200, 565); + this.LutApplyActiveXLabel.Name = "LutApplyActiveXLabel"; + this.LutApplyActiveXLabel.Size = new System.Drawing.Size(35, 13); + this.LutApplyActiveXLabel.TabIndex = 164; + this.LutApplyActiveXLabel.Text = "label1"; + // + // XLutApplyDropdown + // + this.XLutApplyDropdown.FormattingEnabled = true; + this.XLutApplyDropdown.Location = new System.Drawing.Point(320, 527); + this.XLutApplyDropdown.Name = "XLutApplyDropdown"; + this.XLutApplyDropdown.Size = new System.Drawing.Size(65, 21); + this.XLutApplyDropdown.TabIndex = 165; + // + // YLutApplyDropdown + // + this.YLutApplyDropdown.FormattingEnabled = true; + this.YLutApplyDropdown.Location = new System.Drawing.Point(397, 527); + this.YLutApplyDropdown.Name = "YLutApplyDropdown"; + this.YLutApplyDropdown.Size = new System.Drawing.Size(73, 21); + this.YLutApplyDropdown.TabIndex = 166; + // + // LutApplyActiveYLabel + // + this.LutApplyActiveYLabel.AutoSize = true; + this.LutApplyActiveYLabel.Location = new System.Drawing.Point(417, 565); + this.LutApplyActiveYLabel.Name = "LutApplyActiveYLabel"; + this.LutApplyActiveYLabel.Size = new System.Drawing.Size(35, 13); + this.LutApplyActiveYLabel.TabIndex = 167; + this.LutApplyActiveYLabel.Text = "label1"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1704,8 +1768,14 @@ namespace grapher private System.Windows.Forms.Label gainSwitchActiveLabelX; private System.Windows.Forms.Panel LUTPanelY; private System.Windows.Forms.Panel LUTPanelX; - private System.Windows.Forms.RichTextBox richTextBox2; - private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.RichTextBox YLutPointsBox; + private System.Windows.Forms.RichTextBox XLutPointsBox; + private System.Windows.Forms.Label LutApplyActiveYLabel; + private System.Windows.Forms.ComboBox YLutApplyDropdown; + private System.Windows.Forms.ComboBox XLutApplyDropdown; + private System.Windows.Forms.Label LutApplyActiveXLabel; + private System.Windows.Forms.Label YLutApplyLabel; + private System.Windows.Forms.Label XLutApplyLabel; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 2b2ad42..113fc4d 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -59,6 +59,8 @@ namespace grapher GainChartY, accelTypeDropX, accelTypeDropY, + XLutApplyDropdown, + YLutApplyDropdown, writeButton, toggleButton, showVelocityGainToolStripMenuItem, @@ -102,6 +104,8 @@ namespace grapher gainSwitchY, LUTPanelX, LUTPanelY, + XLutPointsBox, + YLutPointsBox, LockXYLabel, sensitivityLabel, rotationLabel, @@ -162,7 +166,11 @@ namespace grapher DomainActiveValueY, DirectionalityRangeLabel, RangeActiveValueX, - RangeActiveValueY); + RangeActiveValueY, + XLutApplyLabel, + YLutApplyLabel, + LutApplyActiveXLabel, + LutApplyActiveYLabel); ResizeAndCenter(); } diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 5035598..b82cf59 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -26,6 +26,8 @@ namespace grapher.Models Chart gainChartY, ComboBox accelTypeDropX, ComboBox accelTypeDropY, + ComboBox lutApplyDropdownX, + ComboBox lutApplyDropdownY, Button writeButton, ButtonBase toggleButton, ToolStripMenuItem showVelocityGainToolStripMenuItem, @@ -69,6 +71,8 @@ namespace grapher.Models CheckBox gainSwitchY, Panel lutPanelX, Panel lutPanelY, + RichTextBox xLutPointsBox, + RichTextBox yLutPointsBox, Label lockXYLabel, Label sensitivityLabel, Label rotationLabel, @@ -129,7 +133,11 @@ namespace grapher.Models Label domainActiveValueY, Label rangeLabel, Label rangeActiveValueX, - Label rangeActiveValueY) + Label rangeActiveValueY, + Label lutApplyLabelX, + Label lutApplyLabelY, + Label lutApplyActiveValueX, + Label lutApplyActiveValueY) { fakeBox.Checked = false; fakeBox.Hide(); @@ -339,7 +347,11 @@ namespace grapher.Models exponentX, midpointX, lutTextX, - new LUTPanelOptions(lutPanelX), + new LUTPanelOptions(lutPanelX, xLutPointsBox), + new LutApplyOptions( + lutApplyLabelX, + lutApplyDropdownX, + new ActiveValueLabel(lutApplyActiveValueX, activeValueTitleX)), writeButton, new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); @@ -355,7 +367,11 @@ namespace grapher.Models exponentY, midpointY, lutTextY, - new LUTPanelOptions(lutPanelY), + new LUTPanelOptions(lutPanelY, yLutPointsBox), + new LutApplyOptions( + lutApplyLabelY, + lutApplyDropdownY, + new ActiveValueLabel(lutApplyActiveValueY, activeValueTitleY)), writeButton, new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index cc2480c..08ab111 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -40,6 +40,7 @@ namespace grapher Option midpoint, TextOption lutText, LUTPanelOptions lutPanelOptions, + LutApplyOptions lutApplyOptions, Button writeButton, ActiveValueLabel accelTypeActiveValue) { @@ -73,6 +74,7 @@ namespace grapher AccelTypeActiveValue = accelTypeActiveValue; LutText = lutText; LutPanel = lutPanelOptions; + LutApply = lutApplyOptions; AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; AccelTypeActiveValue.Height = AccelDropdown.Height; @@ -237,6 +239,7 @@ namespace grapher Limit.SetActiveValue(args.limit); Exponent.SetActiveValue(args.exponent); Midpoint.SetActiveValue(args.midpoint); + LutPanel.SetActiveValues(args.tableData.points); LutApply.SetActiveValue(args.tableData.velocity); } diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index e723dcd..6425d91 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -10,39 +10,33 @@ namespace grapher.Models.Options.LUT { public class LUTPanelOptions : OptionBase { - public const string ApplyAsSensTitle = "Apply as sensitivity"; - public const string ApplyAsVelocityTitle = "Apply as velocity"; - public const int TitlePadding = 5; + public const int PanelPadding = 5; public const int PanelHeight = 100; - public LUTPanelOptions(Panel activePanel) + public LUTPanelOptions(Panel activePanel, RichTextBox pointsTextBox) { + PointsTextBox = pointsTextBox; + ActivePanel = activePanel; ActivePanel.Height = PanelHeight; ActivePanel.Paint += Panel_Paint; - ApplyAsSens = new CheckBox(); - ApplyAsSens.Text = ApplyAsSensTitle; - ApplyAsVelocity = new CheckBox(); - ApplyAsVelocity.Text = ApplyAsVelocityTitle; - } - - public Panel ActivePanel - { - get; + ActiveValuesTextBox = new RichTextBox(); + ActiveValuesTextBox.ReadOnly = true; + ActivePanel.Controls.Add(ActiveValuesTextBox); } - public Label Title + public RichTextBox PointsTextBox { get; } - public CheckBox ApplyAsSens + public RichTextBox ActiveValuesTextBox { get; } - public CheckBox ApplyAsVelocity + public Panel ActivePanel { get; } @@ -51,7 +45,7 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Visible || ShouldShow; + return PointsTextBox.Visible || ShouldShow; } } @@ -59,10 +53,11 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Top; + return PointsTextBox.Top; } set { + PointsTextBox.Top = value; ActivePanel.Top = value; } } @@ -71,7 +66,7 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Height; + return PointsTextBox.Height; } } @@ -79,11 +74,12 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Left; + return PointsTextBox.Left; } set { - ActivePanel.Left = value; + PointsTextBox.Left = value; + AlignActivePanelToPointsTextBox(); } } @@ -91,11 +87,14 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Width; + return PointsTextBox.Width; } set { - ActivePanel.Width = value; + var panelWidth = value / 2 - PanelPadding; + PointsTextBox.Width = panelWidth; + ActivePanel.Width = panelWidth; + AlignActivePanelToPointsTextBox(); } } @@ -103,12 +102,14 @@ namespace grapher.Models.Options.LUT public override void Hide() { + PointsTextBox.Hide(); ActivePanel.Hide(); ShouldShow = false; } public override void Show(string name) { + PointsTextBox.Show(); ActivePanel.Show(); ShouldShow = true; } @@ -118,6 +119,108 @@ namespace grapher.Models.Options.LUT // Nothing to do here. } + public void SetActiveValues(IEnumerable> activePoints) + { + if (activePoints.Any() && activePoints.First().x != 0) + { + ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints); + } + else + { + ActiveValuesTextBox.Text = string.Empty; + } + } + + public Vec2[] GetPoints() + { + return UserTextToPoints(PointsTextBox.Text); + } + + private static Vec2[] UserTextToPoints(string userText) + { + if (string.IsNullOrWhiteSpace(userText)) + { + throw new Exception("Text must be entered in text box to fill Look Up Table."); + } + + Vec2[] points = new Vec2[256]; + + var userTextSplit = userText.Split(';'); + int index = 0; + float lastX = 0; + + foreach(var pointEntry in userTextSplit) + { + var pointSplit = pointEntry.Trim().Split(','); + + if (pointSplit.Length != 2) + { + throw new Exception($"Point at index {index} is malformed. Expected format: x,y; Given: {pointEntry.Trim()}"); + } + + float x; + float y; + + try + { + x = float.Parse(pointSplit[0]); + } + catch (Exception ex) + { + throw new Exception($"X-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[0]}", ex); + } + + if (x <= 0) + { + throw new Exception($"X-value for point at index {index} is less than or equal to 0. Point (0,0) is implied and should not be specified in points text."); + } + + if (x <= lastX) + { + throw new Exception($"X-value for point at index {index} is less than or equal to previous x-value. Value: {x} Previous: {lastX}"); + } + + lastX = x; + + try + { + y = float.Parse(pointSplit[1]); + } + catch (Exception ex) + { + throw new Exception($"Y-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[1]}", ex); + } + + if (y <= 0) + { + throw new Exception($"Y-value for point at index {index} is less than or equal to 0. Value: {y}"); + } + + points[index] = new Vec2 { x = x, y = y }; + + index++; + } + + return points; + } + + private void AlignActivePanelToPointsTextBox() + { + ActivePanel.Left = PointsTextBox.Right + PanelPadding; + } + + private string PointsToActiveValuesText(IEnumerable> points) + { + StringBuilder builder = new StringBuilder(); + + foreach(var point in points) + { + builder.AppendLine($"{point.x},{point.y};"); + } + + return builder.ToString(); + } + private void Panel_Paint(object sender, PaintEventArgs e) { Color col = Color.DarkGray; -- cgit v1.2.3