fix cut file calculation

This commit is contained in:
kwan.nguyen 2024-10-30 18:16:08 +07:00
parent f5d9cce2ea
commit 5e1344d9d5
4 changed files with 12 additions and 11 deletions

View File

@ -27,7 +27,6 @@ namespace PCUT.Extensions
public static IEnumerable<(string Path, TimeSpan EstimateTime)> ToHPGL(
this XDocument svg,
(double Width, double Height) size,
(double Width, double Height) sheetSize,
int speed, // mm/s
int pen = 0)
{
@ -36,7 +35,7 @@ namespace PCUT.Extensions
var widthUnit = (int)Math.Ceiling(size.Width / UnitLength);
var heightUnit = (int)Math.Ceiling(size.Height / UnitLength);
SvgTransform transform = new TranslateTransform(0, (int)Math.Ceiling(sheetSize.Height / UnitLength));
SvgTransform transform = new TranslateTransform(0, heightUnit);
var flipTransform = new ScaleTransform(1, -1);
flipTransform.SetNext(transform);
@ -64,7 +63,7 @@ namespace PCUT.Extensions
{
var lengthX = Math.Abs(maxX - moveCommand.X);
builder.AddHpglMove(moveCommand.X, moveCommand.Y, ref maxX);
length += (lengthX + (sheetSize.Height / UnitLength)) * 0.75;
length += (lengthX + (heightUnit / UnitLength)) * 0.75;
break;
}
case LineCommand lineCommand:

View File

@ -49,23 +49,23 @@ namespace PCUT.Pages
StartButton.IsEnabled = !(portName is null);
ViewModels = DataContext as CutDialogViewModel;
ViewModels.Width = Math.Ceiling(_designCenterViewModel.UseOrigin ? _designCenterViewModel.Width : _svgData.NestedWidth.Value);
ViewModels.Height = Math.Ceiling(_designCenterViewModel.UseOrigin ? _designCenterViewModel.Height : _svgData.NestedHeight.Value);
}
private Task _printTask;
private void ContentDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args)
{
var data = _designCenterViewModel.UseOrigin ? _svgData.Data : _svgData.NestedData;
PreviewWidthDisplay.Text = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginWidth.Value : _svgData.NestedWidth.Value).ToString();
PreviewHeightDisplay.Text = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginHeight.Value : _svgData.NestedHeight.Value).ToString();
PreviewWidthDisplay.Text = ViewModels.Width.ToString();
PreviewHeightDisplay.Text = ViewModels.Height.ToString();
DisplayModel.SetSource(data);
}
private void MainScroll_Loading(FrameworkElement sender, object args)
{
var borderRatio = MainColumnDefinition.ActualWidth / PreviewRowDefinition.ActualHeight;
var width = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginWidth.Value : _svgData.NestedWidth.Value);
var height = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginHeight.Value : _svgData.NestedHeight.Value);
var ratio = width / height;
var ratio = ViewModels.Width / ViewModels.Height;
if (ratio < borderRatio)
((ComponentStyle)Resources["previewStyle"]).SetSize(PreviewRowDefinition, ratio);
else
@ -98,8 +98,7 @@ namespace PCUT.Pages
await Task.Factory.StartNew(() =>
{
var data = nested.ToHPGL(
(_svgData.OriginWidth.Value, _svgData.OriginHeight.Value),
(_designCenterViewModel.Width, _designCenterViewModel.Height),
(ViewModels.Width, ViewModels.Height),
_portSettings.Speed);
serialPort.Open();
Task waitTask = Task.CompletedTask;

View File

@ -401,7 +401,7 @@ namespace PCUT.Pages
var width = _svgData.SheetInfo.Width;
var height = _svgData.SheetInfo.Height;
var viewBox = _svgData.OriginViewBox.GetViewBoxData();
nestedDoc.Root.SetAttributeValue("viewBox", $"{viewBox.MinX - 100} {viewBox.MinY - 100} {nestedWidth + 100} {nestedHeight + 100}");
nestedDoc.Root.SetAttributeValue("viewBox", $"0 0 {nestedWidth} {nestedHeight}");
nestedDoc.Root.Add(XElement.Parse($"<rect id=\"PCUT_BOUNDING\" x=\"0\" y=\"0\" width=\"{_designCenterModel.Width}\" height=\"{_designCenterModel.Height}\" fill=\"none\" stroke=\"blue\" stroke-dasharray=\"{_designCenterModel.Width / 200}\" stroke-width=\"{_designCenterModel.Height / 2000}\" />"));
nestedDoc.Root.Add(XElement.Parse($"<rect id=\"PCUT_BOUNDING_NESTED\" x=\"0\" y=\"0\" width=\"{nestedWidth}\" height=\"{nestedHeight}\" fill=\"none\" stroke=\"blue\" stroke-dasharray=\"{width / 200}\" stroke-width=\"{width / 2000}\" />"));
return (nestedDoc, nestedWidth, nestedHeight);

View File

@ -12,6 +12,9 @@ namespace PCUT.ViewModels
{
internal class CutDialogViewModel : NotificationBase
{
public double Width { get; set; }
public double Height { get; set; }
private string _printCommand;
public string PrintCommand
{