예제 #1
0
        private Gates.IC CreateAndChain(int len)
        {
            Gates.Circuit andc = new Gates.Circuit();
            andc.Start();



            Gates.IOGates.UserInput in1 = new Gates.IOGates.UserInput();
            andc.Add(in1);
            Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput();
            andc.Add(out1);

            if (len > 1)
            {
                Gates.IC cand1 = CreateAndChain(len / 2);
                Gates.IC cand2 = CreateAndChain(len / 2);
                andc.Add(cand1);
                andc.Add(cand2);
                andc[new Gates.Terminal(0, cand1)] = new Gates.Terminal(0, in1);
                andc[new Gates.Terminal(0, cand2)] = new Gates.Terminal(0, cand1);
                andc[new Gates.Terminal(0, out1)]  = new Gates.Terminal(0, cand2);
            }
            else
            {
                Gates.BasicGates.And mand = new Gates.BasicGates.And();
                andc.Add(mand);
                andc[new Gates.Terminal(0, mand)] = new Gates.Terminal(0, in1);
                andc[new Gates.Terminal(1, mand)] = new Gates.Terminal(0, in1);
                andc[new Gates.Terminal(0, out1)] = new Gates.Terminal(0, mand);
            }

            return(new Gates.IC(andc, new Gates.IOGates.UserInput[] { in1 },
                                new Gates.IOGates.UserOutput[] { out1 }, "AndChain"));
        }
예제 #2
0
        public void ThruCircuit2()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.BasicGates.Not mnot1 = new Gates.BasicGates.Not();
            Gates.BasicGates.Not mnot2 = new Gates.BasicGates.Not();
            Gates.BasicGates.Not mnot3 = new Gates.BasicGates.Not();

            c.Add(mnot1);
            c.Add(mnot2);
            c.Add(mnot3);

            mnot1[0] = true;

            c[new Gates.Terminal(0, mnot2)] = new Gates.Terminal(0, mnot1);
            c[new Gates.Terminal(0, mnot3)] = new Gates.Terminal(0, mnot2);



            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, mnot3.Output[0]);

            mnot1[0] = false;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(true, mnot3.Output[0]);

            c.Disconnect(new Gates.Terminal(0, mnot2));
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, mnot3.Output[0]);
        }
예제 #3
0
        Gates.IC CreateSRLatch()
        {
            Gates.Circuit sr = new Gates.Circuit();
            sr.Start();
            Gates.IC nor1 = CreateNor();
            Gates.IC nor2 = CreateNor();

            Gates.IOGates.UserInput  in1  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  in2  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput();
            Gates.IOGates.UserOutput out2 = new Gates.IOGates.UserOutput();

            sr.Add(nor1);
            sr.Add(nor2);

            sr.Add(in1);
            sr.Add(in2);
            sr.Add(out1);
            sr.Add(out2);


            sr[new Gates.Terminal(0, nor1)] = new Gates.Terminal(0, in1);
            sr[new Gates.Terminal(1, nor2)] = new Gates.Terminal(0, in2);

            sr[new Gates.Terminal(1, nor1)] = new Gates.Terminal(0, nor2);
            sr[new Gates.Terminal(0, nor2)] = new Gates.Terminal(0, nor1);

            sr[new Gates.Terminal(0, out1)] = new Gates.Terminal(0, nor1);
            sr[new Gates.Terminal(0, out2)] = new Gates.Terminal(0, nor2);

            return(new Gates.IC(sr, new Gates.IOGates.UserInput[] { in1, in2 },
                                new Gates.IOGates.UserOutput[] { out1, out2 }, "SRLatch"));
        }
예제 #4
0
        public void NorInCiruit()
        {
            Gates.IC      nor = CreateNor();
            Gates.Circuit c   = new Gates.Circuit();
            c.Start();
            c.Add(nor);


            // primarily just tests that c's wait
            // also makes the nor wait

            nor[0] = false;
            nor[1] = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, nor.Output[0]);

            nor[0] = true;
            nor[1] = false;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, nor.Output[0]);

            nor[0] = false;
            nor[1] = false;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(true, nor.Output[0]);

            nor[0] = true;
            nor[1] = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, nor.Output[0]);
        }
