コード例 #1
0
        private void PopulateButtonsList()
        {
            var generateButton = UiElements.GetButton("Generate Graph");

            generateButton.EventMouseClick += (sender, args) =>
            {
                var dialog = new GenerateGraphDialog(_presenter.MaxVertices);
                dialog.GotCorrectInput += OnGotGraphGenerationInput;
                dialog.Show(this);
            };

            var shimbelButton = UiElements.GetButton("Shimbel's Algorithm");

            shimbelButton.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    var dialog = new ShimbelDialog(_presenter.Vertices);
                    dialog.GotCorrectShimbel += OnGotShimbelInput;
                    dialog.Show(this);
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var checkReachButton = UiElements.GetButton("Check Path Existence");

            checkReachButton.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    var dialog = new CheckPathExistenceDialog(_presenter.Vertices);
                    dialog.GotCorrectCheckPath += OnGotCheckPathInput;
                    dialog.Show(this);
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var shortestPathButton = UiElements.GetButton("Find Shortest Path");

            shortestPathButton.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    var dialog = new ShortestPathDialog(_presenter.Vertices);
                    dialog.GotCorrectFindPath += OnGotFindPathInput;
                    dialog.Show(this);
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var spanningTreesButton = UiElements.GetButton("Find Spanning Trees");

            spanningTreesButton.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    var dialog = new MinimumSpanningTreeDialog();
                    dialog.GotPrimRequest    += OnGotPrimRequest;
                    dialog.GotKruskalRequest += OnGotKruskalRequest;
                    dialog.GotTotalRequest   += OnGotTotalRequest;
                    dialog.Show(this);
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var getPruferCode = UiElements.GetButton("Get Prufer Code for SST");

            getPruferCode.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    if (_presenter.IsSstGenerated())
                    {
                        ShowPopUp(_presenter.OnGetPruferCall());
                    }
                    else
                    {
                        ShowPopUp("Generate SST first");
                    }
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var setPruferCode = UiElements.GetButton("Graph from Prufer Code");

            setPruferCode.EventMouseClick += (sender, args) =>
            {
                var dialog = new PruferCodeDialog();
                dialog.GotCorrectPruferInput += OnGotPruferInput;
                dialog.Show(this);
            };

            var generateFlowNetwork = UiElements.GetButton("Flow network from this");

            generateFlowNetwork.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    //_presenter.SaveGraph();
                    _presenter.OnCreateFlowNetworkCall();
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var findMaxFlow = UiElements.GetButton("Find max flow");

            findMaxFlow.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    if (_presenter.IsFlowNetworkGenerated())
                    {
                        ShowPopUp("Max Flow: " + _presenter.OnMaxFlowCall().ToString());
                    }
                    else
                    {
                        ShowPopUp("Modify graph into flow network");
                    }
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var findMinCostFlow = UiElements.GetButton("Find min cost flow");

            findMinCostFlow.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    if (_presenter.IsFlowNetworkGenerated())
                    {
                        ShowPopUp("Min Cost (2 * Max Flow / 3): " +
                                  _presenter.OnMinCostFlowCall().ToString());
                    }
                    else
                    {
                        ShowPopUp("Modify graph into flow network");
                    }
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var makeEulerian = UiElements.GetButton("Make Eulerian");

            makeEulerian.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    if (!_presenter.WasModified())
                    {
                        _presenter.OnMakeEulerianCall();
                    }
                    else
                    {
                        ShowPopUp("Reset modified graph");
                    }
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var makeHamiltonian = UiElements.GetButton("Make Hamiltonian");

            makeHamiltonian.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    if (!_presenter.WasModified())
                    {
                        _presenter.OnMakeHamiltonianCall();
                    }
                    else
                    {
                        ShowPopUp("Reset modified graph");
                    }
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var findEulerianCycle = UiElements.GetButton("Find Eulerian Cycle");

            findEulerianCycle.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    if (_presenter.WasModified())
                    {
                        if (_presenter.IsEulerian() || _presenter.Vertices == 2)
                        {
                            _presenter.OnFindEulerianCycleCall();
                        }
                        else
                        {
                            ShowPopUp("Graph is not eulerian");
                        }
                    }
                    else
                    {
                        ShowPopUp("Create eulerian graph first");
                    }
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            var findHamiltonianCycle = UiElements.GetButton("Find Hamiltonian Cycle");

            findHamiltonianCycle.EventMouseClick += (sender, args) =>
            {
                if (_presenter.IsGraphGenerated())
                {
                    if (_presenter.WasModified())
                    {
                        if (_presenter.IsHamiltonian())
                        {
                            if (_presenter.Vertices <= 8)
                            {
                                _presenter.OnFindHamiltonianCycleCall();
                            }
                            else
                            {
                                ShowPopUp("There should be <= 7 vertices");
                            }
                        }
                        else
                        {
                            ShowPopUp("Graph is not hamiltonian");
                        }
                    }
                    else
                    {
                        ShowPopUp("Create hamiltonian graph first");
                    }
                }
                else
                {
                    ShowPopUp("Generate graph first");
                }
            };

            _buttonsList.AddItems(
                generateButton,
                shimbelButton,
                checkReachButton,
                shortestPathButton,
                spanningTreesButton,
                getPruferCode,
                setPruferCode,
                generateFlowNetwork,
                findMaxFlow,
                findMinCostFlow,
                makeEulerian,
                makeHamiltonian,
                findEulerianCycle,
                findHamiltonianCycle);
        }