Esempio n. 1
0
        private void NewGraphButton_Click(object sender, EventArgs e)
        {
            if (DialogResult.Cancel == AskForSave())
            {
                return;
            }

            _dijkstra.Invalidate();
            _rectangle = new RectangleF(0, 0, 0, 0);
            _forestGraph.Clear();
            _graphPath.Clear();
            _saved = true;
            graphCanvas.Invalidate();
            _saveFileName = "";
            BuildRangeTree();
            SetTitle();
            File.Delete(_binaryFile);
        }
Esempio n. 2
0
        public static bool LoadData(Graph <string, VertexData, string, EdgeData> graph, string path)
        {
            GraphData data;

            StreamReader  sr           = new StreamReader(path);
            XmlSerializer deserializer = new XmlSerializer(typeof(GraphData));

            data = (GraphData)deserializer.Deserialize(sr);
            sr.Close();

            bool replaceData = false;

            if (!graph.IsEmpty())
            {
                DialogResult result = MessageBox.Show(Resources.DataAlreadyExists, Resources.DataAlreadyExistsTitle,
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    replaceData = true;
                }
            }

            if (graph.IsEmpty() || (!graph.IsEmpty() && replaceData))
            {
                graph.Clear();

                foreach (var v in data.Vertices)
                {
                    VertexData vertexData = new VertexData(v.Key, new PointF(v.X, v.Y), v.Type);
                    graph.AddVertex(v.Key, vertexData);
                }

                foreach (var e in data.Edges)
                {
                    EdgeData edgeData = new EdgeData(e.Size, EdgeType.Free);
                    graph.AddEdge(e.Key, e.Start, e.Target, edgeData);
                }
                return(true);
            }
            return(false);
        }