예제 #5
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        Gates.IC CreateNor()
        {
            Gates.Circuit nor = new Gates.Circuit();
            nor.Start();

            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot1 = new Gates.BasicGates.Not();
            Gates.BasicGates.Not mnot2 = new Gates.BasicGates.Not();

            Gates.IOGates.UserInput  in1  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  in2  = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput out1 = new Gates.IOGates.UserOutput();

            nor.Add(mand);
            nor.Add(mnot1);
            nor.Add(mnot2);
            nor.Add(in1);
            nor.Add(in2);
            nor.Add(out1);

            nor[new Gates.Terminal(0, mnot1)] = new Gates.Terminal(0, in1);
            nor[new Gates.Terminal(0, mnot2)] = new Gates.Terminal(0, in2);
            nor[new Gates.Terminal(0, mand)]  = new Gates.Terminal(0, mnot1);
            nor[new Gates.Terminal(1, mand)]  = new Gates.Terminal(0, mnot2);
            nor[new Gates.Terminal(0, out1)]  = new Gates.Terminal(0, mand);

            return(new Gates.IC(nor, new Gates.IOGates.UserInput[] { in1, in2 },
                                new Gates.IOGates.UserOutput[] { out1 }, "Nor"));
        }
예제 #6
0
        public void ThruCircuit1()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.And mand2 = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot  = new Gates.BasicGates.Not();

            c.Add(mand);
            c.Add(mand2);
            c.Add(mnot);
            mand2[0] = true;

            c[new Gates.Terminal(1, mand2)] = new Gates.Terminal(0, mand);
            c[new Gates.Terminal(0, mnot)]  = new Gates.Terminal(0, mand2);


            Assert.AreEqual(true, mnot.Output[0]);

            mand[1] = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(true, mnot.Output[0]);

            mand[0] = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, mnot.Output[0]);
        }
예제 #7
0
        public void OscillationCircuit2()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.BasicGates.Not mnot1 = new Gates.BasicGates.Not();
            Gates.BasicGates.Not mnot2 = new Gates.BasicGates.Not();
            Gates.BasicGates.Not mnot3 = new Gates.BasicGates.Not();

            c.Add(mnot1);
            c.Add(mnot2);
            c.Add(mnot3);

            mnot1[0] = true;

            c[new Gates.Terminal(0, mnot2)] = new Gates.Terminal(0, mnot1);
            c[new Gates.Terminal(0, mnot3)] = new Gates.Terminal(0, mnot2);
            c[new Gates.Terminal(0, mnot1)] = new Gates.Terminal(0, mnot3);


            int      cnt    = 0;
            bool     oldval = true;
            DateTime start  = DateTime.Now;

            while (DateTime.Now - start < new TimeSpan(0, 0, 5))
            {
                if (mnot1.Output[0] != oldval)
                {
                    oldval = mnot1.Output[0];
                    cnt++;
                }
            }

            // after 5 seconds expect at least 5 oscillations
            if (cnt < 5)
            {
                Assert.Fail("Unacceptable count = " + cnt.ToString());
            }


            c.Disconnect(new Gates.Terminal(0, mnot2));
            cnt    = 0;
            oldval = false;
            start  = DateTime.Now;
            while (DateTime.Now - start < new TimeSpan(0, 0, 5))
            {
                if (mnot1.Output[0] != oldval)
                {
                    oldval = mnot1.Output[0];
                    cnt++;
                }
            }
            // wire is disconnected; no changes should occur
            // 1 change allowable for final sync
            if (cnt > 1)
            {
                Assert.Fail("Disconnect didn't: " + cnt.ToString());
            }
        }
