// Creates Sensor wrapper private Sensor CreateItem( // Fields of Sensor table Guid SensorId, SensorType SensorType, int BitWidth, PinSide PinSide, string Notation, string Data, string Note // Fields of Circuit table ) { TableSnapshot <CircuitData> tableCircuit = (TableSnapshot <CircuitData>) this.CircuitProject.Table("Circuit"); CircuitData dataCircuit = new CircuitData() { CircuitId = SensorId }; RowId rowIdCircuit = tableCircuit.Insert(ref dataCircuit); SensorData dataSensor = new SensorData() { SensorId = SensorId, SensorType = SensorType, BitWidth = BitWidth, PinSide = PinSide, Notation = Notation, Data = Data, Note = Note, }; return(this.Create(this.Table.Insert(ref dataSensor), rowIdCircuit)); }
public Constant Create(int bitWidth, int value, PinSide pinSide) { Constant constant = this.CreateItem(Guid.NewGuid(), bitWidth, Constant.Normalize(value, bitWidth), pinSide, ConstantData.NoteField.Field.DefaultValue); this.CreateDevicePin(constant); return(constant); }
public Sound Create(PinSide pinSide, string notation) { Sound sound = this.CreateItem(Guid.NewGuid(), pinSide, notation, SoundData.NoteField.Field.DefaultValue); this.CreateDevicePin(sound); return(sound); }
// Creates Constant wrapper private Constant CreateItem( // Fields of Constant table Guid ConstantId, int BitWidth, int Value, PinSide PinSide, string Note // Fields of Circuit table ) { TableSnapshot <CircuitData> tableCircuit = (TableSnapshot <CircuitData>) this.CircuitProject.Table("Circuit"); CircuitData dataCircuit = new CircuitData() { CircuitId = ConstantId }; RowId rowIdCircuit = tableCircuit.Insert(ref dataCircuit); ConstantData dataConstant = new ConstantData() { ConstantId = ConstantId, BitWidth = BitWidth, Value = Value, PinSide = PinSide, Note = Note, }; return(this.Create(this.Table.Insert(ref dataConstant), rowIdCircuit)); }
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); }
// Creates Sound wrapper private Sound CreateItem( // Fields of Sound table Guid SoundId, PinSide PinSide, string Notation, string Note // Fields of Circuit table ) { TableSnapshot <CircuitData> tableCircuit = (TableSnapshot <CircuitData>) this.CircuitProject.Table("Circuit"); CircuitData dataCircuit = new CircuitData() { CircuitId = SoundId }; RowId rowIdCircuit = tableCircuit.Insert(ref dataCircuit); SoundData dataSound = new SoundData() { SoundId = SoundId, PinSide = PinSide, Notation = Notation, Note = Note, }; return(this.Create(this.Table.Insert(ref dataSound), rowIdCircuit)); }
// Creates CircuitButton wrapper private CircuitButton CreateItem( // Fields of CircuitButton table Guid CircuitButtonId, string Notation, bool IsToggle, PinSide PinSide, bool Inverted, int Width, int Height, string Note // Fields of Circuit table ) { TableSnapshot <CircuitData> tableCircuit = (TableSnapshot <CircuitData>) this.CircuitProject.Table("Circuit"); CircuitData dataCircuit = new CircuitData() { CircuitId = CircuitButtonId }; RowId rowIdCircuit = tableCircuit.Insert(ref dataCircuit); CircuitButtonData dataCircuitButton = new CircuitButtonData() { CircuitButtonId = CircuitButtonId, Notation = Notation, IsToggle = IsToggle, PinSide = PinSide, Inverted = Inverted, Width = Width, Height = Height, Note = Note, }; return(this.Create(this.Table.Insert(ref dataCircuitButton), rowIdCircuit)); }
private void ButtonOkClick(object sender, RoutedEventArgs e) { try { string name = this.name.Text.Trim(); string note = this.note.Text.Trim(); PinSide pinSide = ((EnumDescriptor <PinSide>) this.side.SelectedItem).Value; bool isInverted = this.inverted.IsChecked.HasValue && this.inverted.IsChecked.Value; if (this.button.Notation != name || this.button.IsToggle != this.isToggle.IsChecked || this.button.PinSide != pinSide || this.button.Inverted != isInverted || this.button.Note != note ) { this.button.CircuitProject.InTransaction(() => { this.button.Notation = name; this.button.IsToggle = this.isToggle.IsChecked.Value; this.button.PinSide = pinSide; this.button.Inverted = isInverted; this.button.Note = note; this.button.Pins.First().PinSide = pinSide; }); } this.Close(); } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
private void ButtonOkClick(object sender, RoutedEventArgs e) { try { string name = this.name.Text.Trim(); string notation = this.notation.Text.Trim(); string note = this.note.Text.Trim(); PinSide pinSide = ((EnumDescriptor <PinSide>) this.side.SelectedItem).Value; bool inverted = this.inverted.IsChecked.Value; int bitWidth = (int)this.bitWidth.SelectedItem; if (this.pin.Name != name || this.pin.JamNotation != notation || this.pin.Note != note || this.pin.PinSide != pinSide || this.pin.Inverted != inverted || this.pin.BitWidth != bitWidth ) { this.pin.CircuitProject.InTransaction(() => { this.pin.Rename(name); this.pin.JamNotation = notation; this.pin.Note = note; this.pin.PinSide = pinSide; this.pin.Inverted = inverted; this.pin.BitWidth = bitWidth; }); } this.Close(); } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
private void ButtonOkClick(object sender, RoutedEventArgs e) { try { PinSide pinSide = ((EnumDescriptor <PinSide>) this.side.SelectedItem).Value; string notation = this.notation.Text.Trim(); string note = this.note.Text.Trim(); if (this.sound.PinSide != pinSide || this.sound.Notation != notation || this.sound.Note != note ) { this.sound.CircuitProject.InTransaction(() => { this.sound.PinSide = pinSide; this.sound.Notation = notation; this.sound.Note = note; this.sound.Pins.First().PinSide = pinSide; }); } this.Close(); } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
public Pin GetPin(PinSide side, byte pin_index) { if (GetNumberOfPins(side) <= pin_index) { throw new PinIndexOutOfRangeException("Wrong pin index"); } return(GetPinsBySide(side)[pin_index]); }
public PinSide Side = PinSide.Right; //Right is the default for the CircuitButton, and the implied side unless specified otherwise. public Constant(XmlNode node) { XmlNodeList children = node.ChildNodes; foreach (XmlNode child in children) { switch (child.Name) { case "lc:ConstantId": Id = child.InnerText; break; case "lc:CircuitId": ParentId = child.InnerText; break; case "lc:BitWidth": BitWidth = int.Parse(child.InnerText); break; case "lc:Value": Value = int.Parse(child.InnerText); break; case "lc:PinSide": if (child.InnerText == "Left") { Side = PinSide.Left; } else if (child.InnerText == "Top") { Side = PinSide.Top; } else if (child.InnerText == "Right") { Side = PinSide.Right; } else if (child.InnerText == "Bottom") { Side = PinSide.Bottom; } else { throw new Exception("Constant Constructor: An invalid PinSide element has been detected in the save file, please check your project and try again!"); } break; default: Console.WriteLine("Constant Constructor: Unknown Element Type -- Ignoring"); break; } } if (Id == null) { throw new Exception("Constant Constructor: An invalid Constant element has been detected in the save file, please check your project and try again!"); } }
public CircuitButton Create(string notation, bool isToggle, PinSide pinSide) { CircuitButton button = this.CreateItem(Guid.NewGuid(), notation, isToggle, pinSide, CircuitButtonData.WidthField.Field.DefaultValue, CircuitButtonData.HeightField.Field.DefaultValue, CircuitButtonData.NoteField.Field.DefaultValue ); this.CreateDevicePin(button); return(button); }
public DevicePin Create(Circuit circuit, PinType pinType, int bitWidth) { PinSide pinSide = BasePin.DefaultSide((circuit is Pin circuitPin) ? (circuitPin.PinType == PinType.Input ? PinType.Output : PinType.Input) : pinType); DevicePin pin = this.CreateItem(Guid.NewGuid(), circuit, bitWidth, pinType, pinSide, false, this.UniqueName(BasePin.DefaultName(pinType), circuit), DevicePinData.NoteField.Field.DefaultValue, DevicePinData.JamNotationField.Field.DefaultValue ); pin.Order = this.order++; return(pin); }
public List <Pin> GetPinsBySide(PinSide side) { switch (side) { case PinSide.INPUT: return(input_pins); case PinSide.OUTPUT: return(output_pins); default: throw new InvalidPinSideException(); } }
private Point GetShift(PinSide side, int index) { if (side == PinSide.INPUT) { return(Parent.ImageData.InputPoints[index]); } else if (side == PinSide.OUTPUT) { return(Parent.ImageData.OutputPoints[index]); } else { throw new InvalidPinSideException(); } }
public PinSide SourcePinSide = PinSide.Right;//Right is the default for the SourcePinSide, and the implied side unless specified otherwise. public Splitter(XmlNode node) { XmlNodeList children = node.ChildNodes; foreach (XmlNode child in children) { switch (child.Name) { case "lc:SplitterId": Id = child.InnerText; break; case "lc:CircuitId": ParentId = child.InnerText; break; case "lc:BitWidth": BitWidth = int.Parse(child.InnerText); break; case "lc:Clockwise": if (child.InnerText == "True") { SourcePinSide = PinSide.Left; } else { SourcePinSide = PinSide.Right; } break; default: Console.WriteLine("Splitter Constructor: Unknown Element Type -- Ignoring"); break; } } if (Id == null) { throw new Exception("Splitter Constructor: An invalid Splitter element has been detected in the save file, please check your project and try again!"); } }
private void ButtonOkClick(object sender, RoutedEventArgs e) { try { int bitWidth = (int)this.bitWidth.SelectedItem; int value = Constant.Normalize(int.Parse(this.value.Text.Trim(), NumberStyles.HexNumber, CultureInfo.InvariantCulture), bitWidth); PinSide pinSide = ((EnumDescriptor <PinSide>) this.side.SelectedItem).Value; string note = this.note.Text.Trim(); if (this.constant.BitWidth != bitWidth || this.constant.ConstantValue != value || this.constant.PinSide != pinSide || this.constant.Note != note) { this.constant.CircuitProject.InTransaction(() => { this.constant.BitWidth = bitWidth; this.constant.ConstantValue = value; this.constant.PinSide = pinSide; this.constant.Note = note; this.constant.Pins.First().PinSide = pinSide; }); } this.Close(); } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
// Creates DevicePin wrapper private DevicePin CreateItem( // Fields of DevicePin table Guid PinId, Circuit Circuit, int BitWidth, PinType PinType, PinSide PinSide, bool Inverted, string Name, string Note, string JamNotation // Fields of Circuit table ) { TableSnapshot <CircuitData> tableCircuit = (TableSnapshot <CircuitData>) this.CircuitProject.Table("Circuit"); CircuitData dataCircuit = new CircuitData() { CircuitId = PinId }; RowId rowIdCircuit = tableCircuit.Insert(ref dataCircuit); DevicePinData dataDevicePin = new DevicePinData() { PinId = PinId, CircuitId = (Circuit != null) ? Circuit.CircuitId : DevicePinData.CircuitIdField.Field.DefaultValue, BitWidth = BitWidth, PinType = PinType, PinSide = PinSide, Inverted = Inverted, Name = Name, Note = Note, JamNotation = JamNotation, }; return(this.Create(this.Table.Insert(ref dataDevicePin), rowIdCircuit)); }
public Pin(PinSide side) { Side = side; State = new Logic(LogicValue.UNINITIALIZED); connected_pin = null; }
public static EnumDescriptor <PinSide> PinSideDescriptor(PinSide pinSide) { Tracer.Assert(EnumHelper.IsValid(pinSide)); return(PinDescriptor.PinSideRange.First(d => d.Value == pinSide)); }
private void ButtonOkClick(object sender, RoutedEventArgs e) { // All the logic of this method assumes that validation prevents this been called if there is an incorrect user input. try { int bitWidth = (int)this.bitWidth.SelectedItem; PinSide pinSide = ((EnumDescriptor <PinSide>) this.side.SelectedItem).Value; string notation = this.notation.Text.Trim(); string note = this.note.Text.Trim(); string data = this.SeriesData.Trim(); string minText = this.RandomMin.Trim(); string maxText = this.RandomMax.Trim(); string initial = this.ManualInitialValue.Trim(); SensorType type = this.SelectedSensorType.Value; if (type == SensorType.Series && string.IsNullOrWhiteSpace(data)) { data = Sensor.DefaultSeriesData; } if (type == SensorType.Series && this.IsLoop) { type = SensorType.Loop; } else if (type == SensorType.Random) { if (int.TryParse(minText, NumberStyles.Integer, Properties.Resources.Culture, out int min) && int.TryParse(maxText, NumberStyles.Integer, Properties.Resources.Culture, out int max) && 0 < min && min <= max ) { data = Sensor.SaveSeries(new List <SensorPoint>() { new SensorPoint(min, max) }); } else { data = Sensor.DefaultRandomData; } } else if (type == SensorType.Manual) { int value; if (!int.TryParse(initial, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value)) { value = 0; } data = Constant.Normalize(value, bitWidth).ToString("X", CultureInfo.InvariantCulture); } if (this.sensor.SensorType != type || this.sensor.BitWidth != bitWidth || this.sensor.PinSide != pinSide || this.sensor.Notation != notation || this.sensor.Note != note || this.sensor.Data != data ) { this.sensor.CircuitProject.InTransaction(() => { this.sensor.SensorType = type; this.sensor.BitWidth = bitWidth; this.sensor.PinSide = pinSide; this.sensor.Notation = notation; this.sensor.Note = note; this.sensor.Data = data; this.sensor.Pins.First().PinSide = pinSide; }); } this.Close(); } catch (Exception exception) { App.Mainframe.ReportException(exception); } }
public Pin(XmlNode node) { bool sideSet = false; XmlNodeList children = node.ChildNodes; foreach (XmlNode child in children) { switch (child.Name) { case "lc:PinId": Id = child.InnerText; break; case "lc:CircuitId": ParentId = child.InnerText; break; case "lc:PinType": if (child.InnerText == "Output") { if (!sideSet) { Side = PinSide.Right; } Type = PinType.Output; } else { if (!sideSet) { Side = PinSide.Left; } Type = PinType.Input; } break; case "lc:PinSide": sideSet = true; if (child.InnerText == "Left") { Side = PinSide.Left; } else if (child.InnerText == "Top") { Side = PinSide.Top; } else if (child.InnerText == "Right") { Side = PinSide.Right; } else if (child.InnerText == "Bottom") { Side = PinSide.Bottom; } else { throw new Exception("Pin Constructor: An invalid PinSide element has been detected in the save file, please check your project and try again!"); } break; case "lc:Name": Name = child.InnerText; break; default: Console.WriteLine("Pin Constructor: Unknown Element Type -- Ignoring"); break; } } if (Type == PinType.Invalid) { Type = PinType.Input; } if (Name == null || Id == null) { throw new Exception("Pin Constructor: An invalid Pin element has been detected in the save file, please check your project and try again!"); } }
public byte GetNumberOfPins(PinSide side) { return((byte)(GetPinsBySide(side).Count)); }
public Pin(Visual.Element parent, PinSide side, int index) { Parent = parent; Side = side; Index = index; }
private Dictionary <string, string> FindConnectedGroups(PinSide side, CircuitPinOffset offset, List <WireGroup> groups) { List <Pin> pins = new List <Pin>(); foreach (var circuitBase in circuits) { if (circuitBase.GetType() == typeof(Pin)) { Pin pin = (Pin)circuitBase; if (pin.Side == side) { pins.Add(pin); } } } List <Pin> sortedPins = new List <Pin>(); sortedPins.Add(pins[0]); bool foundLocation = false; if (pins.Count > 1) { for (int i = 1; i < pins.Count; i++) { foundLocation = false; for (int j = 0; j < sortedPins.Count; j++) { if (pins[i].Symbol.Location.y < sortedPins[j].Symbol.Location.y) { sortedPins.Insert(j, pins[i]); foundLocation = true; break; } else if (pins[i].Symbol.Location.y == sortedPins[j].Symbol.Location.y) { if (pins[i].Symbol.Location.x < sortedPins[j].Symbol.Location.x) { sortedPins.Insert(j, pins[i]); foundLocation = true; break; } } } if (!foundLocation) { sortedPins.Add(pins[i]); } } } Dictionary <string, string> returnDictionary = new Dictionary <string, string>(); for (int i = 0; i < sortedPins.Count; i++) { Coords current = new Coords(Symbol.Location); if (side == PinSide.Left || side == PinSide.Right) { current.x = current.x + offset.OffsetX; current.y = current.y + offset.OffsetY + (i * offset.SplitSpace); } else { current.x = current.x + offset.OffsetX + (i * offset.SplitSpace); current.y = current.y + offset.OffsetY; } foreach (var group in groups) { if (group.coords.Exists(x => x.x == current.x && x.y == current.y)) { returnDictionary.Add(sortedPins[i].Name, group.inputList[0]); } } } if (returnDictionary.Count != sortedPins.Count) { throw new Exception("Gate -- FindConnectedGroups: Unable to match a wire group to each input!"); } return(returnDictionary); }
public CircuitPinOffset OffsetCalculator(PinSide type) { int left = 0, top = 0, right = 0, bottom = 0; foreach (var circuitBase in circuits) { if (circuitBase.GetType() == typeof(Pin)) { Pin pin = (Pin)circuitBase; switch (pin.Side) { case PinSide.Left: left++; break; case PinSide.Top: top++; break; case PinSide.Right: right++; break; case PinSide.Bottom: bottom++; break; } } } CircuitPinOffset offset = new CircuitPinOffset(); switch (type) { case PinSide.Left: offset.OffsetX = 0; if (left == 1) { if (right <= 3) { offset.OffsetY = 2; } else { if (right % 2 != 0) { offset.OffsetY = right / 2; } else { offset.OffsetY = (right / 2) + 1; } } } else { offset.OffsetY = 1; if (right <= 1) { offset.SplitSpace = 1; } else { int spacesize = left - 1; int calc = right - left; if (calc <= 0) { offset.SplitSpace = 0; } else { offset.SplitSpace = calc / spacesize; } } } break; case PinSide.Top: offset.OffsetY = 0; if (top == 1) { if (bottom % 2 != 0) { offset.OffsetX = bottom / 2; } else { offset.OffsetX = (bottom / 2) + 1; } } else { offset.OffsetY = 1; if (bottom <= 1) { offset.SplitSpace = 0; } else { int spacesize = top - 1; int calc = bottom - top; if (calc <= 0) { offset.SplitSpace = 0; } else { offset.SplitSpace = calc / spacesize; } } } break; case PinSide.Right: offset.OffsetX = Math.Max(Math.Max(top, bottom) + 1, 3); if (right == 1) { if (left <= 3) { offset.OffsetY = 2; } else { if (left % 2 != 0) { offset.OffsetY = left / 2; } else { offset.OffsetY = (left / 2) + 1; } } } else { offset.OffsetY = 1; if (left <= 1) { offset.SplitSpace = 1; } else { int spacesize = left - 1; int calc = left - right; if (calc <= 0) { offset.SplitSpace = 0; } else { offset.SplitSpace = calc / spacesize; } } } break; case PinSide.Bottom: offset.OffsetY = Math.Max(Math.Max(left, right) + 1, 4); if (top == 1) { if (bottom % 2 != 0) { offset.OffsetX = bottom / 2; } else { offset.OffsetX = (bottom / 2) + 1; } } else { offset.OffsetY = 1; if (bottom <= 1) { offset.SplitSpace = 0; } else { int spacesize = top - 1; int calc = bottom - top; if (calc <= 0) { offset.SplitSpace = 0; } else { offset.SplitSpace = calc / spacesize; } } } break; } return(offset); }