Пример #1
0
 public Connection(Node sourceNode, Node sinkNode)
 {
     SourceNode = sourceNode;
     SinkNode = sinkNode;
     UpdatePathGeometry();
     //LayoutUpdated += OnLayoutUpdated;
     Loaded += OnLoaded;
     SourceNode.PositionPropertyChanged += PositionPropertyChanged;
     SinkNode.PositionPropertyChanged += PositionPropertyChanged;
 }
Пример #2
0
 //private void BruteForce()
 //{
 //}
 public void DFS(Node node, List<Node> list)
 {
     if (!node.Children.Any())
     {
         ChainsList.Add(new List<Node>(list));
         list.Remove(node);
         return;
     }
     foreach (var child in node.Children)
     {
         list.Add(child);
         DFS(child, list);
     }
     list.Remove(node);
 }
Пример #3
0
        private void OkButtonOnClick(object sender, RoutedEventArgs routedEventArgs)
        {
            var canvas = VisualTreeHelper.GetParent(this) as GraphCanvas;
            var nodeName = GetTemplateChild("PART_NodeName") as TextBox;
            if (canvas != null)
            {
                if (canvas.NodeService.SourceNode != null)
                {
                    if (_newExcelPath != null)
                    {
                        canvas.NodeService.SourceNode.ExcelPath = _newExcelPath;
                    }
                    if (nodeName != null) canvas.NodeService.SourceNode.NodeName = nodeName.Text;
                    AddButton.Visibility = Visibility.Visible;
                    OkButton.Visibility = Visibility.Hidden;
                    ExcelButton.Visibility = Visibility.Hidden;
                    if (nodeName != null) nodeName.Visibility = Visibility.Hidden;
                    Height -= 50;
                    return;
                }
            }

            if (_newExcelPath == null)
            {
                MessageBox.Show("Не указана таблица Excel", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            NodesCount++;
            Node node = new Node(Id);
            Canvas.SetTop(node, (NodesCount - 1) * 50 + 50 * NodesCount);
            double groupLeft = Canvas.GetLeft(this);
            Canvas.SetLeft(node, groupLeft + 25);
            if (nodeName != null) node.NodeName = nodeName.Text;
            if (!string.IsNullOrEmpty(_newExcelPath))
            {
                node.ExcelPath = _newExcelPath;
                _newExcelPath = null;
            }
            node.SelectionPropertyChanged += NodeOnSelectionPropertyChanged;
            Height += 100;
            if (canvas != null)
            {
                canvas.Children.Add(node);
            }
            Height -= 120;
            AddButton.Visibility = Visibility.Visible;
            OkButton.Visibility = Visibility.Hidden;
            ExcelButton.Visibility = Visibility.Hidden;
            if (nodeName != null) nodeName.Visibility = Visibility.Hidden;
        }
Пример #4
0
        private void GenerateChainButton_Click(object sender, RoutedEventArgs e)
        {
            ChainsList.Clear();
            ResultChains.Clear();
            ChainList.Items.Clear();

            int groupsCount = GraphCanvas.Children.OfType<Group>().Count();
            int i = 0;
            if (!Nodes.Any())
            {
                Node parentNode = new Node(0);
                parentNode.Id = i;
                Nodes.Add(parentNode);
                foreach (var node in GraphCanvas.Children.OfType<Node>())
                {
                    i++;
                    node.Id = i;
                    Nodes.Add(node);
                    if (node.GroupId == 1)
                    {
                        Nodes[0].Children.Add(node);
                    }
                }
            }

            DFS(Nodes[0], new List<Node>());

            #if DEBUG
            string str = "";
            #endif
            foreach (var list in ChainsList)
            {
                if (list.Count == groupsCount)
                {
                    ResultChains.Add(new List<Node>(list));
            #if DEBUG
                    foreach (var node in list)
                    {
                        str += node.Id;
                    }
                    ChainList.Items.Add(str);
                    str = "";
            #endif
                }
            }
            #if DEBUG
            ChainList.Visibility = Visibility.Visible;
            #endif
            ChainList.Items.Clear();
            OptimisationService optimisationService = new OptimisationService();
            Dictionary<string, int>[] dictionaries = new Dictionary<string, int>[GraphCanvas.GroupsCount];
            foreach (var chain in ResultChains)
            {
                for (int j = 0; j < GraphCanvas.GroupsCount; j++)
                {
                    dictionaries[j] = chain[j].OptimisationParams;
                }
                optimisationService.BruteForce(dictionaries);
            }

            List<KeyValuePair<string, int>> result = optimisationService.GetResult();

            foreach (var res in result)
            {
                ChainList.Items.Add(res.Key);
            }
        }
Пример #5
0
        public void ClearSelection()
        {
            if (SelectedConnection != null)
            {
                Panel.SetZIndex(SelectedConnection, 0);
                SelectedConnection.IsSelected = false;
                SelectedConnection = null;
            }

            if (SourceNode != null && SourceNode.IsEditing == false)
            {
                SourceNode.IsSelected = false;
                //SourceNull();
                SourceNode = null;

            }
        }
Пример #6
0
 public void Connect(Node node)
 {
     if (SourceNode == null)
     {
         SourceNode = node;
         SourceNode.IsSelected = true;
     }
     else
     {
         if (!SourceNode.Equals(node) && SourceNode.GroupId < node.GroupId && SourceNode.GroupId + 1 == node.GroupId)
         {
             Connection connection = new Connection(SourceNode,node);
             _graphCanvas.Children.Add(connection);
             SourceNode.Children.Add(node);
             ClearSelection();
         }
         else
         {
             if (SourceNode.GroupId == node.GroupId && !SourceNode.Equals(node))
             {
                 ClearSelection();
                 SourceNode = node;
                 SourceNode.IsSelected = true;
             }
             else
             {
                 ClearSelection();
             }
         }
     }
 }