예제 #8
0
        public void OscillationCircuit1()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.BasicGates.And mand  = new Gates.BasicGates.And();
            Gates.BasicGates.And mand2 = new Gates.BasicGates.And();
            Gates.BasicGates.Not mnot  = new Gates.BasicGates.Not();

            c.Add(mand);
            c.Add(mand2);
            c.Add(mnot);
            mand2[0] = true;
            mand[1]  = false;

            c[new Gates.Terminal(1, mand2)] = new Gates.Terminal(0, mand);
            c[new Gates.Terminal(0, mnot)]  = new Gates.Terminal(0, mand2);
            c[new Gates.Terminal(0, mand)]  = new Gates.Terminal(0, mnot);


            int      cnt    = 0;
            bool     oldval = true;
            DateTime start  = DateTime.Now;

            while (DateTime.Now - start < new TimeSpan(0, 0, 5))
            {
                if (mnot.Output[0] != oldval)
                {
                    oldval = mnot.Output[0];
                    cnt++;
                }
            }
            // 5 seconds but circuit should be "off" due to first and
            Assert.AreEqual(0, cnt);

            // turn circuit on and try again
            mand[1] = true;
            cnt     = 0;
            oldval  = false;
            start   = DateTime.Now;
            while (DateTime.Now - start < new TimeSpan(0, 0, 5))
            {
                if (mnot.Output[0] != oldval)
                {
                    oldval = mnot.Output[0];
                    cnt++;
                }
            }

            // 5 seconds at arbitrarily high propagation rate
            // we'll assume AT LEAST 1 prop a second
            if (cnt < 5)
            {
                Assert.Fail("Unacceptable count = " + cnt.ToString());
            }

            c.Stop();
        }
예제 #9
0
        /// <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 = x, Y = y, Angle = 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(""));
            }
        }
예제 #10
0
        public void PropagationTest()
        {
            // this test checks for the accuracy
            // of wait for propagation
            // by determining if it fully waits for all propagation
            // to occur through the contained sub-circuits

            // this came from a problem where all sub-circuits
            // were instructed to wait BUT
            // the loop didn't repeat this based on that
            // so one could pass off an incomplete result
            // to another and the waiting could end before
            // it was all really done
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            // EXTREMELY SPECIFIC
            // The long chain appears FIRST in the circuit add list
            // But the input connects to the short chain first
            // Then the wait waits on the long chain, which has nothing
            // then briefly on the short chain, which passes a change
            // to the long chain...
            // but it DOESN'T wait for the long chain to finish
            // (because it already waited on the long chain before it had any work!)
            Gates.IC ac1 = CreateAndChain(64);
            Gates.IC ac2 = CreateAndChain(10);

            Gates.IOGates.UserInput ui   = new Gates.IOGates.UserInput();
            Gates.BasicGates.And    mand = new Gates.BasicGates.And();

            c.Add(ac1);
            c.Add(ac2);
            c.Add(ui);
            c.Add(mand);

            c[new Gates.Terminal(0, ac2)]  = new Gates.Terminal(0, ui);
            c[new Gates.Terminal(0, ac1)]  = new Gates.Terminal(0, ac2);
            c[new Gates.Terminal(0, mand)] = new Gates.Terminal(0, ac1);
            c[new Gates.Terminal(1, mand)] = new Gates.Terminal(0, ac2);

            ui.Value = false;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(false, mand.Output[0]);

            ui.Value = true;
            Gates.PropagationThread.Instance.WaitOnPropagation();
            Assert.AreEqual(true, mand.Output[0]);
        }
예제 #11
0
        public void SRLatch()
        {
            Gates.Circuit c = new Gates.Circuit();
            c.Start();

            Gates.IOGates.UserInput  ui_r = new Gates.IOGates.UserInput();
            Gates.IOGates.UserInput  ui_s = new Gates.IOGates.UserInput();
            Gates.IOGates.UserOutput uo   = new Gates.IOGates.UserOutput();
            Gates.IC latch = CreateSRLatch();

            c.Add(ui_r);
            c.Add(ui_s);
            c.Add(uo);
            c.Add(latch);

            c[new Gates.Terminal(0, latch)] = new Gates.Terminal(0, ui_r);
            c[new Gates.Terminal(1, latch)] = new Gates.Terminal(0, ui_s);
            c[new Gates.Terminal(0, uo)]    = new Gates.Terminal(0, latch);

            for (int i = 0; i < 4; i++)
            {
                // SET
                ui_r.Value = false;
                ui_s.Value = true;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(true, uo.Value);

                // HOLD
                ui_r.Value = false;
                ui_s.Value = false;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(true, uo.Value);

                // RESET
                ui_r.Value = true;
                ui_s.Value = false;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(false, uo.Value);

                // HOLD
                ui_r.Value = false;
                ui_s.Value = false;
                Gates.PropagationThread.Instance.WaitOnPropagation();
                Assert.AreEqual(false, uo.Value);
            }
        }
