From 491f4fa200bcd7ba4b49f2ecf0059f8ccc273ba1 Mon Sep 17 00:00:00 2001 From: Pratham Date: Thu, 9 Jan 2025 06:37:45 +0530 Subject: [PATCH] Enhance full parameter change message box (#3412) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Enhance parameter succesfully saved confirmation box to display changed parameters with previous and new value and count of total changed parameters * –Enhance full parameter change message box * –0 param change info solved * remove redundent confirmation and error handling * minor suggested changes --- GCSViews/ConfigurationView/ConfigRawParams.cs | 57 ++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/GCSViews/ConfigurationView/ConfigRawParams.cs b/GCSViews/ConfigurationView/ConfigRawParams.cs index 4005026afb..e4e8e0d112 100644 --- a/GCSViews/ConfigurationView/ConfigRawParams.cs +++ b/GCSViews/ConfigurationView/ConfigRawParams.cs @@ -253,9 +253,6 @@ private void BUT_save_Click(object sender, EventArgs e) private void BUT_writePIDS_Click(object sender, EventArgs e) { - if (Common.MessageShowAgain("Write Raw Params", "Are you Sure?") != DialogResult.OK) - return; - // sort with enable at the bottom - this ensures params are set before the function is disabled var temp = _changes.Keys.Cast().ToList(); @@ -265,6 +262,50 @@ private void BUT_writePIDS_Click(object sender, EventArgs e) int error = 0; bool reboot = false; + int maxdisplay = 20; + + if (temp.Count > 0 && temp.Count <= maxdisplay) + { + // List to track successfully saved parameters + List savedParams = new List(); + + foreach (string value in temp) + { + if (MainV2.comPort.BaseStream == null || !MainV2.comPort.BaseStream.IsOpen) + { + CustomMessageBox.Show("You are not connected", Strings.ERROR); + return; + } + + // Get the previous value of the param to display in 'param change info' + // (a better way would be to get the value somewhere from inside the code, insted of recieving it over mavlink) + string previousValue = MainV2.comPort.MAV.param[value].ToString(); + // new value of param + double newValue = (double)_changes[value]; + + // Add the parameter, previous and new values to the list for 'param change info' + // remember, the 'value' here is key of param, while prev and new are actual values of param + savedParams.Add($"{value}: {previousValue} -> {newValue}"); + } + + // Join the saved parameters list to a string + string savedParamsMessage = string.Join(Environment.NewLine, savedParams); + + // Ask the user for confirmation showing detailed changes + if (CustomMessageBox.Show($"You are about to change {savedParams.Count} parameters. Please review the changes below:\n\n{savedParamsMessage}\n\nDo you want to proceed?", "Confirm Parameter Changes", + CustomMessageBox.MessageBoxButtons.YesNo, CustomMessageBox.MessageBoxIcon.Information) != + CustomMessageBox.DialogResult.Yes) + return; + } + else if (temp.Count > maxdisplay) + { + // Ask the user for confirmation without listing individual changes + if (CustomMessageBox.Show($"You are about to change {temp.Count} parameters. Are you sure you want to proceed?", "Confirm Parameter Changes", + CustomMessageBox.MessageBoxButtons.YesNo, CustomMessageBox.MessageBoxIcon.Information) != + CustomMessageBox.DialogResult.Yes) + return; + } + foreach (string value in temp) { @@ -278,9 +319,9 @@ private void BUT_writePIDS_Click(object sender, EventArgs e) MainV2.comPort.setParam(value, (double)_changes[value]); //check if reboot required - if (ParameterMetaDataRepository.GetParameterRebootRequired(value, MainV2.comPort.MAV.cs.firmware.ToString())) - { - reboot = true; + if (ParameterMetaDataRepository.GetParameterRebootRequired(value, MainV2.comPort.MAV.cs.firmware.ToString())) + { + reboot = true; } try { @@ -321,8 +362,10 @@ private void BUT_writePIDS_Click(object sender, EventArgs e) if (error > 0) CustomMessageBox.Show("Not all parameters successfully saved.", "Saved"); + else if (temp.Count>0) + CustomMessageBox.Show($"{temp.Count} parameters successfully saved.", "Saved"); else - CustomMessageBox.Show("Parameters successfully saved.", "Saved"); + CustomMessageBox.Show("No parameters were changed.", "No changes"); //Check if reboot is required if (reboot)