Пример #1
0
        /// <summary>
        /// Add a gate to this canvas.  An appropriate visual representation will be created.
        /// </summary>
        /// <param name="gate"></param>
        /// <param name="pos"></param>
        public void AddGate(Gates.AbstractGate gate, GateLocation pos)
        {
            // maybe we could use extension methods
            // to add a method to create a UIGate for each AbstractGate?

            Gate uigate;
            if (gate is Gates.BasicGates.And)
            {
                uigate = new UIGates.And((Gates.BasicGates.And)gate);
            }
            else if (gate is Gates.BasicGates.Not)
            {
                uigate = new UIGates.Not((Gates.BasicGates.Not)gate);
            }
            else if (gate is Gates.BasicGates.Or)
            {
                uigate = new UIGates.Or((Gates.BasicGates.Or)gate);
            }
            else if (gate is Gates.BasicGates.Nand)
            {
                uigate = new UIGates.Nand((Gates.BasicGates.Nand)gate);
            }
            else if (gate is Gates.BasicGates.Nor)
            {
                uigate = new UIGates.Nor((Gates.BasicGates.Nor)gate);
            }
            else if (gate is Gates.BasicGates.Xor)
            {
                uigate = new UIGates.Xor((Gates.BasicGates.Xor)gate);
            }
            else if (gate is Gates.BasicGates.Xnor)
            {
                uigate = new UIGates.Xnor((Gates.BasicGates.Xnor)gate);
            }
            else if (gate is Gates.BasicGates.Buffer)
            {
                uigate = new UIGates.Buffer((Gates.BasicGates.Buffer)gate);
            }
            else if (gate is Gates.IOGates.UserInput)
            {
                uigate = new UIGates.UserInput((Gates.IOGates.UserInput)gate);
            }
            else if (gate is Gates.IOGates.UserOutput)
            {
                uigate = new UIGates.UserOutput((Gates.IOGates.UserOutput)gate);
            }
            else if (gate is Gates.IOGates.AbstractNumeric)
            {
                uigate = new UIGates.Numeric((Gates.IOGates.AbstractNumeric)gate);
            }
            else if (gate is Gates.IOGates.Clock)
            {
                uigate = new UIGates.Clock((Gates.IOGates.Clock)gate);
            }
            else if (gate is Gates.IOGates.Comment)
            {
                uigate = new UIGates.Comment((Gates.IOGates.Comment)gate);
            }
            else if (gate is Gates.IC)
            {
                uigate = UIGates.IC.CreateFromTemplate((Gates.IC)gate, icl.GetIC(gate.Name));
            }
            else throw new ArgumentException("gate not of known subclass");

            AddGate(uigate, pos);
        }
Пример #2
0
        public override Gate CreateUserInstance()
        {
            Numeric n;
            if (_nu is Gates.IOGates.NumericInput)
            {
                n = new Numeric(new Gates.IOGates.NumericInput(_nu.Bits));
                ((Gates.IOGates.NumericInput)n.AbGate).SelectedRepresentation = _nu.SelectedRepresentation;
                ((Gates.IOGates.NumericInput)n.AbGate).Value = _nu.Value;
            }
            else
            {
                n = new Numeric(new Gates.IOGates.NumericOutput(_nu.Bits));
                ((Gates.IOGates.NumericOutput)n.AbGate).SelectedRepresentation = _nu.SelectedRepresentation;
            }
            return n;
            

        }