public CyPhy.EDAModel BuildCyPhyEDAModel(avm.schematic.eda.EDAModel edaModel, CyPhy.Component comp) { var rf = CyPhyClasses.RootFolder.GetRootFolder(CurrentProj); var builder = new AVM2CyPhyML.CyPhyMLComponentBuilder(rf); CyPhy.EDAModel cyPhyEDAModel = builder.process(edaModel, comp); #region layout // find the largest current Y value so our new elements are added below the existing design elements greatest_current_y = 0; foreach (var child in GetCurrentDesignElement().AllChildren) { foreach (MgaPart item in (child.Impl as MgaFCO).Parts) { int read_x, read_y; string read_str; item.GetGmeAttrs(out read_str, out read_x, out read_y); greatest_current_y = (read_y > greatest_current_y) ? read_y : greatest_current_y; } } // layout CAD model to the "south" of existing elements foreach (MgaPart item in (cyPhyEDAModel.Impl as MgaFCO).Parts) { item.SetGmeAttrs(null, MODEL_START_X, greatest_current_y + MODEL_START_Y); } #endregion ExtendDevicePorts(cyPhyEDAModel); return(cyPhyEDAModel); }
/// <summary> /// Given an EAGLE device, generate an avm.schematic.eda.EDAModel object. /// </summary> /// <param name="device"></param> /// <returns></returns> public static avm.schematic.eda.EDAModel ConvertEagleDeviceToAvmEdaModel(XmlNode device) { XmlDocument doc; Dictionary <string, XmlNode> packages_Dict; Dictionary <string, XmlNode> symbols_Dict; XmlNode deviceSet; XmlNode library; Dictionary <string, XmlNode> gates_Dict; String devicePackageName; GatherDataFromDocument(device, out doc, out packages_Dict, out symbols_Dict, out deviceSet, out library, out gates_Dict, out devicePackageName); // Create a new EDAModel object var edaModel = new avm.schematic.eda.EDAModel() { Device = (device.Attributes["name"] == null) ? "" : device.Attributes["name"].Value, Package = device.Attributes["package"].Value, DeviceSet = deviceSet.Attributes["name"].Value, Library = (library.Attributes["name"] == null) ? "" : library.Attributes["name"].Value }; // check for UserValue. // If it exists, create a "value" Parameter object inside the schematic model. if (deviceSet.Attributes["uservalue"] != null && deviceSet.Attributes["uservalue"].Value == "yes") { edaModel.Parameter.Add( new avm.schematic.eda.Parameter() { Locator = "value", Value = new avm.Value() { DataType = avm.DataTypeEnum.String } } ); } /* Let's paraphrase the Python script. * * foreach (var conn in device.xpath('connects/connect') * // "gate" attribute of <connect> object ("G$1") * var gate = conn.get('gate') * * // "pin" attribute of <connect> object ("P$1") * var pin = conn.get('pin') * * // "pad" attribute of <connect> object ("CATHODE") * var pad = conn.get('pad') * * // A dictionary with gate name as key, then pin & pad pair as the value * my_gates[gate] = [pin, pad] * * // Iterate only over the keys of the dict. * // That is, only names like "G$1". * // (of which there are two) * foreach (g in my_gates.keys) * // This will be <gate name="G$1" y="0" x="0" symbol="LED"/> * var gate = gate element from ("gates/gate") * * // This will be <symbol name="LED"> and children * var sym = look up "gate.symbol" in ('symbols/symbol'):name * * // This will be: * <pin visible="off" name="P$1" y="0" x="0" rot="R90" length="short" direction="pas"/> * <pin visible="off" name="P$2" y="7.62" x="0" rot="R270" length="short" direction="pas"/> * var pins = sym.xpath('pin') * * ... layout stuff ... * * for pin in pins: * create some pin objects */ // Discover what gates are used List <String> gatesUsed = new List <String>(); foreach (XmlNode conn in device.SelectNodes("*[local-name()='connects']/*[local-name()='connect']")) { gatesUsed.Add(conn.Attributes["gate"].Value); } // Iterate over the distinct gates used foreach (var connGateName in gatesUsed.Distinct()) { var gateDefinition = gates_Dict[connGateName]; var gateSymbolName = gateDefinition.Attributes["symbol"].Value; var gateSymbol = symbols_Dict[gateSymbolName]; foreach (XmlNode pin in gateSymbol.SelectNodes("*[local-name()='pin']")) { edaModel.Pin.Add( new avm.schematic.Pin() { EDAGate = connGateName, EDASymbolLocationX = pin.Attributes["x"].Value, EDASymbolLocationY = pin.Attributes["y"].Value, EDASymbolRotation = (pin.Attributes["rot"] == null) ? "0" : pin.Attributes["rot"].Value, Name = pin.Attributes["name"].Value } ); } } return(edaModel); }