//Modified method from CircuitXML.CreateGate Method private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) numInputs = int.Parse(gate.Attribute("NumInputs").Value); switch (gate.Attribute("Type").Value) { case "And": return new Gates.BasicGates.And(numInputs); case "Not": return new Gates.BasicGates.Not(); case "Or": return new Gates.BasicGates.Or(numInputs); case "Nand": return new Gates.BasicGates.Nand(numInputs); case "Nor": return new Gates.BasicGates.Nor(numInputs); case "Xor": return new Gates.BasicGates.Xor(); case "Xnor": return new Gates.BasicGates.Xnor(); case "Buffer": return new Gates.BasicGates.Buffer(); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return ui; case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return uo; case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return ni; case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); return no; case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return clk; case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return cmt; } throw new ArgumentException("unknown gate"); }
private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) numInputs = int.Parse(gate.Attribute("NumInputs").Value); switch (gate.Attribute("Type").Value) { case "And": return new Gates.BasicGates.And(numInputs); case "Not": return new Gates.BasicGates.Not(); case "Or": return new Gates.BasicGates.Or(numInputs); case "Nand": return new Gates.BasicGates.Nand(numInputs); case "Nor": return new Gates.BasicGates.Nor(numInputs); case "Xor": return new Gates.BasicGates.Xor(); case "Xnor": return new Gates.BasicGates.Xnor(); case "Buffer": return new Gates.BasicGates.Buffer(); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return ui; case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return uo; case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return ni; case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation)int.Parse(gate.Attribute("SelRep").Value); return no; case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return clk; case "IC": // check if this ic has been renamed string cname = gate.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) cname = UpdateICNames[cname]; return icl.GetIC(cname).AbGate.Clone(); case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return cmt; } throw new ArgumentException("unknown gate"); }
private Gates.AbstractGate CreateGate(XElement gate) { int numInputs = 2; // default for variable input gates if (gate.Attribute("NumInputs") != null) { numInputs = int.Parse(gate.Attribute("NumInputs").Value); } switch (gate.Attribute("Type").Value) { case "And": return(new Gates.BasicGates.And(numInputs)); case "Not": return(new Gates.BasicGates.Not()); case "Or": return(new Gates.BasicGates.Or(numInputs)); case "Nand": return(new Gates.BasicGates.Nand(numInputs)); case "Nor": return(new Gates.BasicGates.Nor(numInputs)); case "Xor": return(new Gates.BasicGates.Xor()); case "Xnor": return(new Gates.BasicGates.Xnor()); case "Buffer": return(new Gates.BasicGates.Buffer()); case "UserInput": Gates.IOGates.UserInput ui = new Gates.IOGates.UserInput(); ui.SetName(gate.Attribute("Name").Value); return(ui); case "UserOutput": Gates.IOGates.UserOutput uo = new Gates.IOGates.UserOutput(); uo.SetName(gate.Attribute("Name").Value); return(uo); case "NumericInput": Gates.IOGates.NumericInput ni = new Gates.IOGates.NumericInput(int.Parse(gate.Attribute("Bits").Value)); ni.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value); ni.Value = gate.Attribute("Value").Value; return(ni); case "NumericOutput": Gates.IOGates.NumericOutput no = new Gates.IOGates.NumericOutput(int.Parse(gate.Attribute("Bits").Value)); no.SelectedRepresentation = (Gates.IOGates.AbstractNumeric.Representation) int.Parse(gate.Attribute("SelRep").Value); return(no); case "Clock": Gates.IOGates.Clock clk = new Gates.IOGates.Clock(int.Parse(gate.Attribute("Milliseconds").Value)); return(clk); case "IC": // check if this ic has been renamed string cname = gate.Attribute("Name").Value; // check first if we need to rename if (UpdateICNames.ContainsKey(cname)) { cname = UpdateICNames[cname]; } return(icl.GetIC(cname).AbGate.Clone()); case "Comment": Gates.IOGates.Comment cmt = new Gates.IOGates.Comment(); cmt.Value = gate.Element("Comment").Value; return(cmt); } throw new ArgumentException("unknown gate"); }