示例#1
0
        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");
        }
示例#2
0
文件: Program.cs 项目: Robyrob/kibom
        static void Main(string[] args)
        {
            Version v = Assembly.GetExecutingAssembly().GetName().Version;

            Console.WriteLine(string.Format(System.Globalization.CultureInfo.InvariantCulture, @"Kibom {0}.{1} (build {2}.{3})", v.Major, v.Minor, v.Build, v.Revision));

            string filename        = "";
            string output_filename = "";
            string path            = "";
            string outputs         = "";
            string template        = "";
            string footer          = "";
            string path_txt        = "";
            bool   no_fit_list     = false;

            if (!ParseArgs(args, out filename, out path, out outputs, out output_filename, out template, out footer, out path_txt, out no_fit_list))
            {
                return;
            }

            if (string.IsNullOrEmpty(path_txt))
            {
                path_txt = path;
            }
            if (!Footprint.LoadSubsFile(path_txt) ||
                !Component.LoadDefaultsFile(path_txt))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(path + filename);
            if (ParseKicadXML(doc, path, filename, outputs, output_filename, template, footer, no_fit_list))
            {
                Console.WriteLine("BOM generated.");
            }
        }
示例#3
0
文件: Program.cs 项目: Robyrob/kibom
        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);
        }