private void saveButton_Click(object sender, RoutedEventArgs e) { SaveFileDialog _dialog = new SaveFileDialog(); _dialog.FileName = "*.cgds"; _dialog.ShowDialog(this); PointCollectionTranslator pointsTranslator = new PointCollectionTranslator(); LineCollectionTranslator linesTranslator = new LineCollectionTranslator(); PolygonCollectionTranslator polygonsTranslator = new PolygonCollectionTranslator(); FileHelper.Save(_dialog.FileName, pointsTranslator.Encode <CGUtilities.Point>(drawingCanvas.Points.ToList()) + linesTranslator.Encode <CGUtilities.Line>(drawingCanvas.Lines.ToList()) + polygonsTranslator.Encode <CGUtilities.Polygon>(drawingCanvas.Polygons.ToList())); }
private void LoadButton_OnClickButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog _dialog = new OpenFileDialog(); _dialog.Multiselect = false; _dialog.Filter = "Computational Geometry Dataset|*.cgds"; _dialog.ShowDialog(this); string content = FileHelper.Load(_dialog.FileName); if (content.Equals(String.Empty)) { return; } PointCollectionTranslator pointsTranslator = new PointCollectionTranslator(); LineCollectionTranslator linesTranslator = new LineCollectionTranslator(); PolygonCollectionTranslator polygonsTranslator = new PolygonCollectionTranslator(); drawingCanvas.Points.Clear(); drawingCanvas.Lines.Clear(); drawingCanvas.Polygons.Clear(); foreach (CGUtilities.Point singlePoint in pointsTranslator.Decode(content)) { drawingCanvas.Points.Add(singlePoint); } foreach (CGUtilities.Line singleLine in linesTranslator.Decode(content)) { drawingCanvas.Lines.Add(singleLine); } foreach (CGUtilities.Polygon singlePolygon in polygonsTranslator.Decode(content)) { foreach (CGUtilities.Line singleLine in singlePolygon.lines) { drawingCanvas.Lines.Add(singleLine); } drawingCanvas.Polygons.Add(singlePolygon); } }