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);
            }
        }
 public static bool LoadFromFile(string fileName, out via obj) {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 public static bool Deserialize(string xml, out via obj) {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an via object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output via object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out via obj, out System.Exception exception) {
     exception = null;
     obj = default(via);
     try {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
 /// <summary>
 /// Deserializes workflow markup into an via object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output via object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out via obj, out System.Exception exception) {
     exception = null;
     obj = default(via);
     try {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }