Example #1
0
 private void GeneratePins(Gate gate, int inputCount, bool invertedOutput)
 {
     if (inputCount == 1)
     {
         DevicePin pin = this.CircuitProject.DevicePinSet.Create(gate, PinType.Input, 1);
         pin.Name = Properties.Resources.PinInName;
     }
     else
     {
         for (int i = 0; i < inputCount; i++)
         {
             DevicePin pin = this.CircuitProject.DevicePinSet.Create(gate, PinType.Input, 1);
             pin.Name = Properties.Resources.PinName(Properties.Resources.PinInName, i + 1);
         }
     }
     if (GateSet.HasOutput(gate.GateType))
     {
         DevicePin pin = this.CircuitProject.DevicePinSet.Create(gate, PinType.Output, 1);
         pin.Inverted = invertedOutput;
         pin.Name     = Properties.Resources.PinOutName;
     }
 }
Example #2
0
        public Gate Gate(GateType gateType, int inputCount, bool invertedOutput)
        {
            if (!GateSet.IsValid(gateType))
            {
                throw new ArgumentOutOfRangeException("gateType");
            }
            if (!GateSet.IsValid(gateType, inputCount))
            {
                throw new ArgumentOutOfRangeException("inputCount");
            }
            if (invertedOutput && !GateSet.HasOutput(gateType))
            {
                throw new ArgumentOutOfRangeException("invertedOutput");
            }
            Gate gate = this.FindByGateId(GateSet.GateGuid(gateType, inputCount, invertedOutput));

            if (gate == null)
            {
                return(this.Create(gateType, inputCount, invertedOutput));
            }
            return(gate);
        }
Example #3
0
 private static Guid GateGuid(GateType gateType, int inputCount, bool invertedOutput)
 {
     Tracer.Assert(gateType != GateType.Nop && GateSet.IsValid(gateType, inputCount) && (!invertedOutput || GateSet.HasOutput(gateType)));
     return(new Guid(0, 0, 0, 0, 0, 0, 0, 0,
                     (byte)(int)gateType,
                     (byte)inputCount,
                     (byte)(invertedOutput ? 1 : 0)
                     ));
 }
Example #4
0
        public Gate Gate(Guid gateId)
        {
            Gate gate = this.FindByGateId(gateId);

            if (gate != null)
            {
                return(gate);
            }
            byte[]   id             = gateId.ToByteArray();
            GateType gateType       = (GateType)(int)id[13];
            int      inputCount     = (int)id[14];
            bool     invertedOutput = (id[15] == 0) ? false : true;

            if (GateSet.IsValid(gateType) && GateSet.IsValid(gateType, inputCount) && (!invertedOutput || GateSet.HasOutput(gateType)) && GateSet.GateGuid(gateType, inputCount, invertedOutput) == gateId)
            {
                return(this.Create(gateType, inputCount, invertedOutput));
            }
            return(null);
        }