private void DrawOrGate(Canvas canvas, OrGate orGate) { float x = orGate.X; float y = orGate.Y; bool showPins = orGate.ShowPins; int counter = orGate.Counter; float w = orGate.Width; // element width float h = orGate.Height; // element height SetElementColor(orGate); // draw element shape canvas.DrawLine(x + 0f, y + 0f, x + w, y + 0f, elementPaint); canvas.DrawLine(x + w, y + 0f, x + w, y + h, elementPaint); canvas.DrawLine(x + w, y + h, x + 0f, y + h, elementPaint); canvas.DrawLine(x + 0f, y + h, x + 0f, y + 0f, elementPaint); // draw text in center of element shape string text = "≥" + counter.ToString(); // default counter is 1 float textVerticalOffset = (textElementPaint.Descent() + textElementPaint.Ascent()) / 2f; canvas.DrawText(text, x + w / 2f, y + (h / 2f) - textVerticalOffset, textElementPaint); // draw element pins if (showPins == true) { DrawPins(canvas, orGate.Pins); } }
public OrGate InsertOrGate(float x, float y, bool redraw) { int id = GetNextId(); var orGate = new OrGate(id, x, y, 1); Elements.TryAdd(id, orGate); if (redraw == true) { RedrawCanvas(); } return(orGate); }
public static void Deserialize(string model, ConcurrentDictionary <int, Element> elements) { if (string.IsNullOrEmpty(model)) { return; } string type = null; var lines = model.Split(ModelLineSeparators, StringSplitOptions.RemoveEmptyEntries); foreach (var element in lines) { var args = element.Split(ModelArgSeparators, StringSplitOptions.RemoveEmptyEntries); int length = args.Length; if (length < 2) { continue; } type = args[0]; if (string.Compare(type, "Pin", StringComparison.InvariantCultureIgnoreCase) == 0 && length == 4) { int id = int.Parse(args[1]); float x = float.Parse(args[2]); float y = float.Parse(args[3]); var pin = new Pin(id, null, x, y, 4f, 3f); elements.TryAdd(id, pin); } else if (string.Compare(type, "Wire", StringComparison.InvariantCultureIgnoreCase) == 0 && length == 6) { int id = int.Parse(args[1]); int startParentId = int.Parse(args[2]); int startId = int.Parse(args[3]); int endParentId = int.Parse(args[4]); int endtId = int.Parse(args[5]); var wire = new Wire(id, startParentId, startId, endParentId, endtId); elements.TryAdd(id, wire); } else if (string.Compare(type, "AndGate", StringComparison.InvariantCultureIgnoreCase) == 0 && length == 4) { int id = int.Parse(args[1]); float x = float.Parse(args[2]); float y = float.Parse(args[3]); var andGate = new AndGate(id, x, y); elements.TryAdd(id, andGate); } else if (string.Compare(type, "OrGate", StringComparison.InvariantCultureIgnoreCase) == 0 && length == 4) { int id = int.Parse(args[1]); float x = float.Parse(args[2]); float y = float.Parse(args[3]); var orGate = new OrGate(id, x, y, 1); elements.TryAdd(id, orGate); } } UpdateWireConnections(elements); }