Пример #1
0
        public UIGates.IC CreateIC(string name, SELECTED_GATES selectedOnly)
        {
            Gates.Circuit nc;
            Dictionary<int, int> idxmap = null;

            if ((selected.Count > 1 && selectedOnly == SELECTED_GATES.SELECTED_IF_TWO_OR_MORE) || selectedOnly == SELECTED_GATES.SELECTED)
                nc = c.Clone(selected.ToList().ConvertAll(g => g.AbGate), out idxmap);
            else
                nc = c.Clone();

            ICBuilder icb = new ICBuilder(nc, new ICBuilder.GatePosition(gate =>
            {
                int idx = nc.IndexOf(gate);
                if (idxmap != null)
                {
                    foreach (KeyValuePair<int, int> kv in idxmap)
                        if (kv.Value == idx)
                        {
                            idx = kv.Key;
                            break;
                        }// this makes me want to cry
                    // there must be a better way to look up by value
                    // because the value is the new circuit idx
                    // and the key is the old circuit idx
                    // don't just reverse it on create
                    // we use it the other way too

                }

                Gates.AbstractGate oldgate = c[idx];
                return new GateLocation(gates[oldgate].Margin.Left, gates[oldgate].Margin.Top, ((RotateTransform)gates[oldgate].RenderTransform).Angle);
            }));
            return icb.CreateIC(name);
        }
Пример #2
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("");
            

        }