public static ComponentLocation parseCsv(string csvLine) { ComponentLocation result = new ComponentLocation(); using (StringReader rdr = new StringReader(csvLine)) using (TextFieldParser csvParser = new TextFieldParser(rdr)) { csvParser.CommentTokens = new string[] { "#" }; csvParser.SetDelimiters(new string[] { "," }); csvParser.HasFieldsEnclosedInQuotes = true; string[] components = csvParser.ReadFields(); if (components.Length != 7) { throw new InvalidOperationException("Expected 7 values"); } result.reference = ComponentReference.parse(components[0]); result.value = components[1]; result.package = components[2]; result.x = double.Parse(components[3], CultureInfo.InvariantCulture); result.y = double.Parse(components[4], CultureInfo.InvariantCulture); result.rotation = double.Parse(components[5], CultureInfo.InvariantCulture); result.layer = components[6]; return(result); } }
// Update component references so there is no collision with the designators from // another file. List <BOMLine> UpdateReferences(Dictionary <string, int> designators) { List <BOMLine> result = new List <BOMLine>(components.Count); foreach (BOMLine component in components) { BOMLine other = new BOMLine(); other.designators = new List <ComponentReference>(); other.value = component.value; other.footprint = component.footprint; other.extraAttributes = component.extraAttributes; foreach (ComponentReference reference in component.designators) { ComponentReference newReference = new ComponentReference(); if (designators.ContainsKey(reference.name)) { newReference.name = reference.name; newReference.sequence = reference.sequence + designators[reference.name] + 1; } else { newReference.name = reference.name; newReference.sequence = reference.sequence; } other.designators.Add(newReference); } result.Add(other); } return(result); }
private static List <ComponentReference> parseDesignators(string designators) { string[] elements = designators.Split(','); List <ComponentReference> result = new List <ComponentReference>(); foreach (string component in elements) { result.Add(ComponentReference.parse(component)); } return(result); }
public static ComponentReference parse(string str) { ComponentReference result = new ComponentReference(); int seqLoc = str.IndexOfAny(digits); if (seqLoc < 0) { result.sequence = -1; result.name = str; } else { result.name = str.Substring(0, seqLoc); result.sequence = int.Parse(str.Substring(seqLoc), CultureInfo.InvariantCulture); } return(result); }
public static ComponentLocation parseKicad(string kicadLine) { ComponentLocation result = new ComponentLocation(); string[] components = kicadLine.Split(KicadSeparator, StringSplitOptions.RemoveEmptyEntries); if (components.Length != 7) { throw new InvalidOperationException("Expected 7 values"); } result.reference = ComponentReference.parse(components[0]); result.value = components[1]; result.package = components[2]; result.x = double.Parse(components[3], CultureInfo.InvariantCulture); result.y = double.Parse(components[4], CultureInfo.InvariantCulture); result.rotation = double.Parse(components[5], CultureInfo.InvariantCulture); result.layer = components[6]; return(result); }