/// <summary> /// Load config from "Config.cfg". /// Mainly calibration files. /// </summary> public bool ConfigurationFile_Load() { Regex regex = new Regex(mParameters.Delimiter); string[] lines = File.ReadAllLines("Config.cfg"); Calibrations.Clear(); List <string> calibComboBox = new List <string>(); foreach (string line in lines) { string[] items = regex.Split(line); switch (items[0]) { case "calib_points": { try { var output = LoadData(items[1] + ".clb"); Calibrations.Add(new Calibration_Points(output.Item1, output.Item2)); } catch (FileNotFoundException e) { Front.My_msg(string.Format( "Config.cfg: FileError: '{0}'.", e.Message)); break; } calibComboBox.Add(items[1]); break; } case "calib_polynom": { try { var output = LoadData(items[1] + ".clb"); Calibrations.Add(new Calibration_Polynom(output.Item2)); } catch (FileNotFoundException e) { Front.My_msg(string.Format( "Config.cfg: FileError: '{0}'.", e.Message)); break; } calibComboBox.Add(items[1]); break; } case "const_skip": { if (int.TryParse(items[1], out int output)) { MSpectraProcessor.MParameters.PointsToSkip = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "const_eps": { if (double.TryParse(items[1], out double output)) { MSpectraProcessor.MParameters.EpsilonLimit = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "const_smooth1": { if (int.TryParse(items[1], out int output)) { MSpectraProcessor.MParameters.SmoothingIntensities = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "const_smooth2": { if (int.TryParse(items[1], out int output)) { MSpectraProcessor.MParameters.SmoothingDerivatives = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "const_1DHalfW": { if (int.TryParse(items[1], out int output)) { MSpectraProcessor.MParameters.SearchHalfWidth = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "const_slider": { if (double.TryParse(items[1], out double output)) { MSpectraProcessor.MParameters.SliderLimit = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "DAC": { switch (items[1]) { case "lab": DAC = new DigitalToAnalogConverter.Lab(); break; case "offline": DAC = new DigitalToAnalogConverter.Offline(); break; default: Front.My_msg(string.Format( "Config.cfg: DAC keyError: '{0}'. Setting offline.", items[1])); DAC = new DigitalToAnalogConverter.Offline(); break; } break; } case "DAC_maxStep": { if (double.TryParse(items[1], out double output)) { PID.VDeltaAbsMax = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "PID_P": { Front.Pid_P = items[1]; break; } case "PID_I": { Front.Pid_I = items[1]; break; } case "PID_D": { Front.Pid_D = items[1]; break; } case "PID_period": { if (double.TryParse(items[1], out double output)) { PID.Period = output; } else { Front.My_msg(string.Format( "Config.cfg: Parse error: '{0}'.", output)); } break; } case "inchwormMethod_left": switch (items[1]) { case "old": MSpectraProcessor.MParameters.InchwormMethodLeft = SpectraProcessor.InchwormMethod.Old; break; case "vit": MSpectraProcessor.MParameters.InchwormMethodLeft = SpectraProcessor.InchwormMethod.Vit; break; case "constant": MSpectraProcessor.MParameters.InchwormMethodLeft = SpectraProcessor.InchwormMethod.Constant; break; default: MSpectraProcessor.MParameters.InchwormMethodLeft = SpectraProcessor.InchwormMethod.Constant; Front.My_msg("Wrong inchwormMethod_left, default choosen!"); break; } break; case "inchwormMethod_right": switch (items[1]) { case "old": MSpectraProcessor.MParameters.InchwormMethodRight = SpectraProcessor.InchwormMethod.Old; break; case "vit": MSpectraProcessor.MParameters.InchwormMethodRight = SpectraProcessor.InchwormMethod.Vit; break; case "constant": MSpectraProcessor.MParameters.InchwormMethodRight = SpectraProcessor.InchwormMethod.Constant; break; default: MSpectraProcessor.MParameters.InchwormMethodRight = SpectraProcessor.InchwormMethod.Constant; Front.My_msg("Wrong inchwormMethod_right, default choosen!"); break; } break; default: Front.My_msg(string.Format("Config.cfg: KeyError: '{0}'.", items[0])); break; } } // If DAC not in config file. if (DAC == null) { DAC = new DigitalToAnalogConverter.Offline(); } if (Calibrations.Count == 0) { Front.My_msg("No calibration found!"); Front.BtnCalibrationEnabled = false; return(true); } Front.BtnCalibrationEnabled = true; // ComboBox. Front.CBoxCalibrationDataSource = calibComboBox; SelectCalibration(0); return(true); }