public DialogGraphicsArray(GraphicsArray graphicsArray) { this.graphicsArray = graphicsArray; this.parsedWidth = this.graphicsArray.Width; this.parsedHeight = this.graphicsArray.Height; this.GraphicsArrayWidth = this.parsedWidth.ToString(Properties.Resources.Culture); this.GraphicsArrayHeight = this.parsedHeight.ToString(Properties.Resources.Culture); this.DataContext = this; this.InitializeComponent(); this.dataBitWidth.ItemsSource = GraphicsArrayDescriptor.DataBitWidthRange; this.bitsPerPixel.ItemsSource = GraphicsArrayDescriptor.BitsPerPixelRange; IEnumerable <EnumDescriptor <bool> > writeOnList = MemoryDescriptor.WriteOnList; this.writeOn.ItemsSource = writeOnList; EnumDescriptor <MemoryOnStart>[] onStartList = new EnumDescriptor <MemoryOnStart>[] { new EnumDescriptor <MemoryOnStart>(MemoryOnStart.Random, Properties.Resources.MemoryOnStartRandom), new EnumDescriptor <MemoryOnStart>(MemoryOnStart.Zeros, Properties.Resources.MemoryOnStartZeros), new EnumDescriptor <MemoryOnStart>(MemoryOnStart.Ones, Properties.Resources.MemoryOnStartOnes), //new EnumDescriptor<MemoryOnStart>(MemoryOnStart.Data, Properties.Resources.MemoryOnStartData) }; this.onStart.ItemsSource = onStartList; this.dataBitWidth.SelectedItem = this.graphicsArray.DataBitWidth; this.bitsPerPixel.SelectedItem = this.graphicsArray.BitsPerPixel; this.writeOn.SelectedItem = writeOnList.First(d => d.Value == this.graphicsArray.WriteOn1); this.onStart.SelectedItem = onStartList.First(d => d.Value == this.graphicsArray.OnStart); this.note.Text = this.graphicsArray.Note; }
private void CreateDevicePins(GraphicsArray graphicsArray) { Tracer.Assert(!this.CircuitProject.DevicePinSet.SelectByCircuit(graphicsArray).Any()); // The order of creation of the pins is essential for expansion algorithm. DevicePin address = this.CircuitProject.DevicePinSet.Create(graphicsArray, PinType.Input, graphicsArray.AddressBitWidth); address.PinSide = PinSide.Left; address.Name = Properties.Resources.MemoryAddressPinName; DevicePin data = this.CircuitProject.DevicePinSet.Create(graphicsArray, PinType.Output, graphicsArray.DataBitWidth); data.PinSide = PinSide.Right; data.Name = Properties.Resources.MemoryDataPinName; DevicePin dataIn = this.CircuitProject.DevicePinSet.Create(graphicsArray, PinType.Input, graphicsArray.DataBitWidth); dataIn.PinSide = PinSide.Left; dataIn.Name = Properties.Resources.MemoryDataInPinName; DevicePin write = this.CircuitProject.DevicePinSet.Create(graphicsArray, PinType.Input, 1); write.PinSide = PinSide.Bottom; write.Name = Properties.Resources.MemoryWritePinName(graphicsArray.WriteOn1 ? Properties.Resources.WriteOn1 : Properties.Resources.WriteOn0); graphicsArray.SetPins(address, data, dataIn, write); GraphicsArraySet.UpdateWritePinName(graphicsArray); }
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; } }
private GraphicsArray Register(RowId rowId) { CircuitData data = new CircuitData() { CircuitId = this.Table.GetField(rowId, GraphicsArrayData.GraphicsArrayIdField.Field) }; GraphicsArray graphicsArray = this.Create(rowId, this.CircuitProject.CircuitTable.Insert(ref data)); this.CreateDevicePins(graphicsArray); return(graphicsArray); }
public static int AddressBitsFor(int dataBitWidth, int bitsPerPixel, int width, int height) { int bits = 0; int max = GraphicsArray.NumberCellsFor(dataBitWidth, bitsPerPixel, width, height) - 1; while (max != 0) { bits++; max >>= 1; } return(Math.Max(1, bits)); }
public GraphicsArray Copy(GraphicsArray other) { GraphicsArrayData data; other.CircuitProject.GraphicsArraySet.Table.GetData(other.GraphicsArrayRowId, out data); if (this.FindByGraphicsArrayId(data.GraphicsArrayId) != null) { data.GraphicsArrayId = Guid.NewGuid(); } data.GraphicsArray = null; return(this.Register(this.Table.Insert(ref data))); }
public GraphicsArray Create(int dataBitWidth, int bitsPerPixel, int width, int height) { GraphicsArray graphicsArray = this.CreateItem(Guid.NewGuid(), GraphicsArrayData.WriteOn1Field.Field.DefaultValue, GraphicsArrayData.OnStartField.Field.DefaultValue, dataBitWidth, bitsPerPixel, width, height, GraphicsArrayData.NoteField.Field.DefaultValue ); this.CreateDevicePins(graphicsArray); return(graphicsArray); }
protected override void Edit(Symbol symbol) { CircuitSymbol circuitSymbol = symbol as CircuitSymbol; if (circuitSymbol != null) { if (this.InEditMode) { LogicalCircuit lc = circuitSymbol.Circuit as LogicalCircuit; if (lc != null) { this.OpenLogicalCircuit(lc); return; } CircuitProbe cp = circuitSymbol.Circuit as CircuitProbe; if (cp != null) { this.Edit(cp); return; } CircuitButton cb = circuitSymbol.Circuit as CircuitButton; if (cb != null) { this.Edit(cb); return; } Constant ct = circuitSymbol.Circuit as Constant; if (ct != null) { this.Edit(ct); return; } Sensor sr = circuitSymbol.Circuit as Sensor; if (sr != null) { this.Edit(sr); return; } Memory m = circuitSymbol.Circuit as Memory; if (m != null) { this.Edit(m); return; } Pin pin = circuitSymbol.Circuit as Pin; if (pin != null) { this.Edit(pin); return; } LedMatrix ledMatrix = circuitSymbol.Circuit as LedMatrix; if (ledMatrix != null) { this.Edit(ledMatrix); return; } Sound sound = circuitSymbol.Circuit as Sound; if (sound != null) { this.Edit(sound); return; } GraphicsArray graphicsArray = circuitSymbol.Circuit as GraphicsArray; if (graphicsArray != null) { this.Edit(graphicsArray); return; } } else if (this.CircuitRunner != null && this.CircuitRunner.VisibleMap != null) { CircuitMap map = this.CircuitRunner.VisibleMap.Child(circuitSymbol); if (map != null) { this.OpenLogicalCircuit(map); return; } if (circuitSymbol.Circuit is CircuitProbe) { FunctionProbe functionProbe = this.CircuitRunner.VisibleMap.FunctionProbe(circuitSymbol); if (functionProbe != null) { this.Mainframe.ShowDialog(new DialogProbeHistory(functionProbe)); } return; } if ((circuitSymbol.Circuit is Memory) || (circuitSymbol.Circuit is GraphicsArray)) { IFunctionMemory functionMemory = this.CircuitRunner.VisibleMap.FunctionMemory(circuitSymbol); if (functionMemory != null) { this.Mainframe.ShowDialog(new DialogMemory(functionMemory)); } return; } if (circuitSymbol.Circuit is Constant) { if (this.CircuitRunner.Root.First() == this.CircuitRunner.VisibleMap) { FunctionConstant functionConstant = this.CircuitRunner.VisibleMap.FunctionConstant(circuitSymbol); if (functionConstant != null) { this.CircuitProject.InOmitTransaction(() => functionConstant.Value++); } } else { this.Mainframe.Status = Properties.Resources.MessageNotRootConstant(this.CircuitRunner.Root.First().Circuit.Name); } } } } else if (this.InEditMode) { TextNote textNote = symbol as TextNote; if (textNote != null) { this.Edit(textNote); } } }
private void Edit(GraphicsArray graphicsArray) { this.Mainframe.ShowDialog(new DialogGraphicsArray(graphicsArray)); }
public static void UpdateWritePinName(GraphicsArray graphicsArray) { graphicsArray.WritePin.Name = Properties.Resources.MemoryWritePinName(graphicsArray.WriteOn1 ? Properties.Resources.WriteOn1 : Properties.Resources.WriteOn0); }
protected override int CircuitSymbolHeight(int defaultHeight) { return(base.CircuitSymbolHeight(Math.Max(3, GraphicsArray.PixelsToGridSize(this.Height * this.Zoom)))); }
protected override int CircuitSymbolWidth(int defaultWidth) { return(base.CircuitSymbolWidth(Math.Max(2, GraphicsArray.PixelsToGridSize(this.Width * this.Zoom)))); }