aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Embroidery
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2018-03-04 02:26:30 +0200
committerRoy <roy.mail.net@gmail.com>2018-03-04 02:26:30 +0200
commit485f8da4b55ae19f0a21792314ae2b096d48dab4 (patch)
tree5a7402d91175f409330c052980c596a77e813d7a /Software/Visual_Studio/Embroidery
parent9dedf143c3ac44ca593e735861f4e1e2e6f947c9 (diff)
downloadTango-485f8da4b55ae19f0a21792314ae2b096d48dab4.tar.gz
Tango-485f8da4b55ae19f0a21792314ae2b096d48dab4.zip
Implemented Embroidery Editor.
Implemented Create job from embroidery file.
Diffstat (limited to 'Software/Visual_Studio/Embroidery')
-rw-r--r--Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs32
-rw-r--r--Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs20
2 files changed, 44 insertions, 8 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
diff --git a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs
index a45c2a344..385266228 100644
--- a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs
+++ b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs
@@ -21,6 +21,24 @@ namespace Tango.EmbroideryUI
public static readonly DependencyProperty BrushProperty =
DependencyProperty.Register("Brush", typeof(Brush), typeof(EmbroideryPath), new PropertyMetadata(null,(d,e) => (d as EmbroideryPath).OnBrushChanged()));
+ public double Length
+ {
+ get { return (double)GetValue(LengthProperty); }
+ set { SetValue(LengthProperty, value); }
+ }
+ public static readonly DependencyProperty LengthProperty =
+ DependencyProperty.Register("Length", typeof(double), typeof(EmbroideryPath), new PropertyMetadata(0.0));
+
+ public PathFigure PathFigure
+ {
+ get { return (PathFigure)GetValue(PathFigureProperty); }
+ set { SetValue(PathFigureProperty, value); }
+ }
+ public static readonly DependencyProperty PathFigureProperty =
+ DependencyProperty.Register("PathFigure", typeof(PathFigure), typeof(EmbroideryPath), new PropertyMetadata(null));
+
+
+
private void OnBrushChanged()
{
Stroke = Brush;
@@ -38,7 +56,7 @@ namespace Tango.EmbroideryUI
{
if (IsSelected)
{
- Stroke = Brushes.White;
+ Stroke = Brushes.Black;
}
else
{