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);
            }
        }
 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);
     }
 }
 public static bool LoadFromFile(string fileName, out wire obj) {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an wire object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output wire 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 wire obj, out System.Exception exception) {
     exception = null;
     obj = default(wire);
     try {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string xml, out wire obj) {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an wire object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output wire 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 wire obj, out System.Exception exception) {
     exception = null;
     obj = default(wire);
     try {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
        private void CreateWireSegment(Port port, Eagle.segment segment_obj)
        {
            // create two short wire segments: 1. from src pin to, and 2. to dst pin
            // TODO: create vertical segments for vertical pins (or rotated symbols)
            var wire_obj = new Eagle.wire();
            var rot = port.Impl.Attributes.EDASymbolRotation;
            double x1 = port.CanvasX;
            double y1 = port.CanvasY;
            double x2 = x1;
            double y2 = y1;
            if (rot.Equals("R90") || rot.Equals("90"))
                y2 -= netLength; // 90 pointing down
            else if (rot.Equals("R270") || rot.Equals("270"))
                y2 += netLength; // 270 pointing up
            else if (rot.Equals("R180") || rot.Equals("180"))
                x2 += netLength; // 180 going right
            else
                x2 -= netLength; // 0 going left

            wire_obj.x1 = x1.ToString("F2");
            wire_obj.y1 = y1.ToString("F2");
            wire_obj.x2 = x2.ToString("F2");
            wire_obj.y2 = y2.ToString("F2");
            wire_obj.layer = netLayer;
            wire_obj.width = wireWidth;
            segment_obj.Items.Add(wire_obj);

            var label_obj = new Eagle.label();
            label_obj.x = wire_obj.x2;
            label_obj.y = wire_obj.y2;
            label_obj.size = labelSize;
            label_obj.layer = nameLayer;
            segment_obj.Items.Add(label_obj);
        }