private void AddShape_Click(object sender, RoutedEventArgs e) { var dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = "All supported files|*.jpeg;*.jpg;*.png;*.bmp;*.dat;*.cor;|Image files|*.jpeg;*.jpg;*.png;*.bmp|Coordinate files|*.dat;*.cor;"; var useHeightmap = false; if (dlg.ShowDialog().Value) { var filename = dlg.FileName; if (useHeightmap) { var reliefShape = _factory.LoadRelief(filename, out var name); if (reliefShape != null) { var reliefShapeItem = new MillingShapeItemRelief(name, reliefShape); reliefShapeItem.MetricHeight = 100; Workspace.Children.Add(reliefShapeItem); } } else { var flatShape = _factory.Load(filename, out var name); if (flatShape != null) { var shapeItem = new MillingShapeItem2D(name, flatShape); shapeItem.MetricHeight = 100; Workspace.Children.Add(shapeItem); } } } }
protected override void OnRender(DrawingContext dc) { base.OnRender(dc); if (_drawEvents == null) { var loader = new ShapeFactory3D(); //var points = loader.Load("./test_offset3.png", out _).First().Reverse(); var points = OffsetCalculator.Join(loader.Load("./test_islands.png", out _).Reverse()).First().ToArray(); /*/ * points = new Point2Dmm[] * { * new Point2Dmm(0,0), * new Point2Dmm(100, 0), * new Point2Dmm(100, 100), * new Point2Dmm(60, 100), * new Point2Dmm(80, 110), * new Point2Dmm(30, 110), * new Point2Dmm(20, 100), * new Point2Dmm(0, 100), * * new Point2Dmm(0,0), * };/**/ /*/ * points = new Point2Dmm[] * { * new Point2Dmm(70,60), * new Point2Dmm(40,20), * new Point2Dmm(120,20), * new Point2Dmm(100,60), * new Point2Dmm(105,25), * new Point2Dmm(60,25), * new Point2Dmm(140,140), * new Point2Dmm(70,140), * * new Point2Dmm(70,60), * };/**/ var offset = new OffsetCalculator(points, true); offset.WithOffset(40); _drawEvents = offset.GetUpdateSnapshots().ToArray(); _slider.Maximum = _drawEvents.Length - 1; _slider.Value = _slider.Maximum; } var snapshotToDisplay = _drawEvents[(int)_slider.Value]; foreach (var evt in snapshotToDisplay) { evt.Draw(dc); } }
public MillingItem Load(string path) { var extension = Path.GetExtension(path); if (extension == ".gcode" || extension == ".nc") { var name = Path.GetFileNameWithoutExtension(path); var identifier = new ReadableIdentifier(name); if (_provider != null) { identifier = _provider.UnusedVersion(identifier); } return(new MillingShapeItemGCode(File.ReadAllText(path), identifier)); } var useHeightmap = false; if (useHeightmap) { var reliefShape = _factory.LoadRelief(path, out var name); if (reliefShape != null) { var reliefShapeItem = new MillingShapeItemRelief(name, reliefShape); reliefShapeItem.MetricHeight = 100; return(reliefShapeItem); } } else { var flatShape = _factory.Load(path, out var name); if (flatShape != null) { var shapeItem = new MillingShapeItem2D(name, flatShape); shapeItem.MetricHeight = 100; return(shapeItem); } } return(null); }