Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo 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);
        }