Compare commits
2 Commits
f5d9cce2ea
...
05a0eab829
Author | SHA1 | Date |
---|---|---|
kwan.nguyen | 05a0eab829 | |
kwan.nguyen | 5e1344d9d5 |
|
@ -27,7 +27,6 @@ namespace PCUT.Extensions
|
||||||
public static IEnumerable<(string Path, TimeSpan EstimateTime)> ToHPGL(
|
public static IEnumerable<(string Path, TimeSpan EstimateTime)> ToHPGL(
|
||||||
this XDocument svg,
|
this XDocument svg,
|
||||||
(double Width, double Height) size,
|
(double Width, double Height) size,
|
||||||
(double Width, double Height) sheetSize,
|
|
||||||
int speed, // mm/s
|
int speed, // mm/s
|
||||||
int pen = 0)
|
int pen = 0)
|
||||||
{
|
{
|
||||||
|
@ -36,7 +35,7 @@ namespace PCUT.Extensions
|
||||||
var widthUnit = (int)Math.Ceiling(size.Width / UnitLength);
|
var widthUnit = (int)Math.Ceiling(size.Width / UnitLength);
|
||||||
var heightUnit = (int)Math.Ceiling(size.Height / 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);
|
var flipTransform = new ScaleTransform(1, -1);
|
||||||
flipTransform.SetNext(transform);
|
flipTransform.SetNext(transform);
|
||||||
|
@ -64,7 +63,7 @@ namespace PCUT.Extensions
|
||||||
{
|
{
|
||||||
var lengthX = Math.Abs(maxX - moveCommand.X);
|
var lengthX = Math.Abs(maxX - moveCommand.X);
|
||||||
builder.AddHpglMove(moveCommand.X, moveCommand.Y, ref maxX);
|
builder.AddHpglMove(moveCommand.X, moveCommand.Y, ref maxX);
|
||||||
length += (lengthX + (sheetSize.Height / UnitLength)) * 0.75;
|
length += (lengthX + (heightUnit / UnitLength)) * 0.75;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LineCommand lineCommand:
|
case LineCommand lineCommand:
|
||||||
|
|
|
@ -49,23 +49,23 @@ namespace PCUT.Pages
|
||||||
StartButton.IsEnabled = !(portName is null);
|
StartButton.IsEnabled = !(portName is null);
|
||||||
|
|
||||||
ViewModels = DataContext as CutDialogViewModel;
|
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 Task _printTask;
|
||||||
private void ContentDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args)
|
private void ContentDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args)
|
||||||
{
|
{
|
||||||
var data = _designCenterViewModel.UseOrigin ? _svgData.Data : _svgData.NestedData;
|
var data = _designCenterViewModel.UseOrigin ? _svgData.Data : _svgData.NestedData;
|
||||||
PreviewWidthDisplay.Text = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginWidth.Value : _svgData.NestedWidth.Value).ToString();
|
PreviewWidthDisplay.Text = ViewModels.Width.ToString();
|
||||||
PreviewHeightDisplay.Text = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginHeight.Value : _svgData.NestedHeight.Value).ToString();
|
PreviewHeightDisplay.Text = ViewModels.Height.ToString();
|
||||||
DisplayModel.SetSource(data);
|
DisplayModel.SetSource(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainScroll_Loading(FrameworkElement sender, object args)
|
private void MainScroll_Loading(FrameworkElement sender, object args)
|
||||||
{
|
{
|
||||||
var borderRatio = MainColumnDefinition.ActualWidth / PreviewRowDefinition.ActualHeight;
|
var borderRatio = MainColumnDefinition.ActualWidth / PreviewRowDefinition.ActualHeight;
|
||||||
var width = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginWidth.Value : _svgData.NestedWidth.Value);
|
var ratio = ViewModels.Width / ViewModels.Height;
|
||||||
var height = Math.Ceiling(_designCenterViewModel.UseOrigin ? _svgData.OriginHeight.Value : _svgData.NestedHeight.Value);
|
|
||||||
var ratio = width / height;
|
|
||||||
if (ratio < borderRatio)
|
if (ratio < borderRatio)
|
||||||
((ComponentStyle)Resources["previewStyle"]).SetSize(PreviewRowDefinition, ratio);
|
((ComponentStyle)Resources["previewStyle"]).SetSize(PreviewRowDefinition, ratio);
|
||||||
else
|
else
|
||||||
|
@ -98,8 +98,7 @@ namespace PCUT.Pages
|
||||||
await Task.Factory.StartNew(() =>
|
await Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
var data = nested.ToHPGL(
|
var data = nested.ToHPGL(
|
||||||
(_svgData.OriginWidth.Value, _svgData.OriginHeight.Value),
|
(ViewModels.Width, ViewModels.Height),
|
||||||
(_designCenterViewModel.Width, _designCenterViewModel.Height),
|
|
||||||
_portSettings.Speed);
|
_portSettings.Speed);
|
||||||
serialPort.Open();
|
serialPort.Open();
|
||||||
Task waitTask = Task.CompletedTask;
|
Task waitTask = Task.CompletedTask;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
ManipulationMode="TranslateX,TranslateY" ManipulationDelta="MainScroll_ManipulationDelta"
|
ManipulationMode="TranslateX,TranslateY" ManipulationDelta="MainScroll_ManipulationDelta"
|
||||||
Loading="MainScroll_Loading">
|
Loading="MainScroll_Loading">
|
||||||
<Viewbox Width="{Binding Width, Source={StaticResource previewStyle}, Mode=OneWay}" Height="{Binding Height, Source={StaticResource previewStyle}, Mode=OneWay}">
|
<Viewbox Width="{Binding Width, Source={StaticResource previewStyle}, Mode=OneWay}" Height="{Binding Height, Source={StaticResource previewStyle}, Mode=OneWay}">
|
||||||
<Image x:Name="MainPreview" Source="{x:Bind PreviewModel.Source, Mode=OneWay}" ImageOpened="Image_Loaded">
|
<Image x:Name="MainPreview" Source="{x:Bind PreviewModel.Source, Mode=OneWay}">
|
||||||
<Image.ContextFlyout>
|
<Image.ContextFlyout>
|
||||||
<MenuFlyout>
|
<MenuFlyout>
|
||||||
<MenuFlyoutItem x:Name="MainPreviewRefresh" Text="Refresh" Click="MainPreviewRefresh_Click" />
|
<MenuFlyoutItem x:Name="MainPreviewRefresh" Text="Refresh" Click="MainPreviewRefresh_Click" />
|
||||||
|
@ -76,7 +76,6 @@
|
||||||
Source="{x:Bind Source, Mode=OneWay}"
|
Source="{x:Bind Source, Mode=OneWay}"
|
||||||
Opacity="{x:Bind Deleted, Mode=OneWay, Converter={StaticResource opacityConverter}}"
|
Opacity="{x:Bind Deleted, Mode=OneWay, Converter={StaticResource opacityConverter}}"
|
||||||
Tapped="Image_Tapped"
|
Tapped="Image_Tapped"
|
||||||
ImageOpened="Image_Loaded"
|
|
||||||
Tag="{x:Bind Id}">
|
Tag="{x:Bind Id}">
|
||||||
<Image.ContextFlyout>
|
<Image.ContextFlyout>
|
||||||
<MenuFlyout>
|
<MenuFlyout>
|
||||||
|
|
|
@ -12,6 +12,7 @@ using PCUT.ViewModels;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Input;
|
using Windows.UI.Xaml.Input;
|
||||||
|
using Windows.UI.Xaml.Media.Imaging;
|
||||||
using Windows.UI.Xaml.Navigation;
|
using Windows.UI.Xaml.Navigation;
|
||||||
|
|
||||||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
|
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
|
||||||
|
@ -86,9 +87,9 @@ namespace PCUT.Pages
|
||||||
if (_svgData.Data != null)
|
if (_svgData.Data != null)
|
||||||
{
|
{
|
||||||
LoadingModel.SetCount(_svgData.ComponentCount + dataUnloaded);
|
LoadingModel.SetCount(_svgData.ComponentCount + dataUnloaded);
|
||||||
PreviewModel.SetSource(_svgData.Data);
|
PreviewModel.SetSource(_svgData.Data, Image_Loaded);
|
||||||
foreach (var (id, deleted, component) in _svgData.ComponentData)
|
foreach (var (id, deleted, component) in _svgData.ComponentData)
|
||||||
ComponentModel.AddSource(id, deleted, component);
|
ComponentModel.AddSource(id, deleted, component, Image_Loaded);
|
||||||
}
|
}
|
||||||
if (!UserContext.Instance.IsPermittedEdit)
|
if (!UserContext.Instance.IsPermittedEdit)
|
||||||
_designCenterModel.SelectedHeightIndex = 0;
|
_designCenterModel.SelectedHeightIndex = 0;
|
||||||
|
@ -157,9 +158,10 @@ namespace PCUT.Pages
|
||||||
((ComponentStyle)Resources["componentStyle"]).SetSize(ComponentColumnDefinition, rate: 3);
|
((ComponentStyle)Resources["componentStyle"]).SetSize(ComponentColumnDefinition, rate: 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Image_Loaded(object sender, RoutedEventArgs e)
|
private void Image_Loaded(SvgImageSource sender, SvgImageSourceOpenedEventArgs e)
|
||||||
{
|
{
|
||||||
LoadingModel.DecreaseCount();
|
LoadingModel.DecreaseCount();
|
||||||
|
sender.Opened -= Image_Loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AllImageLoaded(object sender, PropertyChangedEventArgs e)
|
private void AllImageLoaded(object sender, PropertyChangedEventArgs e)
|
||||||
|
|
|
@ -401,7 +401,7 @@ namespace PCUT.Pages
|
||||||
var width = _svgData.SheetInfo.Width;
|
var width = _svgData.SheetInfo.Width;
|
||||||
var height = _svgData.SheetInfo.Height;
|
var height = _svgData.SheetInfo.Height;
|
||||||
var viewBox = _svgData.OriginViewBox.GetViewBoxData();
|
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\" 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}\" />"));
|
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);
|
return (nestedDoc, nestedWidth, nestedHeight);
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using PCUT.Extensions;
|
using PCUT.Extensions;
|
||||||
|
using Windows.Foundation;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using Windows.UI.Xaml.Media.Imaging;
|
using Windows.UI.Xaml.Media.Imaging;
|
||||||
|
@ -13,9 +14,13 @@ namespace PCUT.ViewModels
|
||||||
{
|
{
|
||||||
public ObservableCollection<ComponentImageSource> ComponentList { get; } = new ObservableCollection<ComponentImageSource>();
|
public ObservableCollection<ComponentImageSource> ComponentList { get; } = new ObservableCollection<ComponentImageSource>();
|
||||||
|
|
||||||
public void AddSource(string id, bool deleted, XDocument doc)
|
public void AddSource(string id, bool deleted, XDocument doc, TypedEventHandler<SvgImageSource, SvgImageSourceOpenedEventArgs> eventHandler = null)
|
||||||
{
|
{
|
||||||
var source = new SvgImageSource();
|
var source = new SvgImageSource();
|
||||||
|
if (eventHandler != null)
|
||||||
|
{
|
||||||
|
source.Opened += eventHandler;
|
||||||
|
}
|
||||||
ComponentList.Add(new ComponentImageSource { Id = id, Deleted = deleted, Source = source });
|
ComponentList.Add(new ComponentImageSource { Id = id, Deleted = deleted, Source = source });
|
||||||
_ = source.LoadSvgAsync(doc);
|
_ = source.LoadSvgAsync(doc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@ namespace PCUT.ViewModels
|
||||||
{
|
{
|
||||||
internal class CutDialogViewModel : NotificationBase
|
internal class CutDialogViewModel : NotificationBase
|
||||||
{
|
{
|
||||||
|
public double Width { get; set; }
|
||||||
|
public double Height { get; set; }
|
||||||
|
|
||||||
private string _printCommand;
|
private string _printCommand;
|
||||||
public string PrintCommand
|
public string PrintCommand
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using PCUT.Extensions;
|
using PCUT.Extensions;
|
||||||
|
using Windows.Foundation;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using Windows.UI.Xaml.Media.Imaging;
|
using Windows.UI.Xaml.Media.Imaging;
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ namespace PCUT.ViewModels
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
private ImageSource _source;
|
private ImageSource _source;
|
||||||
private ImageSource _defaultSource = new SvgImageSource();
|
private SvgImageSource _defaultSource = new SvgImageSource();
|
||||||
|
|
||||||
public ImageSource Source
|
public ImageSource Source
|
||||||
{
|
{
|
||||||
|
@ -31,9 +32,13 @@ namespace PCUT.ViewModels
|
||||||
Source = source;
|
Source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetSource(XDocument doc)
|
public void SetSource(XDocument doc, TypedEventHandler<SvgImageSource, SvgImageSourceOpenedEventArgs> eventHandler = null)
|
||||||
{
|
{
|
||||||
Source = _defaultSource;
|
Source = _defaultSource;
|
||||||
|
if (eventHandler != null)
|
||||||
|
{
|
||||||
|
_defaultSource.Opened += eventHandler;
|
||||||
|
}
|
||||||
if (doc != null)
|
if (doc != null)
|
||||||
_ = _source.LoadSvgAsync(doc);
|
_ = _source.LoadSvgAsync(doc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace PCUT.ViewModels
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
private int _count;
|
private int _count;
|
||||||
public int Count { get; }
|
public int Count { get => _count; }
|
||||||
|
|
||||||
public void SetCount(int count)
|
public void SetCount(int count)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue