コード例 #1
0
        public FunctionSensor(CircuitState circuitState, CircuitSymbol symbol, int[] result) : base(circuitState, null, result)
        {
            this.CircuitSymbol = symbol;
            Tracer.Assert(this.BitWidth == result.Length);
            switch (this.Sensor.SensorType)
            {
            case SensorType.Series:
            case SensorType.Loop:
                this.sensorValue = new SeriesValue(this.Sensor.Data, this.Sensor.SensorType == SensorType.Loop, this.Sensor.BitWidth);
                break;

            case SensorType.Random:
                this.sensorValue = new RandomValue(this.Sensor.Data, this.Sensor.BitWidth, this.CircuitState.Random);
                break;

            case SensorType.Manual:
                this.sensorValue = new ManualValue(this.Sensor.Data, this.Sensor.BitWidth);
                break;

            default:
                Tracer.Fail();
                this.sensorValue = null;
                break;
            }
        }
コード例 #2
0
        public static string ToText(IEnumerable <State> probeState, bool showFormatPrefix)
        {
            int value = 0;
            int count = 0;

            foreach (State state in probeState)
            {
                Tracer.Assert(count < 32);
                switch (state)
                {
                case State.Off:
                    return(CircuitFunction.Binary(probeState));

                case State.On0:
                    break;

                case State.On1:
                    value |= 1 << count;
                    break;

                default:
                    Tracer.Fail();
                    break;
                }
                count++;
            }
            if (showFormatPrefix && 1 < count)
            {
                return(string.Format(CultureInfo.InvariantCulture, "0x{0:X}", value));
            }
            else
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0:X}", value));
            }
        }
コード例 #3
0
        public GateDescriptor(Gate gate, string note) : base(gate)
        {
            switch (gate.GateType)
            {
            case GateType.Clock:
            case GateType.Not:
            case GateType.Led:
            case GateType.TriState1:
            case GateType.TriState2:
                this.InputCountRangeLength = 0;
                break;

            case GateType.Or:
            case GateType.And:
            case GateType.Xor:
                this.InputCountRange       = GateDescriptor.inputCountRange;
                this.InputCountRangeLength = GateDescriptor.inputCountRange.Length;
                break;

            default:
                Tracer.Fail();
                break;
            }
            this.InputCount = gate.InputCount;
            gate.Note       = note;
        }
コード例 #4
0
        public Sensor Create(SensorType sensorType, int bitWidth, PinSide pinSide, string notation)
        {
            string data;

            switch (sensorType)
            {
            case SensorType.Series:
            case SensorType.Loop:
                data = Sensor.DefaultSeriesData;
                break;

            case SensorType.Random:
                data = Sensor.DefaultRandomData;
                break;

            case SensorType.Manual:
                data = string.Empty;
                break;

            default:
                Tracer.Fail();
                data = null;
                break;
            }
            Sensor sensor = this.CreateItem(Guid.NewGuid(), sensorType, bitWidth, pinSide, notation, data, SensorData.NoteField.Field.DefaultValue);

            this.CreateDevicePin(sensor);
            return(sensor);
        }
コード例 #5
0
        public FunctionGraphicsArray(
            CircuitState circuitState,
            int[] address,
            int[] inputData,
            int[] outputData,
            int write,
            IEnumerable <CircuitSymbol> symbols
            ) : base(circuitState, FunctionMemory.Input(address, null, inputData, write), outputData)
        {
            this.circuitSymbol = symbols.ToList();
            Tracer.Assert(0 < this.circuitSymbol.Count);

            GraphicsArray graphicsArray = (GraphicsArray)this.circuitSymbol[0].Circuit;

            this.project = graphicsArray.CircuitProject.ProjectSet.Project;

            this.address   = address;
            this.inputData = inputData;
            this.write     = write;
            this.writeOn   = graphicsArray.WriteOn1 ? State.On1 : State.On0;

            Tracer.Assert(this.inputData.Length == outputData.Length && this.inputData.Length == graphicsArray.DataBitWidth);

            this.bitsPerPixel = graphicsArray.BitsPerPixel;
            this.drawingRect  = new Int32Rect(0, 0, graphicsArray.Width, graphicsArray.Height);

            int w = this.drawingRect.Width * this.bitsPerPixel;

            this.memoryStride = w / this.DataBitWidth + (((w % this.DataBitWidth) == 0) ? 0 : 1);
            int byteStride = w / 8 + (((w % 8) == 0) ? 0 : 1);

            this.bitmapStride = Math.Max(byteStride * 8, this.memoryStride * this.DataBitWidth) / 8;
            Tracer.Assert(this.memoryStride * this.DataBitWidth <= this.bitmapStride * 8);
            this.zoom = graphicsArray.Zoom;

            switch (graphicsArray.OnStart)
            {
            case MemoryOnStart.Random:
                this.data = this.Allocate();
                circuitState.Random.NextBytes(this.data);
                break;

            case MemoryOnStart.Zeros:
                this.data = this.Allocate();
                break;

            case MemoryOnStart.Ones:
                this.data = this.Allocate();
                for (int i = 0; i < this.data.Length; i++)
                {
                    this.data[i] = 0xFF;
                }
                break;

            case MemoryOnStart.Data:
            default:
                Tracer.Fail();
                break;
            }
        }
