Component.Model SimplifyModel(Component.IModel model) { Component.Model simplified = new Component.Model(); Primitive.Figure figure = new Primitive.Figure(); Splitter splitter = new Splitter(); var figures = model.GetData(); foreach (var f in figures) { var contours = f.GetContours(); var lines = splitter.Split(contours, double.Parse(textBox_Splitter_Accuracy.Text, CultureInfo.InvariantCulture)); var new_segments = new List <ISegment>(); foreach (var line in lines) { new_segments.Add(JoinMSPoints.PointsToSegment(line.GetPoint1().GetPoint(), line.GetPoint2().GetPoint())); } var contour = new Primitive.Contour(); foreach (var new_s in new_segments) { contour.Add(new_s); } figure.Add(contour); } simplified.Add(figure); return(simplified); }
private void MenuItem_Click_1(object sender, RoutedEventArgs e) { //TODO: Dinar: think about changing statuses and implementation currentStatus.Content = "Экспортирование модели."; SaveFileDialog importDlg = new SaveFileDialog(); importDlg.InitialDirectory = "C:\\"; importDlg.Filter = "All files (*.*)|*.*|XML (*.xml)|*.xml"; importDlg.FilterIndex = 2; importDlg.RestoreDirectory = true; if (importDlg.ShowDialog() != null) { try { Component.Model model_temp = new Component.Model(); new FigureParser().ExportFile(mid_surface_model, importDlg.FileName); //TODO: Dinar: some trick, maybe not good solution model = null; mid_surface_model = null; RedrawModel(); } catch (Exception ex) { //TODO: Dinar: replace MessageBox.Show("Ошибка экспорта! Причина ошибки: " + ex.Message); currentStatus.Content = "Готов к работе."; return; } } mid_surface_model = null; currentStatus.Content = "Экспортирование завершено успешно. Готов к работе."; }
private void Go_all_tests(object sender, RoutedEventArgs e) { System.Windows.Forms.FolderBrowserDialog FBD = new System.Windows.Forms.FolderBrowserDialog(); if (FBD.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] allFoundFiles = Directory.GetFiles(FBD.SelectedPath, "*.xml", SearchOption.AllDirectories); double splitterAccuracy = double.Parse(textBox_Splitter_Accuracy.Text, CultureInfo.InvariantCulture); double detalizerAccuracy = double.Parse(textBox_Detalizer_Accuracy.Text, CultureInfo.InvariantCulture); IAlgorithm alg = new Algorithm(splitterAccuracy, detalizerAccuracy); RenderTargetBitmap rtb = new RenderTargetBitmap((int)mainCanvas.ActualWidth, (int)mainCanvas.ActualHeight, 96d, 96d, PixelFormats.Pbgra32); foreach (string path in allFoundFiles) { Component.Model model_temp = new Component.Model(); model_temp.Add(new FigureParser().ParseFile(path)); model = model_temp; RedrawModel(); mid_surface_model = alg.Run(new SolverData(model)); RedrawMidSurface(); // needed otherwise the image output is black mainCanvas.Measure(new Size((int)mainCanvas.ActualWidth, (int)mainCanvas.ActualHeight)); mainCanvas.Arrange(new Rect(new Size((int)mainCanvas.ActualWidth, (int)mainCanvas.ActualHeight))); rtb.Render(mainCanvas); PngBitmapEncoder BufferSave = new PngBitmapEncoder(); BufferSave.Frames.Add((BitmapFrame.Create(rtb))); using (var fs = File.OpenWrite(path.Substring(0, path.Length - 4) + "res.png")) { BufferSave.Save(fs); } } } }