/// <summary> /// Given an XML circuit representation, create an IC. /// The local IC List will be used to deference any nested ICs. /// </summary> /// <param name="circuit"></param> /// <returns></returns> public UIGates.IC LoadCircuit(XElement circuit) { Gates.Circuit c = new Gates.Circuit(); Dictionary<int, Gates.AbstractGate> gid = new Dictionary<int, Gates.AbstractGate>(); Dictionary<Gates.AbstractGate, GateLocation> gpt = new Dictionary<Gates.AbstractGate, GateLocation>(); foreach (XElement gate in circuit.Element("Gates").Elements()) { Gates.AbstractGate abgate = CreateGate(gate); c.Add(abgate); gid.Add(int.Parse(gate.Attribute("ID").Value), abgate); double x = double.Parse(gate.Element("Point").Attribute("X").Value); double y = double.Parse(gate.Element("Point").Attribute("Y").Value); double angle = double.Parse(gate.Element("Point").Attribute("Angle").Value); gpt.Add(abgate, new GateLocation(x, y, angle)); } foreach (XElement wire in circuit.Element("Wires").Elements()) { c[CreateTerminal(gid, wire.Element("To"))] = CreateTerminal(gid, wire.Element("From")); } ICBuilder icb = new ICBuilder(c, (Gates.AbstractGate abgate) => { return gpt[abgate]; }); // for top level circuit, must not create terminals // otherwise input/output overridden if (circuit.Attribute("Name") != null) { string cname = circuit.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) cname = UpdateICNames[cname]; return icb.CreateIC(cname); } else return icb.CreateNonTerminaledIC(""); }