コード例 #6
0
        public static bool ToInt(long packed, int bitWidth, out int result)
        {
            Tracer.Assert(0 < bitWidth && bitWidth <= 32);
            int unpacked = 0;

            for (int i = 0; i < bitWidth; i++)
            {
                switch ((State)((packed >> (i * 2)) & 0x3))
                {
                case State.Off:
                    result = 0;
                    return(false);

                case State.On0:
                    break;

                case State.On1:
                    unpacked |= (1 << i);
                    break;

                default:
                    Tracer.Fail();
                    break;
                }
            }
            result = unpacked;
            return(true);
        }
コード例 #7
0
        public void TurnOn()
        {
            // Bitmap should be created on UI thread, so this is the right place for it.
            PixelFormat   format  = new PixelFormat();
            BitmapPalette palette = null;

            switch (this.bitsPerPixel)
            {
            case 1:
                format  = PixelFormats.Indexed1;
                palette = BitmapPalettes.BlackAndWhite;
                break;

            case 2:
                format  = PixelFormats.Indexed2;
                palette = BitmapPalettes.Gray4;
                break;

            case 4:
                format  = PixelFormats.Indexed4;
                palette = BitmapPalettes.Halftone8;
                break;

            case 8:
                format  = PixelFormats.Indexed8;
                palette = BitmapPalettes.Halftone256;
                break;

            default:
                Tracer.Fail();
                break;
            }
            this.bitmap  = new WriteableBitmap(this.drawingRect.Width, this.drawingRect.Height, 96, 96, format, palette);
            this.Invalid = true;
        }
コード例 #8
0
        public DialogPin(Pin pin)
        {
            this.DataContext = this;
            this.pin         = pin;
            this.InitializeComponent();
            switch (this.pin.PinType)
            {
            case PinType.None:
                this.type.Text = Properties.Resources.PinTypeNameNone;
                break;

            case PinType.Input:
                this.type.Text = Properties.Resources.PinTypeNameInput;
                break;

            case PinType.Output:
                this.type.Text = Properties.Resources.PinTypeNameOutput;
                break;

            default:
                Tracer.Fail("Unknown pin type");
                break;
            }
            this.name.Text             = this.pin.Name;
            this.notation.Text         = this.pin.JamNotation;
            this.note.Text             = this.pin.Note;
            this.side.ItemsSource      = PinDescriptor.PinSideRange;
            this.side.SelectedItem     = PinDescriptor.PinSideDescriptor(this.pin.PinSide);
            this.inverted.IsChecked    = this.pin.Inverted;
            this.bitWidth.ItemsSource  = PinDescriptor.BitWidthRange;
            this.bitWidth.SelectedItem = this.pin.BitWidth;
        }
コード例 #9
0
ファイル: Gate.cs プロジェクト: liuhui2010518/logiccircuit
        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);
            }
        }
コード例 #10
0
        protected FunctionMemory(
            CircuitState circuitState, int[] address, int[] inputData, int[] outputData, int[] address2, int[] outputData2, int write, Memory memory
            ) : base(circuitState, FunctionMemory.Input(address, address2, inputData, write), FunctionMemory.Output(outputData, outputData2))
        {
            this.address     = address;
            this.address2    = address2;
            this.inputData   = inputData;
            this.outputData  = outputData;
            this.outputData2 = outputData2;
            this.Memory      = memory;
            if (inputData != null)
            {
                Tracer.Assert(memory.Writable);
                Tracer.Assert(this.inputData.Length == this.outputData.Length);
                this.write   = write;
                this.writeOn = this.Memory.WriteOn1 ? State.On1 : State.On0;
                switch (this.Memory.OnStart)
                {
                case MemoryOnStart.Random:
                    this.data = this.Allocate();
                    circuitState.Random.NextBytes(this.data);
                    break;

                case MemoryOnStart.Zeros:
                    this.data = this.Allocate();
                    break;

                case MemoryOnStart.Ones:
                    this.data = this.Allocate();
                    for (int i = 0; i < this.data.Length; i++)
                    {
                        this.data[i] = 0xFF;
                    }
                    break;

                case MemoryOnStart.Data:
                    this.data = memory.MemoryValue();
                    break;

                default:
                    Tracer.Fail();
                    break;
                }
            }
            else
            {
                Tracer.Assert(!memory.Writable);
                this.write = -1;
                this.data  = memory.MemoryValue();
            }
        }
コード例 #11
0
        public static double Angle(Rotation rotation)
        {
            switch (rotation)
            {
            case Rotation.Up:       return(0);

            case Rotation.Right: return(90);

            case Rotation.Down:     return(180);

            case Rotation.Left:     return(-90);
            }
            Tracer.Fail("Invalid Rotation");
            return(0);
        }
