Esempio n. 1
0
        private void ChangePage(ObservableCollection<CanvasControlBase> graph)
        {
            if (_currentPageIndex == 0)
            {
                _currentPageIndex = 1;
                _algorithm = _secondPageAlgorithm;

                if (this.ComboBoxItems != null)
                {
                    _firstPageNodesList.Clear();
                    foreach (ComboboxElement elem in this.ComboBoxItems)
                    {
                        _firstPageNodesList.Add(elem.Clone());
                    }
                }
            }
            else
            {
                _currentPageIndex = 0;
                _algorithm = _firstPageAlgorithm;

                if (this.ComboBoxItems != null)
                {
                    _secondPageNodesList.Clear();
                    foreach (ComboboxElement elem in this.ComboBoxItems)
                    {
                        _secondPageNodesList.Add(elem.Clone());
                    }
                }
            }

            this.CanvasItems = graph;

            this.IsNodeNamesControlEnabled = false;
            this.IsNodeNamesControlVisible = false;

            if (_algorithm is IAlgorithmWithQueue)
            {
                this.ComboBoxItems = (_algorithm as IAlgorithmWithQueue).NodesQueue;
                List<Node> nodesList = graph.GetAllNodes();

                if (_currentPageIndex == 0)
                {
                    for (int i = 0; i < _firstPageNodesList.Count; i++)
                    {
                        Node realNode = nodesList.SingleOrDefault(n => n.ID == _firstPageNodesList[i].SelectedValue?.ID);

                        this.ComboBoxItems[i].SelectedValue = realNode;
                    }
                }
                else
                {
                    for (int i = 0; i < _secondPageNodesList.Count; i++)
                    {
                        Node realNode = nodesList.SingleOrDefault(n => n.ID == _secondPageNodesList[i].SelectedValue?.ID);

                        this.ComboBoxItems[i].SelectedValue = realNode;
                    }
                }

                if (_algorithm is BFS)
                {
                    this.IsNodeNamesControlEnabled = true;
                    this.IsNodeNamesControlVisible = true;
                }

                if (_algorithm is TopologicalSort && (_algorithm as TopologicalSort).isSortingNodes)
                {
                    this.IsNodeNamesControlEnabled = true;
                    this.IsNodeNamesControlVisible = true;
                }

                if (_algorithm is BellmanFord)
                {
                    this.IsNodeNamesControlVisible = true;

                    if ((_algorithm as BellmanFord).NodesQueue.Where(n => n.SelectedValue != null).Count() == _algorithm.CorrectNodesList.Count)
                        this.IsNodeNamesControlEnabled = false;
                    else
                        this.IsNodeNamesControlEnabled = true;

                    if ((_algorithm as BellmanFord).IsLastStep)
                        this.IsStopButtonVisible = true;
                }
            }
        }