public Segment Add(DrawingElement el, Position p)
        {
            Remove(p);

            var seg = Segments.FirstOrDefault (s => s.Position == p);
            if (seg != null) {
                seg.AddPrimitives (el.Primitives);
            } else {
                seg = new Segment (p, el.Primitives, this) { IsPalette = IsPalette };
                Segments.Add (seg);
            }
            seg.Type = el.Type;
            CalculateSize ();

            //join latch

            if(el.Primitives.Any(pr => pr is LineElement && ((pr as LineElement).End.Y > 1)))
            {
                var pos2 = new Position (seg.Position.X, seg.Position.Y + 1);
                var seg2 = Segments.FirstOrDefault (s => s.Position == pos2);
                if (seg2 != null)
                {
                    seg2.Join.Add (seg);
                    seg.Join.Add (seg2);

                    var conR = el
                        .Primitives
                        .Where (p1 => p1 is Connector)
                        .Cast<Connector> ()
                        .Where (c => c.Center.Y > 1);

                    seg2.Connectors.AddRange (conR);

                    if (seg.Selected) {
                        seg2.Selected = true;
                    }
                }
            }

            return seg;
        }
        public Segment Add(Position p)
        {
            var seg = Segments.FirstOrDefault (s => s.Position == p);
            if (seg == null) {
                seg = new Segment (p, this) { IsPalette = IsPalette };
                Segments.Add (seg);
                CalculateSize ();
            }

            return seg;
        }