public static CircuitTester CreateTester(string circuitName) { if (string.IsNullOrEmpty(circuitName)) { throw new ArgumentNullException(nameof(circuitName)); } Editor editor = App.Editor; if (editor == null) { throw new InvalidOperationException("Editor was not created yet"); } LogicalCircuit circuit = editor.CircuitProject.LogicalCircuitSet.FindByName(circuitName); if (circuit == null) { throw new CircuitException(Cause.UserError, string.Format(CultureInfo.InvariantCulture, "Logical Circuit {0} not found", circuitName)); } if (!CircuitTestSocket.IsTestable(circuit)) { throw new CircuitException(Cause.UserError, string.Format(CultureInfo.InvariantCulture, "Logical Circuit {0} is not testable. There are no any input or/and output pins on it.", circuitName) ); } return(new CircuitTester(editor, circuit)); }
public CircuitTestSocket(LogicalCircuit circuit, bool multithreaded) { Tracer.Assert(CircuitTestSocket.IsTestable(circuit)); TableChank.Validate(circuit); this.chank = new TableChank(circuit); if (multithreaded && 1 < Environment.ProcessorCount && 15 < this.chank.InputBitCount) { this.chankList = new TableChank[Environment.ProcessorCount]; BigInteger total = this.chank.Count; BigInteger count = total / this.chankList.Length; for (int i = 0; i < this.chankList.Length; i++) { if (i == 0) { this.chankList[i] = this.chank; } else { this.chankList[i] = new TableChank(circuit); } this.chankList[i].Count = count; this.chankList[i].Start = count * i; } this.chankList[this.chankList.Length - 1].Count += total % this.chankList.Length; } }
public DialogTruthTable(LogicalCircuit logicalCircuit) { this.InvertFilter = true; this.testSocket = new CircuitTestSocket(logicalCircuit); int inputBits = this.testSocket.Inputs.Sum(p => p.Pin.BitWidth); if (0 < inputBits) { this.TotalRows = BigInteger.One << inputBits; } else { this.TotalRows = 0; this.TruthTable = new ListCollectionView(new List <TruthState>()); } this.BuildTruthTable(); this.DataContext = this; this.InitializeComponent(); Dictionary <DataGridTextColumn, Func <TruthState, int> > dataAccessor = new Dictionary <DataGridTextColumn, Func <TruthState, int> >(); void addColumn(Pin pin, string path, int i) { DataGridTextColumn column = new DataGridTextColumn(); column.Header = pin.Name.Replace("_", "__"); column.Binding = new Binding(path); if (pin.PinType == PinType.Input) { column.Binding.StringFormat = "{0:X}"; } Style style = new Style(typeof(DataGridColumnHeader)); style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, pin.ToolTip)); column.HeaderStyle = style; this.dataGrid.Columns.Add(column); dataAccessor.Add(column, DialogTruthTable.InputFieldAccesor(i)); } int index = 0; foreach (InputPinSocket socket in this.testSocket.Inputs) { addColumn(socket.Pin, "Input[" + index + "]", index); index++; } index = 0; foreach (OutputPinSocket socket in this.testSocket.Outputs) { addColumn(socket.Pin, "[" + index + "]", index); index++; } this.sortComparer = new TruthStateComparer(dataAccessor); this.dataGrid.Sorting += new DataGridSortingEventHandler(this.DataGridSorting); DataObject.AddPastingHandler(this.filter, this.OnFilterPaste); }
internal CircuitTester(Editor editor, LogicalCircuit circuit) { Tracer.Assert(editor != null); Tracer.Assert(circuit != null); Tracer.Assert(circuit.CircuitProject == editor.CircuitProject); Tracer.Assert(CircuitTestSocket.IsTestable(circuit)); this.originalEditor = new WeakReference <Editor>(editor); this.originalVersion = editor.CircuitProject.Version; this.logicalCircuitName = circuit.Name; this.socket = new CircuitTestSocket(circuit, false); }
public ExpressionParser(CircuitTestSocket socket) { this.socket = socket; }