Esempio n. 1
0
        private void RemoveEdgeButton_Click(object sender, EventArgs e)
        {
            SelectTwoVerticesDialog selectEdge = new SelectTwoVerticesDialog();
            bool repeate = true;

            do
            {
                if (DialogResult.OK == selectEdge.ShowDialog())
                {
                    try
                    {
                        // remove edge
                        _forestGraph.RemoveEdge(selectEdge.StartVertex, selectEdge.TargetVertex);
                        _graphPath.Clear();
                        _saved = false;
                        _dijkstra.Invalidate();
                        RegenerateTrajectoryMatrix();
                    }
                    catch (Exception ex)
                    {
                        ShowMessage(ex.Message);
                        continue;
                    }

                    graphCanvas.Invalidate();
                }

                repeate = false;
            } while (repeate);
        }
Esempio n. 2
0
        private void FindRouteButton_Click(object sender, EventArgs e)
        {
            SelectTwoVerticesDialog selectPath = new SelectTwoVerticesDialog(true);
            bool repeate = true;

            do
            {
                if (DialogResult.OK == selectPath.ShowDialog())
                {
                    // start and target points are same
                    if (selectPath.StartVertex == selectPath.TargetVertex &&
                        _forestGraph.HasVertex(selectPath.TargetVertex))
                    {
                        ShowMessage(Resources.PathToSameVertex, MessageBoxIcon.Information);
                        continue;
                    }

                    // start or target point (or both) do not exist
                    if (!_forestGraph.HasVertex(selectPath.StartVertex) ||
                        !_forestGraph.HasVertex(selectPath.TargetVertex))
                    {
                        ShowMessage(Resources.SelectedVerticesNotExist, MessageBoxIcon.Warning);
                        continue;
                    }

                    try
                    {
                        if (selectPath.Starship == true)
                        {
                            _graphPath = new List <string>()
                            {
                                selectPath.StartVertex, selectPath.TargetVertex
                            };
                            graphCanvas.Invalidate();
                            ShowMessage(Resources.UsingSpaceship, MessageBoxIcon.Warning, "EASTER EGG");
                        }
                        else
                        {
                            // find and store path
                            _graphPath.Clear();
                            var path = _dijkstra.FindPaths(selectPath.StartVertex).GetPath(selectPath.TargetVertex);
                            if (path.Count > 0)
                            {
                                _graphPath = path;
                                graphCanvas.Invalidate();
                            }
                            else
                            {
                                ShowMessage(Resources.PathNotExists, MessageBoxIcon.Warning);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowMessage(ex.Message);
                        continue;
                    }

                    graphCanvas.Invalidate();
                }

                repeate = false;
            } while (repeate);
        }