From 5e1344d9d594deabb5f31672f90a8015de2456f6 Mon Sep 17 00:00:00 2001 From: "kwan.nguyen" Date: Wed, 30 Oct 2024 18:16:08 +0700 Subject: [PATCH] fix cut file calculation --- PCUT/PCUT/Extensions/HpglExtensions.cs | 5 ++--- PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs | 13 ++++++------- PCUT/PCUT/Pages/DesignCenter/SvgNestPage.xaml.cs | 2 +- PCUT/PCUT/ViewModels/CutDialogViewModel.cs | 3 +++ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/PCUT/PCUT/Extensions/HpglExtensions.cs b/PCUT/PCUT/Extensions/HpglExtensions.cs index 63ed203..7ca0799 100644 --- a/PCUT/PCUT/Extensions/HpglExtensions.cs +++ b/PCUT/PCUT/Extensions/HpglExtensions.cs @@ -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: diff --git a/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs b/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs index 096290e..4c220cb 100644 --- a/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs +++ b/PCUT/PCUT/Pages/DesignCenter/CutFilesDialog.xaml.cs @@ -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; diff --git a/PCUT/PCUT/Pages/DesignCenter/SvgNestPage.xaml.cs b/PCUT/PCUT/Pages/DesignCenter/SvgNestPage.xaml.cs index abf1234..09d119b 100644 --- a/PCUT/PCUT/Pages/DesignCenter/SvgNestPage.xaml.cs +++ b/PCUT/PCUT/Pages/DesignCenter/SvgNestPage.xaml.cs @@ -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($"")); nestedDoc.Root.Add(XElement.Parse($"")); return (nestedDoc, nestedWidth, nestedHeight); diff --git a/PCUT/PCUT/ViewModels/CutDialogViewModel.cs b/PCUT/PCUT/ViewModels/CutDialogViewModel.cs index dc83a68..a57c644 100644 --- a/PCUT/PCUT/ViewModels/CutDialogViewModel.cs +++ b/PCUT/PCUT/ViewModels/CutDialogViewModel.cs @@ -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 {