private ConnectionItemData[] ConvertConnectionItems(Connection connection)
        {
            GraphicConnection         graphicConnection = connection.LinkedObject as GraphicConnection;
            List <ConnectionItemData> itemdatalist      = new List <ConnectionItemData>(graphicConnection.Children.Count);

            foreach (IConnectionItem item in graphicConnection.Children)
            {
                if (item is ConnectionLine)
                {
                    ConnectionLine line     = item as ConnectionLine;
                    LineItemData   linedata = new LineItemData(line.Nodes[0].Name, line.Nodes[1].Name);
                    itemdatalist.Add(linedata);
                }
                if (item is ConnectionNode)
                {
                    ConnectionNode node = item as ConnectionNode;
                    //if (node.Parent is GraphicTerminal) //impossible
                    //{
                    //    NodeItemData nodedata = new NodeItemData(node.Name);
                    //    nodedata.IsTerminalNode = true; //not needed
                    //    itemdatalist.Add(nodedata);
                    //} else
                    if (node.Parent is GraphicConnection)
                    {
                        NodeItemData nodedata = new NodeItemData(node.Name);
                        //nodedata.IsTerminalNode = false; //not needed
                        nodedata.X = node.Location.X;
                        nodedata.Y = node.Location.Y;
                        itemdatalist.Add(nodedata);
                    }
                }
            }

            return(itemdatalist.ToArray());
        }
        private void CreateConnectionLines(Circuit circuit, GraphicConnection graphicConnection, ConnectionData connectionData)
        {
            if (connectionData.Items == null || connectionData.Items.Length == 0)
            {
                //downward compatibility - no detailed information available:
                Connection      connection = graphicConnection.LinkedObject as Connection;
                GraphicTerminal previous   = null;
                //displays straight lines from one terminal to another
                foreach (Terminal terminal in connection.Terminals)
                {
                    GraphicTerminal graphicTerminal = terminal.LinkedObject as GraphicTerminal;
                    if (previous != null)
                    {
                        graphicConnection.AddChild(new ConnectionLine(previous.ConnectionNode, graphicTerminal.ConnectionNode));
                    }
                    previous = graphicTerminal;
                }
                return;
            }
            //create nodes
            foreach (ConnectionItemData itemData in connectionData.Items)
            {
                if (itemData is NodeItemData)
                {
                    NodeItemData   nodeData = itemData as NodeItemData;
                    ConnectionNode node     = new ConnectionNode(nodeData.X, nodeData.Y);
                    graphicConnection.AddChild(node);
                }
            }
            //create lines
            foreach (ConnectionItemData itemData in connectionData.Items)
            {
                if (itemData is LineItemData)
                {
                    LineItemData lineData = itemData as LineItemData;

                    ConnectionNode node1 = SearchNode(lineData.Node1, circuit, graphicConnection);
                    ConnectionNode node2 = SearchNode(lineData.Node2, circuit, graphicConnection);

                    if (node1 != null && node2 != null)
                    {
                        ConnectionLine line = new ConnectionLine(node1, node2);
                        graphicConnection.AddChild(line);
                    }
                }
            }
        }