public AndGate InsertAndGate(float x, float y, bool redraw)
        {
            int id      = GetNextId();
            var andGate = new AndGate(id, x, y);

            Elements.TryAdd(id, andGate);

            if (redraw == true)
            {
                RedrawCanvas();
            }

            return(andGate);
        }
        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);
        }