aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2018-03-06 12:11:22 +0200
committerShlomo Hecht <shlomo@twine-s.com>2018-03-06 12:11:22 +0200
commit99715aa1c659a3d5d7709cb16d5dfe1b1c29a135 (patch)
treed003fe1c07117036039294ffc8b6ba51096938d4 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels
parentce68bf700e2e6535e1ed155fe2806c1ed6030edd (diff)
parent7e6c673cc8b04086fa3c78cd1bf5e31085fd8cc8 (diff)
downloadTango-99715aa1c659a3d5d7709cb16d5dfe1b1c29a135.tar.gz
Tango-99715aa1c659a3d5d7709cb16d5dfe1b1c29a135.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryDisplayViewVM.cs38
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryImportViewVM.cs42
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs113
3 files changed, 179 insertions, 14 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryDisplayViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryDisplayViewVM.cs
new file mode 100644
index 000000000..74cb2ffa6
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryDisplayViewVM.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.Entities;
+using Tango.Core.Commands;
+using Tango.MachineStudio.Common.Notifications;
+using Tango.SharedUI;
+
+namespace Tango.MachineStudio.Developer.ViewModels
+{
+ public class EmbroideryDisplayViewVM : DialogViewVM
+ {
+ private Job _job;
+
+ public Job Job
+ {
+ get { return _job; }
+ set { _job = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand ExportCommand { get; set; }
+
+ public EmbroideryDisplayViewVM()
+ {
+ ExportCommand = new RelayCommand(() =>
+ {
+ Accept();
+ });
+ }
+
+ public EmbroideryDisplayViewVM(Job job) : this()
+ {
+ Job = job;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryImportViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryImportViewVM.cs
index a0f4314dc..eaffab9e5 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryImportViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryImportViewVM.cs
@@ -27,8 +27,50 @@ namespace Tango.MachineStudio.Developer.ViewModels
public ObservableCollection<EmbroideryPath> Paths { get; set; }
+ public List<IEmbroideryMaterial> EmbroideryMaterials { get; set; }
+
+ private IEmbroideryMaterial _selectedEmbroideryMaterial;
+ public IEmbroideryMaterial SelectedEmbroideryMaterial
+ {
+ get { return _selectedEmbroideryMaterial; }
+ set { _selectedEmbroideryMaterial = value; RaisePropertyChangedAuto(); }
+ }
+
+ private IEmbroideryMaterial _selectedStabilizer;
+ public IEmbroideryMaterial SelectedStabilizer
+ {
+ get { return _selectedStabilizer; }
+ set { _selectedStabilizer = value; RaisePropertyChangedAuto(); }
+ }
+
+ private double _embroideryMaterialThickness;
+ public double EmbroideryMaterialThickness
+ {
+ get { return _embroideryMaterialThickness; }
+ set { _embroideryMaterialThickness = value; RaisePropertyChangedAuto(); }
+ }
+
+ private double _stabilizerThickness;
+ public double StabilizerThickness
+ {
+ get { return _stabilizerThickness; }
+ set { _stabilizerThickness = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _hasStabilizer;
+ public bool HasStabilizer
+ {
+ get { return _hasStabilizer; }
+ set { _hasStabilizer = value; RaisePropertyChangedAuto(); }
+ }
+
public EmbroideryImportViewVM() : base()
{
+ EmbroideryMaterials = EmbroideryMaterialsHelper.GetAvailableEmbroideryMaterials();
+ SelectedEmbroideryMaterial = EmbroideryMaterials.FirstOrDefault();
+ SelectedStabilizer = EmbroideryMaterials.FirstOrDefault();
+ EmbroideryMaterialThickness = 1;
+ StabilizerThickness = 1;
ImportCommand = new RelayCommand(Import);
}
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
index c265c7d25..566dc7a16 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
@@ -28,6 +28,11 @@ using Tango.BL;
using Microsoft.Win32;
using Tango.PMR.Embroidery;
using Tango.EmbroideryUI;
+using System.IO;
+using System.Windows;
+using Tango.Core.Helpers;
+using System.Speech.Synthesis;
+using System.Media;
namespace Tango.MachineStudio.Developer.ViewModels
{
@@ -38,7 +43,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
public class MainViewVM : ViewModel<IMainView>, IShutdownRequestBlocker, IShutdownListener
{
private static object _syncLock = new object();
- private const string EMB_FORMATS = "Embroidery Files|*.pes;*.hus";
+ private const string EMB_FORMATS_EXPORT = "Baby Lock (PES)|*.pes|Tajima (DST)|*.dst|EXP|*.exp|PCS|*.pcs|HUS|*.hus|KSM|*.ksm";
+ private const string EMB_FORMATS_IMPORT = "Embroidery Files|*.pes;*.hus;*.dst";
private INotificationProvider _notification;
private TimeSpan _runningJobEstimatedDuration;
@@ -49,6 +55,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
private ObservablesContext _machineDbContext;
private ObservablesContext _activeJobDbContext;
private LogManager LogManager = LogManager.Default;
+ private SpeechSynthesizer _speech;
+ private SoundPlayer _soundPlayer;
#region Properties
@@ -577,6 +585,10 @@ namespace Tango.MachineStudio.Developer.ViewModels
/// </summary>
public RelayCommand ImportEmbroideryFileCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the display job embroidery file command.
+ /// </summary>
+ public RelayCommand<Job> DisplayJobEmbroideryFileCommand { get; set; }
#endregion
#region Constructors
@@ -625,6 +637,10 @@ namespace Tango.MachineStudio.Developer.ViewModels
LogManager.Log("Initializing relay commands...");
+ _speech = new SpeechSynthesizer();
+ _soundPlayer = new SoundPlayer(EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Developer.bip.wav"));
+ _speech.SelectVoice(_speech.GetInstalledVoices().LastOrDefault(x => x.VoiceInfo.Gender == VoiceGender.Female).VoiceInfo.Name);
+
//Initialize Commands...
EditMachineCommand = new RelayCommand(EditMachine, () => SelectedMachine != null);
EditRMLCommand = new RelayCommand(EditRML, () => SelectedRML != null);
@@ -648,6 +664,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
SaveProcessParametersCommand = new RelayCommand(SaveProcessParameters, () => SelectedRML != null && SelectedRML.ProcessParametersTablesGroups.Count > 0);
PushProcessParametersCommand = new RelayCommand(PushProcessParameters, () => SelectedRML != null && SelectedRML.ProcessParametersTablesGroups.Count > 0 && SelectedProcessParametersTable != null && MachineOperator != null);
ImportEmbroideryFileCommand = new RelayCommand(ImportEmbroideryFile, () => SelectedMachine != null);
+ DisplayJobEmbroideryFileCommand = new RelayCommand<Job>(DisplayJobEmbroideryFile);
ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged;
}
@@ -891,6 +908,9 @@ namespace Tango.MachineStudio.Developer.ViewModels
LogManager.Log("Setting job failed state...");
IsJobRunning = false;
IsJobFailed = true;
+
+ _soundPlayer.Play();
+ _speech.SpeakAsync("Job Failed!");
}
/// <summary>
@@ -901,6 +921,8 @@ namespace Tango.MachineStudio.Developer.ViewModels
LogManager.Log("Setting job completed state...");
IsJobRunning = false;
IsJobCompleted = true;
+ _soundPlayer.Play();
+ _speech.SpeakAsync("Job Completed!");
}
/// <summary>
@@ -958,12 +980,27 @@ namespace Tango.MachineStudio.Developer.ViewModels
}
if (remaining < segmentDuration)
{
- segment.Started = true;
+ if (!segment.Started)
+ {
+ segment.Started = true;
+ _soundPlayer.Play();
+
+ if (segment.ID != -1)
+ {
+ _speech.SpeakAsync(String.Format("Segment {0} Started.", segment.SegmentIndex));
+ }
+ else
+ {
+ _speech.SpeakAsync(String.Format("Inter Segment Started."));
+ }
+ }
}
if (remaining <= TimeSpan.Zero)
{
- segment.Completed = true;
- segment.Started = false;
+ if (!segment.Completed)
+ {
+ segment.Completed = true;
+ }
}
}
};
@@ -1020,6 +1057,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
segments.Add(new Segment()
{
Length = job.InterSegmentLength,
+ ID = -1,
BrushStops = new System.Collections.ObjectModel.ObservableCollection<BrushStop>()
{
new BrushStop()
@@ -1588,18 +1626,20 @@ namespace Tango.MachineStudio.Developer.ViewModels
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Select embroidery file";
- dlg.Filter = EMB_FORMATS;
- if (dlg.ShowDialog().Value)
+ dlg.Filter = EMB_FORMATS_IMPORT;
+ if (dlg.ShowDialogCenter())
{
+ var view = new EmbroideryImportView();
+
_notification.ShowModalDialog<EmbroideryImportViewVM, EmbroideryImportView>(
- new EmbroideryImportViewVM() { FileName = dlg.FileName },
+ new EmbroideryImportViewVM() { FileName = dlg.FileName }, view,
(vm) =>
{
String jobName = _notification.ShowTextInput("Please provide a job name", "Name");
if (jobName != null)
{
- AddJobFromEmbroideryFile(jobName, vm.Paths.ToList(), vm.EmbroideryFile);
+ AddJobFromEmbroideryFile(jobName, vm, dlg.FileName, view.EmbroideryImageBytes);
}
},
() =>
@@ -1609,7 +1649,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
}
}
- private async void AddJobFromEmbroideryFile(String jobName, List<EmbroideryPath> paths, EmbroideryFile embroideryFile)
+ private async void AddJobFromEmbroideryFile(String jobName, EmbroideryImportViewVM vm, String fileName, byte[] imageBytes)
{
LogManager.Log(String.Format("Adding new job from embroidery file {0}...", jobName));
@@ -1623,12 +1663,28 @@ namespace Tango.MachineStudio.Developer.ViewModels
job.SpoolType = _machineDbContext.SpoolTypes.FirstOrDefault();
job.Machine = SelectedMachine;
- foreach (var path in paths.Skip(1))
+ job.EmbroideryFileName = Path.GetFileName(fileName);
+ job.EmbroideryFileData = File.ReadAllBytes(fileName);
+ job.EmbroideryJpeg = imageBytes;
+ job.HasEmbroideryFile = true;
+
+ foreach (var path in vm.Paths.Skip(1))
{
Segment segment = new Segment();
- segment.Length = path.Length / 1000d;
+
+ double baseLength = path.Length / 1000d;
+ double embThicknessLength = (vm.EmbroideryMaterialThickness * path.StitchCount) / 1000d;
+ double stabilizerThicknessLength = (vm.StabilizerThickness * path.StitchCount) / 1000d;
+ double totalLength = (baseLength + embThicknessLength) * vm.SelectedEmbroideryMaterial.Coefficient;
+
+ if (vm.HasStabilizer)
+ {
+ totalLength += (stabilizerThicknessLength * vm.SelectedStabilizer.Coefficient);
+ }
+
+ segment.Length = totalLength;
segment.Name = "Embroidery Segment";
- segment.SegmentIndex = paths.IndexOf(path) + 1;
+ segment.SegmentIndex = vm.Paths.IndexOf(path) + 2;
if (path.Brush is SolidColorBrush)
{
@@ -1639,7 +1695,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
Red = brush.Color.R,
Green = brush.Color.G,
Blue = brush.Color.B,
- ColorSpace = _machineDbContext.ColorSpaces.ToList().SingleOrDefault(x => x.Code == BL.Entities.ColorSpaces.RGB.ToInt32()),
+ ColorSpace = _machineDbContext.ColorSpaces.ToList().SingleOrDefault(x => x.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32()),
});
}
else
@@ -1655,7 +1711,7 @@ namespace Tango.MachineStudio.Developer.ViewModels
Green = stop.Color.G,
Blue = stop.Color.B,
OffsetPercent = stop.Offset,
- ColorSpace = _machineDbContext.ColorSpaces.ToList().SingleOrDefault(x => x.Code == BL.Entities.ColorSpaces.RGB.ToInt32()),
+ ColorSpace = _machineDbContext.ColorSpaces.ToList().SingleOrDefault(x => x.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32()),
});
}
}
@@ -1670,6 +1726,35 @@ namespace Tango.MachineStudio.Developer.ViewModels
LoadSelectedJob();
}
+ private void DisplayJobEmbroideryFile(Job job)
+ {
+ _notification.ShowModalDialog<EmbroideryDisplayViewVM, EmbroideryDisplayView>(new EmbroideryDisplayViewVM(job), (vm) =>
+ {
+
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.Title = "Select embroidery file location and format";
+ dlg.Filter = EMB_FORMATS_EXPORT;
+ dlg.FileName = job.EmbroideryFileName;
+ if (dlg.ShowDialogCenter())
+ {
+ try
+ {
+ String tempPath = PathHelper.GetTempFolderPath();
+ String filePath = Path.Combine(tempPath, job.EmbroideryFileName);
+ File.WriteAllBytes(filePath, job.EmbroideryFileData);
+ EmbroideryFileConverter.ConvertEmbroideryFile(filePath, dlg.FileName);
+ _notification.ShowInfo("Embroidery file exported successfully.");
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "An error has occurred while trying to export the attached embroidery file.");
+ _notification.ShowError("An error has occurred while trying to export the attached embroidery file.");
+ }
+ }
+
+ }, () => { });
+ }
+
#endregion
#region Override Methods