Пример #1
0
        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());
        }
Пример #2
0
        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);
        }
Пример #3
0
        public Tuple <List <DrawableComponent>, List <DrawableWire> > GenerateDrawables(List <ICDescription> availableDescriptions, Vector2 offset)
        {
            DrawableComponent[] components = new DrawableComponent[Components.Count];

            for (int i = 0; i < Components.Count; i++)
            {
                WorkspaceComponent wc = Components[i];
                DrawableComponent  dc = null;
                switch (wc.Type)
                {
                case "ANDGateLogic":
                    dc = new DrawableLogicGate(wc.Position + offset, "AND", new ANDGateLogic(), false);
                    break;

                case "NANDGateLogic":
                    dc = new DrawableLogicGate(wc.Position + offset, "NAND", new NANDGateLogic(), false);
                    break;

                case "ORGateLogic":
                    dc = new DrawableLogicGate(wc.Position + offset, "OR", new ORGateLogic(), false);
                    break;

                case "NORGateLogic":
                    dc = new DrawableLogicGate(wc.Position + offset, "NOR", new NORGateLogic(), false);
                    break;

                case "XORGateLogic":
                    dc = new DrawableLogicGate(wc.Position + offset, "XOR", new XORGateLogic(), false);
                    break;

                case "XNORGateLogic":
                    dc = new DrawableLogicGate(wc.Position + offset, "XNOR", new XNORGateLogic(), false);
                    break;

                case "NOTGateLogic":
                    dc = new DrawableLogicGate(wc.Position + offset, "NOT", new NOTGateLogic(), false);
                    break;

                case "Switch":
                    dc = new DrawableCircuitSwitch(wc.Position + offset, false)
                    {
                        ID = wc.ID
                    };
                    break;

                case "Lamp":
                    dc = new DrawableCircuitLamp(wc.Position + offset, false)
                    {
                        ID = wc.ID
                    };
                    break;

                default:
                    ICDescription icd = GetDescription(wc.Type, availableDescriptions);
                    if (icd != null)
                    {
                        dc = new DrawableIC(wc.Position + offset, icd.Name, icd, false);
                    }
                    else
                    {
                        break;
                    }
                    break;
                }
                components[i] = dc;
            }

            List <DrawableWire> wires = new List <DrawableWire>();

            for (int i = 0; i < Components.Count; i++)
            {
                WorkspaceComponent iccd = Components[i];

                foreach (WorkspaceComponentConnection connection in iccd.ConnectedTo)
                {
                    try
                    {
                        DrawableWire cw = new DrawableWire(components[i], components[connection.To], connection.OutIndex, connection.InIndex);

                        components[i].AddOutputWire(connection.OutIndex, cw);
                        components[connection.To].SetInputWire(connection.InIndex, cw);

                        wires.Add(cw);
                    }
                    catch
                    {
                    }
                }
            }

            return(new Tuple <List <DrawableComponent>, List <DrawableWire> >(components.ToList(), wires));
        }