Esempio n. 1
0
        private static bool IsValid(GateType gateType, int inputCount)
        {
            Tracer.Assert(GateSet.IsValid(gateType));
            switch (gateType)
            {
            case GateType.Nop:
            case GateType.Clock:
                return(inputCount == 0);

            case GateType.Not:
                return(inputCount == 1);

            case GateType.Or:
            case GateType.And:
            case GateType.Xor:
                return(1 < inputCount && inputCount <= LogicCircuit.Gate.MaxInputCount);

            case GateType.Led:
                return(inputCount == 1 || inputCount == 8);

            case GateType.TriState1:
            case GateType.TriState2:
                return(inputCount == 2);

            case GateType.Odd:
            case GateType.Even:
            case GateType.Probe:
                Tracer.Fail();
                return(false);

            default:
                return(false);
            }
        }
Esempio n. 2
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)
                     ));
 }
Esempio n. 3
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);
        }
Esempio n. 4
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;
     }
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private Gate Create(GateType gateType, int inputCount, bool invertedOutput)
        {
            Gate gate = this.CreateItem(GateSet.GateGuid(gateType, inputCount, invertedOutput));

            gate.GateType       = gateType;
            gate.InvertedOutput = invertedOutput;
            switch (gate.GateType)
            {
            case GateType.Clock:
                gate.Name     = Properties.Resources.GateClockName;
                gate.Notation = Properties.Resources.GateClockNotation;
                gate.Category = Properties.Resources.CategoryInputOutput;
                break;

            case GateType.Not:
                gate.Name     = Properties.Resources.GateNotName;
                gate.Notation = Properties.Resources.GateNotNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Or:
                gate.Name     = invertedOutput ? Properties.Resources.GateOrNotName : Properties.Resources.GateOrName;
                gate.Notation = Properties.Resources.GateOrNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.And:
                gate.Name     = invertedOutput ? Properties.Resources.GateAndNotName : Properties.Resources.GateAndName;
                gate.Notation = Properties.Resources.GateAndNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Xor:
                gate.Name     = invertedOutput ? Properties.Resources.GateXorNotName : Properties.Resources.GateXorName;
                gate.Notation = Properties.Resources.GateXorNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Led:
                Tracer.Assert(inputCount == 1 || inputCount == 8);
                gate.Name     = (inputCount == 1) ? Properties.Resources.GateLedName : Properties.Resources.Gate7SegName;
                gate.Notation = Properties.Resources.GateLedNotation;
                gate.Category = Properties.Resources.CategoryInputOutput;
                break;

            case GateType.TriState1:
            case GateType.TriState2:
                gate.Name     = Properties.Resources.GateTriStateName;
                gate.Notation = Properties.Resources.GateTriStateNotation;
                gate.Category = Properties.Resources.CategoryPrimitives;
                break;

            case GateType.Odd:
            case GateType.Even:
            case GateType.Probe:
            default:
                Tracer.Fail();
                break;
            }
            if (gate.GateType == GateType.TriState1 || gate.GateType == GateType.TriState2)
            {
                this.GenerateTriStatePins(gate);
            }
            else if (gate.GateType == GateType.Led && inputCount == 8)
            {
                this.GenerateSevenSegmentIndicatorPins(gate);
            }
            else
            {
                this.GeneratePins(gate, inputCount, invertedOutput);
            }
            return(gate);
        }
Esempio n. 7
0
 private static bool HasOutput(GateType gateType)
 {
     Tracer.Assert(GateSet.IsValid(gateType));
     return(gateType != GateType.Nop && gateType != GateType.Led);
 }