/// <summary> /// Display the result /// </summary> public void DisplayOutputs(bool Exact, Result result) { if (!((result.BaseResistors.R1 == 0) && (result.BaseResistors.R2 == 0))) { if (CheckboxExact.Checked == true) { // Affichage des valeurs exactes textbox_outR1.Text = result.BaseResistors.R1.ToString() + "Ω"; textbox_outR2.Text = result.BaseResistors.R2.ToString() + "Ω"; textbox_outR.Text = result.Resistor.ToString(); textbox_outError.Text = $"{result.Error}%"; } else { // Affichage des valeurs arrondies textbox_outR1.Text = Tools2.DecimalToEngineer(result.BaseResistors.R1); textbox_outR2.Text = Tools2.DecimalToEngineer(result.BaseResistors.R2); textbox_outR.Text = Tools2.DecimalToEngineer(Math.Round(result.Resistor, 3)); textbox_outError.Text = $"{Math.Round(result.Error, 3)}%"; } labelSerieParallel.Text = result.Parallel ? "||" : "+"; } }
/// <summary> /// Display text containing all results /// </summary> public void DisplayList(BackgroundWorker b) { msg = string.Empty; // Use multiple strings to increase speed List <string> msgs = new List <string>(); // Add header line msgs.Add(string.Empty); // Progress int progress; // Line counter int count = 0; // Number of lines int max_i = Results.Count; // Result to display Result result; // Fixed length of the longest double value to be displayed (to have a nice formatted text) int maxlength = 0; // Is exact mode enabled if (Exact) { WriteLog("Exact mode ON", Logger.Log_level.Debug); maxlength = maxRes.ToString().Length; msgs[0] += $"{"R1".PadRight(maxlength)} {" "} {"R2".PadRight(maxlength)} {"Req".PadRight(16)} {"Error [%]"}{Environment.NewLine}"; } else { WriteLog("Exact mode OFF", Logger.Log_level.Debug); msgs[0] += $"{"R1".PadRight(6)} {" "} {"R2".PadRight(6)} {"Req".PadRight(9)} {"Error [%]"}{Environment.NewLine}"; } // Loop every results for (int i = 0; i < max_i; i++) { // If cancel requested if (b.CancellationPending) { WriteLog("Display List skipped", Logger.Log_level.Info); break; } // Retrieve result result = Results[i]; // If exact mode enabled if (Exact) { msgs[count] += $"{result.BaseResistors.R1.ToString().PadRight(maxlength)} {(result.Parallel ? "||" : " +")} {result.BaseResistors.R2.ToString().PadRight(maxlength)} = {result.Resistor.ToString().PadRight(16)} {((result.Error >= 0) ? (" ") : (""))}{result.Error}{Environment.NewLine}"; } else { msgs[count] += $"{Tools2.DecimalToEngineer(result.BaseResistors.R1).PadRight(6)} {(result.Parallel ? "||" : " +")} {Tools2.DecimalToEngineer(result.BaseResistors.R2).PadRight(6)} = {Tools2.DecimalToEngineer(Math.Round(result.Resistor, 3)).PadRight(9)} {((result.Error >= 0) ? (" ") : (""))}{Math.Round(result.Error, 3)}{Environment.NewLine}"; } // Switch to next slot every 5k lines if (i % 5000 == 0) { // Update to preview Window count++; // Add next slot msgs.Add(string.Empty); // Report progress progress = ((i * 100) / max_i); b.ReportProgress(progress); } } // Text generated, appending label_status.Text = "Appending text..."; for (int i = 0; i < msgs.Count; i++) { msg += msgs[i]; if (i % 100 == 0) { progress = (i * 100) / msgs.Count; b.ReportProgress(progress); } } label_status.Text = "Loading window"; b.ReportProgress(100); }