Exemplo n.º 1
0
        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);
                }
        }
Exemplo n.º 2
0
        // Update component references so there is no collision with the designators from
        // another file.
        List <ComponentLocation> UpdateReferences(Dictionary <string, int> designators)
        {
            List <ComponentLocation> result = new List <ComponentLocation>(components.Count);

            foreach (ComponentLocation component in components)
            {
                ComponentLocation other = new ComponentLocation();
                other.reference = new ComponentReference();
                other.value     = component.value;
                other.package   = component.package;
                other.x         = component.x;
                other.y         = component.y;
                other.rotation  = component.rotation;
                other.layer     = component.layer;
                if (designators.ContainsKey(component.reference.name))
                {
                    other.reference.name     = component.reference.name;
                    other.reference.sequence = component.reference.sequence + designators[component.reference.name] + 1;
                }
                else
                {
                    other.reference.name     = component.reference.name;
                    other.reference.sequence = component.reference.sequence;
                }
                result.Add(other);
            }
            return(result);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        private void ParseKicad(List <string> lines)
        {
            bool parseHeader = true;

            foreach (string line in lines)
            {
                if (parseHeader && line.StartsWith("#"))
                {
                    header.Add(line);
                    continue;
                }
                parseHeader = false;
                if (line.StartsWith("#"))
                {
                    // just a comment, ignore
                    continue;
                }
                components.Add(ComponentLocation.parseKicad(line));
            }
        }
Exemplo n.º 5
0
        private void ParseCsv(List <string> lines)
        {
            bool parseHeader = true;

            foreach (string line in lines)
            {
                // Header is first line
                if (parseHeader)
                {
                    header.Add(line);
                    parseHeader = false;
                    continue;
                }
                if (line.StartsWith("#"))
                {
                    // just a comment, ignore
                    continue;
                }
                components.Add(ComponentLocation.parseCsv(line));
            }
        }
Exemplo n.º 6
0
        public ComponentLocation Transform(double dx, double dy, double dxP, double dyP, double angleDeg)
        {
            double angle = angleDeg * (Math.PI * 2.0) / 360.0;
            double cosA  = Math.Cos(angle);
            double sinA  = Math.Sin(angle);

            ComponentLocation result = new ComponentLocation();

            result.reference = reference;
            result.package   = package;
            result.value     = value;
            result.layer     = layer;
            double targetX = x + dxP;
            double tragetY = y + dyP;

            if (angle != 0)
            {
                double nX = targetX * cosA - tragetY * sinA;
                double nY = targetX * sinA + tragetY * cosA;
                targetX = nX;
                tragetY = nY;
            }
            result.x        = targetX + dx;
            result.y        = tragetY + dy;
            result.rotation = rotation + angleDeg;
            while (result.rotation < 0)
            {
                result.rotation += 360;
            }
            while (result.rotation >= 360)
            {
                result.rotation -= 360;
            }

            return(result);
        }