/// <summary>
        /// Merges all connected Terminals of the given connection to this one
        /// </summary>
        /// <param name="graphicConnection">connection to derive connection items from</param>
        internal void Merge(GraphicConnection graphicConnection)
        {
            Connection otherConnection = graphicConnection.LinkedObject as Connection;
            Connection connection      = LinkedObject as Connection;

            foreach (Terminal terminal in otherConnection.Terminals)
            {
                otherConnection.DisconnectTerminal(terminal);
                connection.ConnectTerminal(terminal);
            }
            //clone all nodes of the other connection
            foreach (GraphicBaseElement child in graphicConnection.Children)
            {
                if (child is ConnectionNode)
                {
                    ConnectionNode clone = new ConnectionNode(child.Location);
                    AddChild(clone);
                }
            }
            //clone all lines of the other connection attached to the previously cloned nodes
            foreach (GraphicBaseElement child in graphicConnection.Children)
            {
                if (child is ConnectionLine)
                {
                    ConnectionLine orig = child as ConnectionLine;
                    ConnectionNode node1, node2;
                    //select cloned nodes or terminal nodes
                    if (orig.Nodes[0].Parent is GraphicConnection)
                    {
                        node1 = GetItemAt(orig.Nodes[0].Location, typeof(ConnectionNode)) as ConnectionNode;
                    }
                    else
                    {
                        node1 = orig.Nodes[0];
                    }
                    if (orig.Nodes[1].Parent is GraphicConnection)
                    {
                        node2 = GetItemAt(orig.Nodes[1].Location, typeof(ConnectionNode)) as ConnectionNode;
                    }
                    else
                    {
                        node2 = orig.Nodes[1];
                    }
                    if (node1 != null && node2 != null)
                    {
                        graphicConnection.RemoveChild(child);
                        ConnectionLine clone = new ConnectionLine(node1, node2);
                        AddChild(clone);
                    }
                }
            }
            foreach (GraphicBaseElement child in graphicConnection.Children)
            {
                graphicConnection.RemoveChild(child);
            }
            BuildBody();
        }
        private static GraphicBaseElement CreateElement(string name, BaseElement logic)
        {
            //Terminals
            if (name.Equals(typeof(Terminal).Name))
            {
                GraphicBaseElement element = new GraphicTerminal(logic);
                element.Name = logic.Name;
                return(element);
            }
            //Connections
            if (name.Equals(typeof(Connection).Name))
            {
                GraphicBaseElement element = new GraphicConnection(logic);
                element.Name = logic.Name;
                return(element);
            }
            //Macros
            if (name.Equals(typeof(Macro).Name))
            {
                Macro        macro        = logic as Macro;
                GraphicMacro graphicMacro = new GraphicMacro(logic, MacroCache.Instance.GetSymbol(macro.TypeName));

                return(graphicMacro);
            }
            //Gates
            if (name.Equals(typeof(AndGate).Name) || name.Equals(typeof(NandGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"&", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(OrGate).Name) || name.Equals(typeof(NorGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"≥1", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(BufferGate).Name) || name.Equals(typeof(NotGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"1", new PointF(4, 0));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(XorGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"=m", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            if (name.Equals(typeof(XnorGate).Name))
            {
                GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
                TextElement text             = new TextElement(@"=", new PointF(4, 4));
                io.AddChild(text);
                return(io);
            }
            //if (name.Equals(typeof(Delay).Name))
            //{
            //    GraphicInputOutputElement io = new GraphicInputOutputElement(logic);
            //    TextElement text = new TextElement(@"|-|", new PointF(4, 4));
            //    io.AddChild(text);
            //    return io;
            //}
            //Signals
            if (name.Equals(typeof(Clock).Name))
            {
                Clock clock = (Clock)logic;
                GraphicInputOutputElement graphicClock = new GraphicClock(logic);
                return(graphicClock);
            }
            if (name.Equals(typeof(ConstantInput).Name) || name.Equals(typeof(SignalInput).Name))
            {
                GraphicInputOutputElement sig = new GraphicInput(logic);
                TextElement text = null;
                if (logic is SignalInput)
                {
                    text = new TextElement((logic as SignalInput).SignalName, new PointF(2, 0));
                }
                else
                {
                    text = new TextElement((logic as ConstantInput).State.ToString().Substring(0, 2), new PointF(2, 0));
                }
                if (text != null)
                {
                    sig.AddChild(text);
                }
                return(sig);
            }
            if (name.Equals(typeof(SignalOutput).Name))
            {
                SignalOutput output           = (SignalOutput)logic;
                GraphicInputOutputElement sig = new GraphicOutput(logic);
                TextElement text = new TextElement(output.SignalName, new PointF(2, 0));
                sig.AddChild(text);
                return(sig);
            }
            return(null);
        }