Пример #1
0
        /// <summary>
        /// Define an IC based on a circuit with identified input and output ports.
        /// Ports must be a member of the circuit.
        /// </summary>
        /// <param name="circuit"></param>
        /// <param name="inputs"></param>
        /// <param name="outputs"></param>
        /// <param name="name"></param>
        public IC(Circuit circuit, UserInput[] inputs, UserOutput[] outputs, string name)
            : base(inputs.Length, outputs.Length)
        {
            foreach (UserInput p in inputs)
                if (!circuit.Contains(p))
                    throw new ArgumentException("not all inputs part of circuit");

            // we wire up the output ports so that any internal
            // change in the circuit results in
            // passing notification up the chain
            // this is not needed for input because
            // any input change will cause compute to be called
            // automatically
            foreach (UserOutput p in outputs)
            {
                p.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(p_PropertyChanged);
                if (!circuit.Contains(p))
                    throw new ArgumentException("not all outputs part of circuit");
            }
            _inputs = inputs;
            _outputs = outputs;
            _circuit = circuit;
            _name = name;

            RunCompute();
        }
Пример #2
0
        public IC Clone(string newName)
        {
            Circuit nc = _circuit.Clone();

            UserInput[] nui = new UserInput[_inputs.Length];
            for (int i = 0; i < _inputs.Length; i++)
                nui[i] = (UserInput)nc[_circuit.IndexOf(_inputs[i])];

            UserOutput[] nuo = new UserOutput[_outputs.Length];
            for (int i = 0; i < _outputs.Length; i++)
                nuo[i] = (UserOutput)nc[_circuit.IndexOf(_outputs[i])];

            IC nic = new IC(nc, nui, nuo, newName);

            return nic;
        }
Пример #3
0
 public override AbstractGate Clone()
 {
     UserInput ui = new UserInput();
     ui.SetName(Name);
     return ui;
 }