/// <summary> /// Add a form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonAdd(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Geometric shape file|*.gsf"; openFileDialog.Title = "Geometric shape File"; if (openFileDialog.ShowDialog() == DialogResult.OK) { StreamReader file = new StreamReader(openFileDialog.FileName); GeoShape shape = new GeoShape(file.ReadToEnd()); file.Close(); } DrawGraphic(); }
/// <summary> /// Load collection from .gsf file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadColection(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Geometric shape files archive|*.gsfar"; openFileDialog.Title = "Geometric shape file archive"; if (openFileDialog.ShowDialog() == DialogResult.OK) { GeoShape.GeoShapes.Clear(); currentGeoShape = 0; StreamReader file = new StreamReader(openFileDialog.FileName); GeoShape.PopulateGeoShapes(file.ReadToEnd().ToString()); file.Close(); } }
/// <summary> /// A function that populates GeoShapes with objects serialized. /// </summary> /// <param name="shapesData">A string that represents the serialized collection</param> public static void PopulateGeoShapes(string shapesData) { GeoShape val = new GeoShape(); string line; StringReader stringReader = new StringReader(shapesData); while (null != (line = stringReader.ReadLine())) { if (line.Equals("ENDOF")) { if (GeoShape.GeoShapes == null) { GeoShape.GeoShapes = new List <GeoShape>(); } GeoShape.GeoShapes.Add(val); val = new GeoShape(); } else { List <float> values = new List <float>(); var nameValue = line.Split('='); if ("Name".Equals(nameValue[0])) { val.name = nameValue[1]; } else { var valuesString = nameValue[1].Split(';'); foreach (var value in valuesString) { values.Add(float.Parse(value)); } val.objectDefinition.Add(new Tuple <string, List <float> >(nameValue[0], values)); } } } }