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(
|
||||
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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
ManipulationMode="TranslateX,TranslateY" ManipulationDelta="MainScroll_ManipulationDelta"
|
||||
Loading="MainScroll_Loading">
|
||||
<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>
|
||||
<MenuFlyout>
|
||||
<MenuFlyoutItem x:Name="MainPreviewRefresh" Text="Refresh" Click="MainPreviewRefresh_Click" />
|
||||
|
@ -76,7 +76,6 @@
|
|||
Source="{x:Bind Source, Mode=OneWay}"
|
||||
Opacity="{x:Bind Deleted, Mode=OneWay, Converter={StaticResource opacityConverter}}"
|
||||
Tapped="Image_Tapped"
|
||||
ImageOpened="Image_Loaded"
|
||||
Tag="{x:Bind Id}">
|
||||
<Image.ContextFlyout>
|
||||
<MenuFlyout>
|
||||
|
|
|
@ -12,6 +12,7 @@ using PCUT.ViewModels;
|
|||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
// 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)
|
||||
{
|
||||
LoadingModel.SetCount(_svgData.ComponentCount + dataUnloaded);
|
||||
PreviewModel.SetSource(_svgData.Data);
|
||||
PreviewModel.SetSource(_svgData.Data, Image_Loaded);
|
||||
foreach (var (id, deleted, component) in _svgData.ComponentData)
|
||||
ComponentModel.AddSource(id, deleted, component);
|
||||
ComponentModel.AddSource(id, deleted, component, Image_Loaded);
|
||||
}
|
||||
if (!UserContext.Instance.IsPermittedEdit)
|
||||
_designCenterModel.SelectedHeightIndex = 0;
|
||||
|
@ -157,9 +158,10 @@ namespace PCUT.Pages
|
|||
((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();
|
||||
sender.Opened -= Image_Loaded;
|
||||
}
|
||||
|
||||
private void AllImageLoaded(object sender, PropertyChangedEventArgs e)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
|
|||
using System.ComponentModel;
|
||||
using System.Xml.Linq;
|
||||
using PCUT.Extensions;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
@ -13,9 +14,13 @@ namespace PCUT.ViewModels
|
|||
{
|
||||
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();
|
||||
if (eventHandler != null)
|
||||
{
|
||||
source.Opened += eventHandler;
|
||||
}
|
||||
ComponentList.Add(new ComponentImageSource { Id = id, Deleted = deleted, Source = source });
|
||||
_ = source.LoadSvgAsync(doc);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.ComponentModel;
|
||||
using System.Xml.Linq;
|
||||
using PCUT.Extensions;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
|
@ -11,7 +12,7 @@ namespace PCUT.ViewModels
|
|||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private ImageSource _source;
|
||||
private ImageSource _defaultSource = new SvgImageSource();
|
||||
private SvgImageSource _defaultSource = new SvgImageSource();
|
||||
|
||||
public ImageSource Source
|
||||
{
|
||||
|
@ -31,9 +32,13 @@ namespace PCUT.ViewModels
|
|||
Source = source;
|
||||
}
|
||||
|
||||
public void SetSource(XDocument doc)
|
||||
public void SetSource(XDocument doc, TypedEventHandler<SvgImageSource, SvgImageSourceOpenedEventArgs> eventHandler = null)
|
||||
{
|
||||
Source = _defaultSource;
|
||||
if (eventHandler != null)
|
||||
{
|
||||
_defaultSource.Opened += eventHandler;
|
||||
}
|
||||
if (doc != null)
|
||||
_ = _source.LoadSvgAsync(doc);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace PCUT.ViewModels
|
|||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private int _count;
|
||||
public int Count { get; }
|
||||
public int Count { get => _count; }
|
||||
|
||||
public void SetCount(int count)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue