public MemoryEditorRow(IFunctionMemory memory, int rowIndex, string rowIndexFormat, string cellFormat)
 {
     this.memory         = memory;
     this.rowIndex       = rowIndex;
     this.rowIndexFormat = rowIndexFormat;
     this.cellFormat     = cellFormat;
 }
Beispiel #2
0
 private void ButtonLoadClick(object sender, RoutedEventArgs e)
 {
     try {
         OpenFileDialog dialog = new OpenFileDialog {
             InitialDirectory = Mainframe.IsDirectoryPathValid(this.openFileFolder.Value) ? this.openFileFolder.Value : Mainframe.DefaultProjectFolder()
         };
         bool?result = dialog.ShowDialog(this);
         if (result.HasValue && result.Value)
         {
             this.openFileFolder.Value = Path.GetDirectoryName(dialog.FileName);
             int    addressBitWidth = this.AddressBitWidth;
             int    dataBitWidth    = this.DataBitWidth;
             byte[] buffer          = new byte[Memory.BytesPerCellFor(dataBitWidth)];
             int    cellCount       = Memory.NumberCellsFor(addressBitWidth);
             Tracer.Assert(cellCount * buffer.Length == this.data.Length);
             using (FileStream stream = File.Open(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                 for (int i = 0; i < cellCount; i++)
                 {
                     int readed = stream.Read(buffer, 0, buffer.Length);
                     if (readed <= 0)
                     {
                         Array.Clear(this.data, i * buffer.Length, this.data.Length - i * buffer.Length);
                         break;
                     }
                     int value = Memory.CellValue(buffer, Math.Min(8 * readed, dataBitWidth), 0);
                     Memory.SetCellValue(this.data, dataBitWidth, i, value);
                 }
             }
             this.FunctionMemory = new MemoryEditor(this.data, addressBitWidth, dataBitWidth);
         }
     } catch (Exception exception) {
         App.Mainframe.ReportException(exception);
     }
 }
		protected DialogMemoryEditor(Memory memory) {
			string typeName = this.GetType().Name;
			this.openFileFolder = new SettingsStringCache(Settings.User, typeName + ".OpenFile.Folder", Mainframe.DefaultProjectFolder());
			this.DataHeight = new SettingsGridLengthCache(Settings.User, typeName + ".Data.Height", memory.Writable ? "0.25*" : "0.75*");
			this.NoteHeight = new SettingsGridLengthCache(Settings.User, typeName + ".Note.Height", memory.Writable ? "0.75*" : "0.25*");

			this.Memory = memory;
			this.data = memory.MemoryValue();

			this.DataContext = this;
			this.InitializeComponent();

			this.addressBitWidth.ItemsSource = MemoryDescriptor.AddressBitWidthRange;
			this.dataBitWidth.ItemsSource = PinDescriptor.BitWidthRange;
			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.addressBitWidth.SelectedItem = this.currentAddressBitWidth = this.Memory.AddressBitWidth;
			this.dataBitWidth.SelectedItem = this.currentDataBitWidth = this.Memory.DataBitWidth;
			this.writeOn.SelectedItem = writeOnList.First(d => d.Value == this.Memory.WriteOn1);
			this.onStart.SelectedItem = onStartList.First(d => d.Value == (this.Memory.Writable ? this.Memory.OnStart : MemoryOnStart.Data));
			this.note.Text = this.Memory.Note;

			this.FunctionMemory = new MemoryEditor(this.data, this.Memory.AddressBitWidth, this.DataBitWidth);

			this.initialized = true;
		}
		private void MemorySizeChanged(object sender, SelectionChangedEventArgs e) {
			try {
				if(this.initialized) {
					this.FunctionMemory = new MemoryEditor(this.Memory.MemoryValue(), this.Memory.AddressBitWidth, this.DataBitWidth);

					int newAddressBitWidth = this.AddressBitWidth;
					int newDataBitWidth = this.DataBitWidth;
					if(this.currentAddressBitWidth != newAddressBitWidth || this.currentDataBitWidth != newDataBitWidth) {
						this.data = Memory.Reallocate(this.data, this.currentAddressBitWidth, this.currentDataBitWidth, newAddressBitWidth, newDataBitWidth);
						this.currentAddressBitWidth = newAddressBitWidth;
						this.currentDataBitWidth = newDataBitWidth;
						this.FunctionMemory = new MemoryEditor(this.data, newAddressBitWidth, newDataBitWidth);
					}
				}
			} catch(Exception exception) {
				App.Mainframe.ReportException(exception);
			}
		}
        private List <MemoryEditorRow> RowList()
        {
            IFunctionMemory functionMemory = this.FunctionMemory;
            int             cells          = Memory.NumberCellsFor(functionMemory.AddressBitWidth);
            int             rows           = cells / 16 + (((cells % 16) == 0) ? 0 : 1);
            string          format         = "{{0:X{0}}}";
            string          rowIndexFormat = string.Format(CultureInfo.InvariantCulture, format,
                                                           Math.Max(1, ControlMemoryEditor.HexDigits(functionMemory.AddressBitWidth) - 1)
                                                           );
            string cellFormat = string.Format(CultureInfo.InvariantCulture, format, ControlMemoryEditor.HexDigits(functionMemory.DataBitWidth));

            List <MemoryEditorRow> list = new List <MemoryEditorRow>(rows);

            for (int i = 0; i < rows; i++)
            {
                list.Add(new MemoryEditorRow(functionMemory, i, rowIndexFormat, cellFormat));
            }

            return(list);
        }
Beispiel #6
0
        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);
                }
            }
        }
 public DialogMemory(IFunctionMemory functionMemory)
 {
     this.FunctionMemory = functionMemory;
     this.DataContext    = this;
     this.InitializeComponent();
 }