예제 #12
0
        public ConnectWire(Gates.Circuit c, Gates.Terminal origin, Gates.Terminal dest)
        {
            this.c      = c;
            this.origin = origin;
            this.dest   = dest;

            c.ReplaceGates += (sender2, e2) =>
            {
                if (e2.ContainsKey(origin.gate) && e2[origin.gate] != null)
                {
                    origin.gate = e2[origin.gate];
                }

                if (e2.ContainsKey(dest.gate) && e2[dest.gate] != null)
                {
                    dest.gate = e2[dest.gate];
                }
            };
        }
예제 #13
0
        /// <summary>
        /// Construct a chart based on the given circuit.
        /// </summary>
        /// <param name="c"></param>
        public Chart(Gates.Circuit c)
        {
            InitializeComponent();
            begin = DateTime.Now;

            foreach (Gates.AbstractGate ag in c)
            {
                AddGate(ag);
            }
            this.c         = c;
            c.ListChanged += c_ListChanged;

            timer = new BackgroundWorker();
            timer.WorkerReportsProgress      = true;
            timer.WorkerSupportsCancellation = true;
            timer.ProgressChanged           += timer_ProgressChanged;
            timer.DoWork += timer_DoWork;

            paused = new TimeSpan();

            slZoom.Value = 7;
            timer.RunWorkerAsync();
        }
예제 #14
0
 public ICBuilder(Gates.Circuit c, GatePosition pos)
 {
     this.c = c;
     this.pos = pos;
 }
예제 #15
0
        /// <summary>
        /// Wire up all event notifications for circuit changes.
        /// </summary>
        /// <param name="c"></param>
        /// <param name="icl"></param>
        protected GateCanvas(Gates.Circuit c, ICList icl)
        {

            InitializeComponent();
            this.icl = icl;
            this.c = c;
            c.CircuitConnection += new Gates.Circuit.CircuitConnectionEventHandler(c_CircuitConnection);
            c.ListChanged += new System.ComponentModel.ListChangedEventHandler(c_ListChanged);
            c.ReplaceGates += new Gates.Circuit.ReplaceGatesEventHandler(c_ReplaceGates);
        }
예제 #16
0
 public ICBuilder(Gates.Circuit c, GatePosition pos)
 {
     this.c   = c;
     this.pos = pos;
 }
예제 #17
0
        /// <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("");
            

        }
예제 #18
0
        public InterTree ParseXElement(XElement root)
        {
            parsedWires.Clear();
            diagramGid.Clear();

            XElement circuit = root.Element("Circuit");

            //Like load XElement
            if (root.Attribute("Version") != null && root.Attribute("Version").Value != "1.2")
                throw new Exception("Unsupport version " + root.Attribute("Version").Value);

            Gates.Circuit c = new Gates.Circuit();

                XElement outputGate = null;

                foreach (XElement gate in circuit.Element("Gates").Elements())
                {
                    Gates.AbstractGate abgate = this.CreateGate(gate);
                    if (gate.Attribute("Type").Value == "UserOutput")
                    {
                        outputGate = gate;
                    }
                    c.Add(abgate);
                    int gateIDTest = int.Parse(gate.Attribute("ID").Value);

                    diagramGid.Add(int.Parse(gate.Attribute("ID").Value), abgate);
                }
                if(outputGate == null)
                    return null;

                char letter = outputGate.Attribute("Name").Value[0];

                InterTree rootInterTree = new InterTree(InterTree.LogicOperator.EQUAL);
                rootInterTree.LeftNode = new InterTree(letter.ToString());

                int gateID = int.Parse(outputGate.Attribute("ID").Value);

                ConvertXElementToInterTree(gateID, ref rootInterTree, circuit);

                return rootInterTree;
        
        }
