aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs')
-rw-r--r--Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs32
1 files changed, 25 insertions, 7 deletions
diff --git a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs
index f8ae8faa1..9d7475aea 100644
--- a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs
+++ b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
@@ -43,7 +44,7 @@ namespace Tango.EmbroideryUI
public EmbroideryFile EmbroideryFile
{
get { return (EmbroideryFile)GetValue(EmbroideryFileProperty); }
- private set { SetValue(EmbroideryFileProperty, value); }
+ set { SetValue(EmbroideryFileProperty, value); }
}
public static readonly DependencyProperty EmbroideryFileProperty =
DependencyProperty.Register("EmbroideryFile", typeof(EmbroideryFile), typeof(EmbroideryFileEditor), new PropertyMetadata(null));
@@ -54,7 +55,7 @@ namespace Tango.EmbroideryUI
set { SetValue(FileNameProperty, value); }
}
public static readonly DependencyProperty FileNameProperty =
- DependencyProperty.Register("FileName", typeof(String), typeof(EmbroideryFileEditor), new PropertyMetadata(null,(d,e) => (d as EmbroideryFileEditor).OnFileNameChanged()));
+ DependencyProperty.Register("FileName", typeof(String), typeof(EmbroideryFileEditor), new PropertyMetadata(null, (d, e) => (d as EmbroideryFileEditor).OnFileNameChanged()));
public double ScaleFactor
{
@@ -62,7 +63,7 @@ namespace Tango.EmbroideryUI
set { SetValue(ScaleFactorProperty, value); }
}
public static readonly DependencyProperty ScaleFactorProperty =
- DependencyProperty.Register("ScaleFactor", typeof(double), typeof(EmbroideryFileEditor), new PropertyMetadata(1.0,(d,e) => (d as EmbroideryFileEditor).OnScaleFactorChanged()));
+ DependencyProperty.Register("ScaleFactor", typeof(double), typeof(EmbroideryFileEditor), new PropertyMetadata(1.0, (d, e) => (d as EmbroideryFileEditor).OnScaleFactorChanged()));
public EmbroideryPath SelectedPath
{
@@ -89,6 +90,8 @@ namespace Tango.EmbroideryUI
protected virtual void OnFileNameChanged()
{
+ if (!File.Exists(FileName)) return;
+
AnalyzeInput input = new AnalyzeInput();
input.FilePath = FileName;
@@ -180,12 +183,18 @@ namespace Tango.EmbroideryUI
Point _currentPoint = new Point();
Point _lastPoint = new Point();
+ Stitch _lastStitch = new Stitch();
StitchFlag _mode = StitchFlag.Jump;
+ if (Paths == null)
+ {
+ Paths = new ObservableCollection<EmbroideryPath>();
+ }
+
Paths.Clear();
Color color = ConvertStitchColorToColor(EmbroideryFile.Colors[0]);
- PathFigure path = CreatePathFigure(color, _currentPoint);
+ var path = CreatePathFigure(color, _currentPoint);
foreach (var stitch in EmbroideryFile.Stitches)
{
@@ -204,12 +213,15 @@ namespace Tango.EmbroideryUI
if (_mode == StitchFlag.Normal)
{
- path.Segments.Add(new LineSegment(new Point(_currentPoint.X, _currentPoint.Y), true));
+ path.PathFigure.Segments.Add(new LineSegment(new Point(_currentPoint.X, _currentPoint.Y), true));
+ path.Length += Math.Abs(GetDistance(_lastStitch.XX, _lastStitch.YY, stitch.XX, stitch.YY));
}
_mode = StitchFlag.Normal;
break;
}
+
+ _lastStitch = stitch;
_lastPoint = _currentPoint;
}
}
@@ -219,7 +231,7 @@ namespace Tango.EmbroideryUI
return Color.FromRgb((byte)stitchColor.Red, (byte)stitchColor.Green, (byte)stitchColor.Blue);
}
- private PathFigure CreatePathFigure(Color color, Point startPoint)
+ private EmbroideryPath CreatePathFigure(Color color, Point startPoint)
{
PathFigure figure = new PathFigure();
figure.StartPoint = startPoint;
@@ -227,10 +239,16 @@ namespace Tango.EmbroideryUI
EmbroideryPath path = new EmbroideryPath(new PathGeometry(new PathFigureCollection() { figure }));
+ path.PathFigure = figure;
path.StrokeThickness = 1;
path.Brush = new SolidColorBrush(color);
Paths.Add(path);
- return figure;
+ return path;
+ }
+
+ private static double GetDistance(double x1, double y1, double x2, double y2)
+ {
+ return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
#endregion