public static Path3D LoadFromFile(string filePath, List<Point3D> points) { Path3D path = new Path3D(points); using (StreamReader reader = new StreamReader(filePath)) { string line = reader.ReadLine(); const string pointPattern = @"Path:\s+((?:Point\s*\((?:.*?),\s*(?:.*?),\s*(?:.*?)\)\s*)+)"; while (line != null) { Regex regex = new Regex(pointPattern); MatchCollection matches = regex.Matches(line); if (matches.Count == 3) { double x = double.Parse(matches[0].Groups[1].Value); double y = double.Parse(matches[1].Groups[2].Value); double z = double.Parse(matches[2].Groups[3].Value); Point3D point = new Point3D(x, y, z); path.AddPointToPath(point); } line = reader.ReadLine(); } } return path; }
static void Main() { //TODO try { List<Point3D> pointsList = new List<Point3D>(); pointsList.Add(Point3D.StartingPoint); pointsList.Add(new Point3D(0, 2, 2.9)); pointsList.Add(new Point3D(-9, -1, -1.9)); pointsList.Add(new Point3D(2, -2, -19)); Path3D path = new Path3D(pointsList); path.AddPointToPath(new Point3D(1, 2.0001, -4.7)); Console.WriteLine(path); Storage.SavePathToFile("../../path.txt", path.ToString()); Console.WriteLine("Load from file:\n\r" + Storage.SavePathToFile("../../path.txt", path.ToString())); } catch (Exception) { throw; } }