예제 #19
0
        /// <summary>
        /// Create an XML representation of a given IC.  Nested ICs will be referenced,
        /// but not created by this method.
        /// </summary>
        /// <param name="cc"></param>
        /// <returns></returns>
        public XElement CreateCircuitXML(UIGates.IC cc)
        {
            XElement circuit = new XElement("Circuit");

            circuit.SetAttributeValue("Name", cc.AbGate.Name);



            XElement gates = new XElement("Gates");
            Dictionary <Gates.AbstractGate, int> gid = new Dictionary <Gates.AbstractGate, int>();
            int cid = 1;

            Gates.Circuit circ = ((Gates.IC)cc.AbGate).Circuit;
            foreach (Gates.AbstractGate g in circ)
            {
                XElement gt = new XElement("Gate");
                gt.SetAttributeValue("Type", g.GetType().Name);
                gt.SetAttributeValue("Name", g.Name);
                gt.SetAttributeValue("ID", cid);
                gt.Add(new XElement("Point"));
                gt.Element("Point").SetAttributeValue("X", cc.locationHints[g].X);
                gt.Element("Point").SetAttributeValue("Y", cc.locationHints[g].Y);
                gt.Element("Point").SetAttributeValue("Angle", cc.locationHints[g].Angle);

                if (g is Gates.IVariableInputs)
                {
                    gt.SetAttributeValue("NumInputs", g.NumberOfInputs);
                }

                if (g is Gates.IOGates.AbstractNumeric)
                {
                    gt.SetAttributeValue("Bits", ((Gates.IOGates.AbstractNumeric)g).Bits);
                    gt.SetAttributeValue("SelRep", (int)(((Gates.IOGates.AbstractNumeric)g).SelectedRepresentation));
                    gt.SetAttributeValue("Value", ((Gates.IOGates.AbstractNumeric)g).Value);
                }
                if (g is Gates.IOGates.Clock)
                {
                    gt.SetAttributeValue("Milliseconds", ((Gates.IOGates.Clock)g).Milliseconds);
                }
                if (g is Gates.IOGates.Comment)
                {
                    gt.Add(new XElement("Comment", ((Gates.IOGates.Comment)g).Value));
                }
                gates.Add(gt);
                gid.Add(g, cid);
                cid++;
            }

            XElement wires = new XElement("Wires");

            foreach (Gates.AbstractGate g in circ)
            {
                for (int i = 0; i < g.NumberOfInputs; i++)
                {
                    Gates.Terminal t = circ.GetSource(new Gates.Terminal(i, g));
                    if (t != null)
                    {
                        XElement wire = new XElement("Wire",
                                                     new XElement("From"), new XElement("To"));
                        wire.Element("From").SetAttributeValue("ID", gid[t.gate]);
                        wire.Element("From").SetAttributeValue("Port", t.portNumber);
                        wire.Element("To").SetAttributeValue("ID", gid[g]);
                        wire.Element("To").SetAttributeValue("Port", i);
                        wires.Add(wire);
                    }
                }
            }


            circuit.Add(gates);
            circuit.Add(wires);
            return(circuit);
        }
예제 #20
0
 public ChangeNumInputs(Gates.Circuit c, Gates.AbstractGate original, Gates.AbstractGate replacement)
 {
     this.c = c;
     this.orig_gate = original;
     this.new_gate = replacement;
 }
예제 #21
0
        public ConnectWire(Gates.Circuit c, Gates.Terminal origin, Gates.Terminal dest)
        {
            this.c = c;
            this.origin = origin;
            this.dest = dest;

            c.ReplaceGates += (sender2, e2) =>
            {
                if (e2.ContainsKey(origin.gate) && e2[origin.gate] != null)
                {
                    origin.gate = e2[origin.gate];
                }

                if (e2.ContainsKey(dest.gate) && e2[dest.gate] != null)
                {
                    dest.gate = e2[dest.gate];
                }
            };
        }
예제 #22
0
 public ChangeNumInputs(Gates.Circuit c, Gates.AbstractGate original, Gates.AbstractGate replacement)
 {
     this.c         = c;
     this.orig_gate = original;
     this.new_gate  = replacement;
 }