Ejemplo n.º 1
0
        // 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);
        }
Ejemplo n.º 2
0
        private void ParseCsv(List <string> lines)
        {
            bool parseHeader = true;

            foreach (string line in lines)
            {
                // Header is first line
                if (parseHeader)
                {
                    using (StringReader rdr = new StringReader(line))
                        using (TextFieldParser csvParser = new TextFieldParser(rdr))
                        {
                            csvParser.CommentTokens = new string[] { "#" };
                            csvParser.SetDelimiters(new string[] { "," });
                            csvParser.HasFieldsEnclosedInQuotes = false;
                            var headerColumns = csvParser.ReadFields();
                            for (int idx = 0; idx < headerColumns.Length; idx++)
                            {
                                if (headerColumns[idx].CompareTo("Comment") == 0)
                                {
                                    valueIdx = idx;
                                }
                                else if (headerColumns[idx].CompareTo("Designator") == 0)
                                {
                                    designatorIdx = idx;
                                }
                                else if (headerColumns[idx].CompareTo("Footprint") == 0)
                                {
                                    footprintIdx = idx;
                                }
                                header.Add(idx, headerColumns[idx]);
                            }
                            if (valueIdx < 0 || designatorIdx < 0 || footprintIdx < 0)
                            {
                                throw new InvalidOperationException("Could not locate Comment, Designator or Footprint");
                            }
                        }
                    parseHeader = false;
                    continue;
                }
                if (line.StartsWith("#"))
                {
                    // just a comment, ignore
                    continue;
                }
                components.Add(BOMLine.parseCsv(line, valueIdx, designatorIdx, footprintIdx));
            }
        }