private static List <ICComponentDescription> GenerateDescription(List <DrawableComponent> comps) { List <ICComponentDescription> llicc = new List <ICComponentDescription>(); for (int i = 0; i < comps.Count; i++) { //----------------------------------------- string type = ""; if (comps[i] is DrawableLogicGate) { type = ((DrawableLogicGate)comps[i]).GetLogicName(); } else if (comps[i] is DrawableCircuitLamp) { type = "Lamp"; } else if (comps[i] is DrawableCircuitSwitch) { type = "Switch"; } else if (comps[i] is DrawableIC) { type = ((DrawableIC)comps[i]).Description.Name; } List <ICConnectionDescription> to = new List <ICConnectionDescription>(); foreach (CircuitOutput co in comps[i].Outputs) { foreach (DrawableWire cw in co.Signals) { int indexOf = comps.IndexOf(cw.To); if (indexOf == -1) { return(null); } ICConnectionDescription iccd = new ICConnectionDescription(indexOf, cw.FromIndex, cw.ToIndex); to.Add(iccd); } } ICComponentDescription icccc = new ICComponentDescription(type, to); if (comps[i] is DrawableCircuitLamp) { if (((DrawableCircuitLamp)comps[i]).ID == "") { return(null); } icccc.SetID(((DrawableCircuitLamp)comps[i]).ID); } if (comps[i] is DrawableCircuitSwitch) { if (((DrawableCircuitSwitch)comps[i]).ID == "") { return(null); } icccc.SetID(((DrawableCircuitSwitch)comps[i]).ID); } if (comps[i] is DrawableIC) { DrawableIC dic = (DrawableIC)comps[i]; icccc.SetDescription(dic.Description); } llicc.Add(icccc); } return(llicc); }
public List <CircuitComponent> GenerateComponents() { CircuitComponent[] components = new CircuitComponent[Descriptions.Count]; for (int i = 0; i < Descriptions.Count; i++) { ICComponentDescription iccd = Descriptions[i]; CircuitComponent dc = null; switch (iccd.Type) { case "ANDGateLogic": dc = new MinimalLogicGate(new ANDGateLogic()); break; case "NANDGateLogic": dc = new MinimalLogicGate(new NANDGateLogic()); break; case "ORGateLogic": dc = new MinimalLogicGate(new ORGateLogic()); break; case "NORGateLogic": dc = new MinimalLogicGate(new NORGateLogic()); break; case "XORGateLogic": dc = new MinimalLogicGate(new XORGateLogic()); break; case "XNORGateLogic": dc = new MinimalLogicGate(new XNORGateLogic()); break; case "NOTGateLogic": dc = new MinimalLogicGate(new NOTGateLogic()); break; case "Switch": //CircuitSwitch cs = new CircuitSwitch(Vector2.Zero); //cs.SetID(iccd.ID); dc = new MinimalSwitch() { ID = iccd.ID }; break; case "Lamp": //CircuitLamp cl = new CircuitLamp(Vector2.Zero); //cl.SetID(iccd.ID); dc = new MinimalLamp() { ID = iccd.ID }; break; default: // It is not a built in thing - look for it in the IC files folder ICDescription icd = iccd.Description; dc = new DrawableIC(Vector2.Zero, icd.Name, icd, false); break; } components[i] = dc; } for (int i = 0; i < Descriptions.Count; i++) { ICComponentDescription iccd = Descriptions[i]; foreach (ICConnectionDescription connection in iccd.To) { CircuitWire cw = new CircuitWire(); components[i].AddOutputWire(connection.OutIndex, cw); components[connection.To].SetInputWire(connection.InIndex, cw); } } return(components.ToList()); }