コード例 #12
0
        private Sensor Register(RowId rowId)
        {
            CircuitData data = new CircuitData()
            {
                CircuitId = this.Table.GetField(rowId, SensorData.SensorIdField.Field)
            };
            Sensor sensor = this.Create(rowId, this.CircuitProject.CircuitTable.Insert(ref data));

            this.CreateDevicePin(sensor);

            IList <SensorPoint> list;
            SensorPoint         point;

            switch (sensor.SensorType)
            {
            case SensorType.Series:
            case SensorType.Loop:
                if (!Sensor.TryParseSeries(sensor.Data, sensor.BitWidth, out list))
                {
                    sensor.Data = Sensor.DefaultSeriesData;
                }
                break;

            case SensorType.Random:
                if (!Sensor.TryParsePoint(sensor.Data, 32, out point))
                {
                    sensor.Data = Sensor.DefaultRandomData;
                }
                break;

            case SensorType.Manual:
                break;

            default:
                Tracer.Fail();
                break;
            }

            return(sensor);
        }
コード例 #13
0
        public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
        {
            Tracer.Assert(this == symbol.Circuit);
            string skin = SymbolShape.SensorAuto;

            switch (this.SensorType)
            {
            case LogicCircuit.SensorType.Series:
            case LogicCircuit.SensorType.Loop:
            case LogicCircuit.SensorType.Random:
                break;

            case LogicCircuit.SensorType.Manual:
                skin = SymbolShape.SensorManual;
                break;

            default:
                Tracer.Fail();
                break;
            }
            return(symbol.CreateSensorGlyph(skin));
        }
コード例 #14
0
        protected void InTransaction(Action action)
        {
            CircuitProject project = this.Circuit.CircuitProject;

            if (project.StartTransaction())
            {
                try {
                    action();
                } catch {
                    project.Rollback();
                    throw;
                } finally {
                    if (project.IsEditor)
                    {
                        project.Omit();
                    }
                }
            }
            else
            {
                Tracer.Fail();
            }
        }
コード例 #15
0
            private void Plug()
            {
                List <Pin> pins = this.LogicalCircuit.CircuitProject.PinSet.SelectByCircuit(this.LogicalCircuit).ToList();

                pins.Sort(PinComparer.Comparer);
                this.LogicalCircuit.CircuitProject.InTransaction(() => {
                    foreach (Pin pin in pins)
                    {
                        if (pin.PinType == PinType.Input)
                        {
                            this.Inputs.Add(new InputPinSocket(pin));
                        }
                        else if (pin.PinType == PinType.Output)
                        {
                            this.Outputs.Add(new OutputPinSocket(pin));
                        }
                        else
                        {
                            Tracer.Fail();
                        }
                    }
                });
            }
コード例 #16
0
 public int this[int index] {
     get { return(this.Read(index)); }
     //TODO: implement
     set { Tracer.Fail("Not yet implemented"); }
 }
コード例 #17
0
ファイル: Tracer.cs プロジェクト: liuhui2010518/logiccircuit
 //public static void Fail(string reason, params object[] args) {
 //	Tracer.Fail(string.Format(CultureInfo.CurrentUICulture, reason, args));
 //}
 public static void Fail()
 {
     Tracer.Fail("Internal Error.");
 }
コード例 #18
0
ファイル: Gate.cs プロジェクト: liuhui2010518/logiccircuit
        public override FrameworkElement CreateGlyph(CircuitGlyph symbol)
        {
            Tracer.Assert(this == symbol.Circuit);
            string skin;

            switch (this.GateType)
            {
            case GateType.Clock:
                skin = SymbolShape.Clock;
                break;

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

            case GateType.Led:
                if (this.InputCount == 1)
                {
                    skin = SymbolShape.Led;
                }
                else
                {
                    Tracer.Assert(this.InputCount == 8);
                    skin = SymbolShape.SevenSegment;
                }
                break;

            default:
                if (Settings.User.GateShape == GateShape.Rectangular)
                {
                    return(symbol.CreateRectangularGlyph());
                }
                else
                {
                    switch (this.GateType)
                    {
                    case GateType.Not:
                        skin = SymbolShape.ShapedNot;
                        break;

                    case GateType.Or:
                        skin = SymbolShape.ShapedOr;
                        break;

                    case GateType.And:
                        skin = SymbolShape.ShapedAnd;
                        break;

                    case GateType.Xor:
                        skin = SymbolShape.ShapedXor;
                        break;

                    case GateType.TriState1:
                        skin = SymbolShape.ShapedTriState1;
                        break;

                    case GateType.TriState2:
                        skin = SymbolShape.ShapedTriState2;
                        break;

                    default:
                        Tracer.Fail();
                        return(null);
                    }
                    return(symbol.CreateShapedGlyph(skin));
                }
            }
            return(symbol.CreateSimpleGlyph(skin, symbol));
        }
コード例 #19
0
ファイル: Gate.cs プロジェクト: liuhui2010518/logiccircuit
        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);
        }