コード例 #1
0
        static void CopyDesignRules(string designRuleFile, Eagle.designrules designRules)
        {
            try
            {
                using (StreamReader druIn = new StreamReader(designRuleFile))
                {

                    // initialize the design rules section
                    designRules.name = Path.GetFileNameWithoutExtension(designRuleFile);
                    designRules.description.Clear();
                    designRules.param.Clear();

                    var line = druIn.ReadLine();
                    var regex = new Regex("[a-zA-Z]*\\[(.*)\\]");
                    while (line != null)
                    {
                        string[] nameValues = line.Split('=');
                        if (nameValues.Count() < 2)
                        {
                            // error 
                            continue;
                        }
                        var name = nameValues[0].Trim();
                        var value = nameValues[1].Trim();

                        if (name.Contains("description"))
                        {
                            var desc = new Eagle.description();
                            desc.Text.Add(value);
                            Console.WriteLine(name);
                            desc.language = regex.Replace(name, "$1");
                            Console.WriteLine(desc.language);
                            designRules.description.Add(desc);
                        }
                        else
                        {
                            var param = new Eagle.param();
                            param.name = name;
                            param.value = value;
                            designRules.param.Add(param);
                        }

                        // read the next line
                        line = druIn.ReadLine();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in reading design rules file {0}", e.Message);
            }

        }
コード例 #2
0
        static void AddSignals(Eagle.nets nets, Eagle.parts parts, 
            Dictionary<string, Signal> signalMap, Dictionary<string, Package> packageMap,
            Eagle.libraries libs, Eagle.signals signals)
        {
            foreach (var net in nets.net)
            {
                var signal = new Eagle.signal();
                signal.name = net.name;
                var pinrefs = net.segment.SelectMany(s => s.Items).
                    Where(i => i is Eagle.pinref).
                    Select(i => i as Eagle.pinref );

                foreach (var pinref in pinrefs )
                {
                    var part = parts.part.Where(p => p.name.Equals(pinref.part)).FirstOrDefault();
                    var device =
                        libs.library.Where(l => l.name.Equals(part.library)).                                   // find library
                        SelectMany(l => l.devicesets.deviceset).Where(ds => ds.name.Equals(part.deviceset)).    // find deviceset
                        SelectMany(ds => ds.devices.device).Where(d => d.name.Equals(part.device)).             // find device
                        FirstOrDefault();

                    if (device == null)
                    {
                        // same error as reported above 
                        continue;
                    }

                    var connect = device.connects.connect.
                        Where(c => c.pin.Equals(pinref.pin) && c.gate.Equals(pinref.gate)).
                        FirstOrDefault();

                    var pads = connect.pad.Split(' ');
                    foreach (var pad in pads)
                    {
                        var contactref = new Eagle.contactref();
                        contactref.element = pinref.part;
                        contactref.pad = pad;
                        if (connect.route != CyPhy2Schematic.Schematic.Eagle.connectRoute.all)
                            contactref.route = (CyPhy2Schematic.Schematic.Eagle.contactrefRoute)connect.route;
                        signal.Items.Add(contactref);
                    }
                }

                if (signalMap.ContainsKey(net.name))        // add pre-route if we already have it 
                {
                    var jsig = signalMap[net.name];
                    Package refPkg = null;
                    if (jsig.RelComponentID != null && packageMap.ContainsKey(jsig.RelComponentID))
                        refPkg = packageMap[jsig.RelComponentID];

                    if (jsig.wires != null)
                    {
                        foreach (var jwire in jsig.wires)
                        {
                            double rx1 = jwire.x1;
                            double rx2 = jwire.x2;
                            double ry1 = jwire.y1;
                            double ry2 = jwire.y2;

                            var wire = new Eagle.wire();
                            if (refPkg != null)
                            {
                                RotateAndTranslate(refPkg, jwire.x1, jwire.y1, out rx1, out ry1);
                                RotateAndTranslate(refPkg, jwire.x2, jwire.y2, out rx2, out ry2);
                            }
                            wire.x1 = rx1.ToString();
                            wire.x2 = rx2.ToString();
                            wire.y1 = ry1.ToString();
                            wire.y2 = ry2.ToString();
                            wire.width = jwire.width.ToString();
                            wire.layer = jwire.layer.ToString();
                            signal.Items.Add(wire);
                        }
                    }
                    if (jsig.vias != null)
                    {
                        foreach (var jvia in jsig.vias)
                        {
                            var via = new Eagle.via();
                            double rx = jvia.x;
                            double ry = jvia.y;
                            if (refPkg != null)
                            {
                                RotateAndTranslate(refPkg, jvia.x, jvia.y, out rx, out ry);
                            }
                            via.x = rx.ToString();
                            via.y = ry.ToString();
                            via.extent = jvia.layerBegin.ToString() + '-' + jvia.layerEnd.ToString();
                            via.drill = jvia.drill.ToString();
                            signal.Items.Add(via);
                        }
                    }
                }

                signals.signal.Add(signal);
            }
        }
コード例 #3
0
 static void AddBoundary(Layout boardLayout, Eagle.plain plain)
 {
     {
         var w = new Eagle.wire();
         w.x1 = Convert.ToString(0);
         w.x2 = Convert.ToString(boardLayout.boardWidth);
         w.y1 = Convert.ToString(0);
         w.y2 = Convert.ToString(0);
         w.width = Convert.ToString(0);
         w.layer = BOARD_LAYER;
         plain.Items.Add(w);
     }
     {
         var w = new Eagle.wire();
         w.x1 = Convert.ToString(0);
         w.x2 = Convert.ToString(boardLayout.boardWidth);
         w.y1 = Convert.ToString(boardLayout.boardHeight);
         w.y2 = Convert.ToString(boardLayout.boardHeight);
         w.width = Convert.ToString(0);
         w.layer = BOARD_LAYER;
         plain.Items.Add(w);
     }
     {
         var w = new Eagle.wire();
         w.x1 = Convert.ToString(0);
         w.x2 = Convert.ToString(0);
         w.y1 = Convert.ToString(0);
         w.y2 = Convert.ToString(boardLayout.boardHeight);
         w.width = Convert.ToString(0);
         w.layer = BOARD_LAYER;
         plain.Items.Add(w);
     }
     {
         var w = new Eagle.wire();
         w.x1 = Convert.ToString(boardLayout.boardWidth);
         w.x2 = Convert.ToString(boardLayout.boardWidth);
         w.y1 = Convert.ToString(0);
         w.y2 = Convert.ToString(boardLayout.boardHeight);
         w.width = Convert.ToString(0);
         w.layer = BOARD_LAYER;
         plain.Items.Add(w);
     }
 }
コード例 #4
0
        static void AddElements(Eagle.parts parts, Dictionary<string, Package> packageMap, 
            Eagle.libraries libs, Eagle.elements elements)
        {
            foreach (var part in parts.part)
            {
                Eagle.element element = new Eagle.element();
                element.name = part.name;
                element.library = part.library;
                var devset =
                    libs.library.Where(l => l.name.Equals(part.library)).                     // find library
                    SelectMany(l => l.devicesets.deviceset).Where(ds => ds.name.Equals(part.deviceset)).    // find deviceset
                    FirstOrDefault();
                var device = devset != null ?
                    devset.devices.device.Where(d => d.name.Equals(part.device)).             // find device
                    FirstOrDefault() : null;
                var tech = device != null ?
                    device.technologies.technology.Select(t => t.name).FirstOrDefault() : null;

                if (devset == null || device == null)
                {
                    Console.WriteLine("ERROR: part {0} does not have device or deviceset information in schema file", part.name); 
                    continue;
                }
                element.package = device.package;

                if (devset.uservalue.ToString().Equals("no"))
                {
                    var value = devset.name + device.name;
                    element.value = value.Replace("*", tech);
                }

                if (packageMap.ContainsKey(part.name))
                {
                    var pkg = packageMap[part.name];
                    // multiple with 10, floor and divide by 10 to align place on a 0.1 mm grid 
                    double pkgx = (pkg.x != null) ? (double)pkg.x : 0.0;
                    double pkgy = (pkg.y != null) ? (double)pkg.y : 0.0;
                    int prot = (pkg.rotation != null) ? (int)pkg.rotation : 0;
                    double x = 0.1 * Math.Floor(10.0 * (pkgx + 
                        ((prot % 2)  == 1 ? pkg.height/2.0 : pkg.width/2.0)));
                    double y = 0.1 * Math.Floor(10.0 * (pkgy + 
                        ((prot % 2)  == 1 ? pkg.width/2.0 : pkg.height/2.0)));
                    double xorg = pkg.originX != null ? (double)pkg.originX : 0.0;
                    double yorg = pkg.originY != null ? (double)pkg.originY : 0.0;
                    switch (prot)
                    {
                        case 0: x -= xorg; y -= yorg; break;
                        case 2: x += xorg; y += yorg; break;
                        case 1: x -= yorg; y -= xorg; break;
                        case 3: x += yorg; y += xorg; break;
                    }

                    double rx = x;
                    double ry = y;

                    if (pkg.RelComponentID != null &&
                        packageMap.ContainsKey(pkg.RelComponentID))
                    // part has a relative placement
                    {
                        var refPkg = packageMap[pkg.RelComponentID];
                        // rotate the contained parts according to refPkg rotation
                        if (refPkg.rotation != null) prot += (int)refPkg.rotation;
                        if (prot > 3) prot = prot % 4;

                        RotateAndTranslate(refPkg, x, y, out rx, out ry);
                    }
                    element.x = rx.ToString();
                    element.y = ry.ToString();
                    string layer = ((pkg.layer == 1) ? "M" : "");
                    string rot = (90 * prot).ToString();
                    element.rot = layer + "R" + rot;
                }
                else
                {
                    Console.WriteLine("WARNING: part {0} not found in layout file", part.name);
                }

                foreach (var sattrib in device.technologies.technology.SelectMany(t => t.attribute))
                {
                    Eagle.attribute dattrib = new Eagle.attribute();
                    dattrib.name = sattrib.name;
                    dattrib.value = sattrib.value;
                    dattrib.layer = ATTRIB_LAYER;
                    dattrib.display = Eagle.attributeDisplay.off;

                    element.attribute.Add(dattrib);
                }


                elements.element.Add(element);
            }
        }