Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            //TODO: Dinar: think about changing statuses and implementation
            currentStatus.Content = "Импортирование модели.";
            currentStatus.UpdateLayout();

            OpenFileDialog importDlg = new OpenFileDialog();

            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();
                    model_temp.Add(new FigureParser().ParseFile(importDlg.FileName));
                    filename = importDlg.FileName;
                    //TODO: Dinar: some trick, maybe not good solution
                    model = model_temp;
                    RedrawModel();
                }
                catch (Exception ex)
                {
                    //TODO: Dinar: replace
                    MessageBox.Show("Ошибка импорта! Причина ошибки: " + ex.Message);
                    currentStatus.Content = "Готов к работе.";
                    model             = null;
                    mid_surface_model = null;
                    RedrawModel();
                    return;
                }
            }
            mid_surface_model     = null;
            currentStatus.Content = "Импортирование завершено успешно. Готов к работе.";
        }