public Component(string reference, string value, string footprint) { this.reference = reference; this.value = value; this.designator = this.reference.Substring(0, this.reference.IndexOfAny("0123456789".ToCharArray())); this.numeric_value = Component.ValueToNumeric(this.value); // normalized footprint if (footprint == null) { Console.Error.WriteLine("No footprint defined on node '" + this.reference + "." + this.value); this.footprint = "no part"; this.footprint_normalized = "no part"; } else { this.footprint_normalized = Footprint.substitute(footprint, true, true); if (footprint.Contains(':')) // contrains library name { this.footprint = footprint.Substring(footprint.IndexOf(':') + 1); } else { this.footprint = footprint; } } this.no_part = (this.footprint_normalized == "no part"); }
static List <Component> ParseComponents(XmlDocument doc) { List <Component> comp_list = new List <Component>(); XmlNode components_node = doc.DocumentElement.SelectSingleNode("components"); XmlNodeList comp_nodes = components_node.SelectNodes("comp"); foreach (XmlNode node in comp_nodes) { var comp = new Component(); comp.reference = node.Attributes["ref"].Value; comp.designator = comp.reference.Substring(0, comp.reference.IndexOfAny("0123456789".ToCharArray())); comp.value = node.SelectSingleNode("value").InnerText; comp.numeric_value = Component.ValueToNumeric(comp.value); comp.footprint = node.SelectSingleNode("footprint").InnerText; // normalized footprint comp.footprint_normalized = Footprint.substitute(comp.footprint, true, true); if (comp.footprint_normalized == "no part") { comp.no_part = true; } if (comp.footprint.Contains(':')) // contrains library name { comp.footprint = comp.footprint.Substring(comp.footprint.IndexOf(':') + 1); } // custom BOM fields XmlNode fields = node.SelectSingleNode("fields"); if (fields != null) { XmlNodeList fields_nodes = fields.SelectNodes("field"); foreach (XmlNode field in fields_nodes) { switch (field.Attributes["name"].Value.ToLower()) { case "bom_footprint": //case "bom_partno": comp.footprint_normalized = field.InnerText; break; case "precision": comp.precision = field.InnerText; break; case "bom_note": comp.note = field.InnerText; break; case "bom_partno": comp.part_no = field.InnerText; break; case "code": comp.code = field.InnerText; break; case "bom_no_part": if ((field.InnerText.ToLower() == "true") || (field.InnerText.ToLower() == "no part")) { comp.no_part = true; } break; case "bom_no_fit": if ((field.InnerText.ToLower() == "true") || (field.InnerText.ToLower() == "no fit")) { comp.no_fit = true; } break; } } } if (!comp.no_part) { comp_list.Add(comp); } //Console.WriteLine(comp.reference + "\t" + comp.value + "\t" + comp.footprint_normalized); } return(comp_list); }