/// <summary>
        /// Получниение Id выделенного элемента
        /// </summary>
        /// <returns></returns>
        public static string GetIdElementSource()
        {
            ElementControl el        = Elements.FirstOrDefault(c => c.IsSelected);
            InOutControl   inControl = InOutControls.FirstOrDefault(c => c.IsSelected);

            return(el != null?el.Element.Id.ToString() : (inControl != null ? inControl.Element.Id.ToString() : null));
        }
        public static InOutControl CreateOutControl(ElementClass element)
        {
            InOutControl control = new InOutControl {
                NameLabel = { Text = element.Name }, Element = element
            };

            Panel.SetZIndex(control, ElementZIndex++);
            control.SetLocation(element.Location);
            InOutControls.Add(control);
            return(control);
        }
        private void AddOutMenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            ElementClass element = new ElementClass()
            {
                InCount = 1, Type = 11, Name = $"Y{SaverClass.Elements.Count(c => c.Type == 11)}"
            };

            SaverClass.Elements.Add(element);
            InOutControl outControl = GraphClass.CreateInControl(element);

            EditorCanvas.Children.Add(outControl);
            UpdateViewOut();
        }
        private void AddInMenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            ElementClass element = new ElementClass()
            {
                InCount = 0, Type = 10, Name = $"X{SaverClass.Elements.Count(c => c.Type == 10)}"
            };

            SaverClass.Elements.Add(element);
            InOutControl inControl = GraphClass.CreateInControl(element);

            inControl.MainGrid.ContextMenu = new ContextMenu();
            inControl.MainGrid.ContextMenu.Items.Add(new MenuItem()
            {
                Header = "_Соединить вход"
            });
            (inControl.MainGrid.ContextMenu.Items[0] as MenuItem).Click += ConntectionMenuItem_Click;
            EditorCanvas.Children.Add(inControl);
            UpdateViewIn();
        }
        /// <summary>
        /// Загрузка схемы
        /// </summary>
        void OpenSchema()
        {
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Title = "Выберите файл", Filter = "json files (*.json)|*.json"
            };

            if (ofd.ShowDialog() == true)
            {
                EditorCanvas.Children.Clear();
                GraphClass.Connections.Clear();
                SaverClass.LoadData(ofd.FileName);
                GraphClass.ElementZIndex    = 10000;
                GraphClass.ConnectionZIndex = 0;
                foreach (ElementClass element in SaverClass.Elements)
                {
                    switch (element.Type)
                    {
                    case 10:
                    {
                        InOutControl inControl = GraphClass.CreateInControl(element);
                        inControl.MainGrid.ContextMenu = new ContextMenu();
                        inControl.MainGrid.ContextMenu.Items.Add(new MenuItem()
                            {
                                Header = "_Соединить вход"
                            });
                        (inControl.MainGrid.ContextMenu.Items[0] as MenuItem).Click += ConntectionMenuItem_Click;
                        EditorCanvas.Children.Add(inControl);
                        continue;
                    }

                    case 11:
                    {
                        EditorCanvas.Children.Add(GraphClass.CreateOutControl(element));
                        foreach (Guid id in element.InElements)
                        {
                            Connection connection = new Connection()
                            {
                                Start  = SaverClass.Elements.First(c => c.Id == id),
                                Finish = element
                            };
                            connection.CalculatePoints();
                            Panel.SetZIndex(connection.Line, GraphClass.ConnectionZIndex++);
                            GraphClass.Connections.Add(connection);
                            EditorCanvas.Children.Add(connection.Line);
                        }
                        continue;
                    }
                    }

                    ElementControl el = GraphClass.CreateElementControl(element, ConntectionMenuItem_Click);
                    el.PreviewMouseMove += El_PreviewMouseMove;
                    EditorCanvas.Children.Add(el);
                    foreach (Guid id in element.InElements)
                    {
                        Connection connection = new Connection()
                        {
                            Start  = SaverClass.Elements.First(c => c.Id == id),
                            Finish = element
                        };
                        connection.CalculatePoints();
                        Panel.SetZIndex(connection.Line, GraphClass.ConnectionZIndex++);
                        GraphClass.Connections.Add(connection);
                        EditorCanvas.Children.Add(connection.Line);
                    }
                }
            }
        }