From 2b8e41b5279c2d3ab370595f6593b64ea734ef87 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 4 Mar 2018 15:28:15 +0200 Subject: Implemented job embroidery image capture, display export, Implemented running job text to speech. --- .../Modules/Tango.MachineStudio.DB/DBModule.cs | 1 + .../DataCaptureModule.cs | 1 + .../Converters/ByteArrayToBitmapSourceConverter.cs | 29 ++++++ .../DeveloperModule.cs | 1 + .../Images/job-emb.png | Bin 0 -> 1626 bytes .../Tango.MachineStudio.Developer.csproj | 17 ++++ .../ViewModels/EmbroideryDisplayViewVM.cs | 38 ++++++++ .../ViewModels/MainViewVM.cs | 98 ++++++++++++++++++--- .../Views/EmbroideryDisplayView.xaml | 51 +++++++++++ .../Views/EmbroideryDisplayView.xaml.cs | 28 ++++++ .../Views/EmbroideryImportView.xaml | 2 +- .../Views/EmbroideryImportView.xaml.cs | 9 ++ .../Views/JobView.xaml | 4 +- .../Views/MachineJobSelectionView.xaml | 25 +++++- .../Views/MainView.xaml | 4 +- .../Modules/Tango.MachineStudio.Developer/bip.wav | Bin 0 -> 161420 bytes .../HardwareDesignerModule.cs | 1 + .../MachineDesignerModule.cs | 1 + .../Tango.MachineStudio.Stubs/StubsModule.cs | 1 + .../SynchronizationModule.cs | 1 + .../TechnicianModule.cs | 1 + 21 files changed, 294 insertions(+), 19 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ByteArrayToBitmapSourceConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/job-emb.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryDisplayViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/bip.wav (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/DBModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/DBModule.cs index 01cbee209..b53f28bd4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/DBModule.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/DBModule.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; using Tango.BL.Entities; +using Tango.BL.Enumerations; using Tango.MachineStudio.Common; using Tango.MachineStudio.DB.Views; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/DataCaptureModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/DataCaptureModule.cs index f3bdb974e..38e82257f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/DataCaptureModule.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/DataCaptureModule.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; using Tango.BL.Entities; +using Tango.BL.Enumerations; using Tango.MachineStudio.Common; using Tango.MachineStudio.DataCapture.Views; using Tango.SharedUI.Helpers; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ByteArrayToBitmapSourceConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ByteArrayToBitmapSourceConverter.cs new file mode 100644 index 000000000..d839b0060 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/ByteArrayToBitmapSourceConverter.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class ByteArrayToBitmapSourceConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + byte[] bytes = value as byte[]; + if (bytes != null) + { + return bytes.ToBitmapSource(); + } + + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs index 0dc35e3bf..9ac8de012 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/DeveloperModule.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; using Tango.BL.Entities; +using Tango.BL.Enumerations; using Tango.MachineStudio.Common; using Tango.MachineStudio.Developer.Views; using Tango.SharedUI.Helpers; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/job-emb.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/job-emb.png new file mode 100644 index 000000000..15f9c73bb Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/job-emb.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 7bf4d22cd..378fb443b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -67,6 +67,7 @@ + ..\..\..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll @@ -82,6 +83,7 @@ ..\..\..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll + ..\..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\System.Windows.Interactivity.dll @@ -105,6 +107,7 @@ + @@ -120,8 +123,12 @@ + + + EmbroideryDisplayView.xaml + EmbroideryImportView.xaml @@ -141,6 +148,10 @@ RunningJobView.xaml + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -336,5 +347,11 @@ + + + + + + \ No newline at end of file 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/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index c265c7d25..76fe33a87 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, 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 /// public RelayCommand ImportEmbroideryFileCommand { get; set; } + /// + /// Gets or sets the display job embroidery file command. + /// + public RelayCommand 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(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!"); } /// @@ -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!"); } /// @@ -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() { 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( - 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.Paths.ToList(), vm.EmbroideryFile, dlg.FileName, view.EmbroideryImageBytes); } }, () => @@ -1609,7 +1649,7 @@ namespace Tango.MachineStudio.Developer.ViewModels } } - private async void AddJobFromEmbroideryFile(String jobName, List paths, EmbroideryFile embroideryFile) + private async void AddJobFromEmbroideryFile(String jobName, List paths, EmbroideryFile embroideryFile, String fileName, byte[] imageBytes) { LogManager.Log(String.Format("Adding new job from embroidery file {0}...", jobName)); @@ -1623,12 +1663,17 @@ namespace Tango.MachineStudio.Developer.ViewModels job.SpoolType = _machineDbContext.SpoolTypes.FirstOrDefault(); job.Machine = SelectedMachine; + job.EmbroideryFileName = Path.GetFileName(fileName); + job.EmbroideryFileData = File.ReadAllBytes(fileName); + job.EmbroideryJpeg = imageBytes; + job.HasEmbroideryFile = true; + foreach (var path in paths.Skip(1)) { Segment segment = new Segment(); segment.Length = path.Length / 1000d; segment.Name = "Embroidery Segment"; - segment.SegmentIndex = paths.IndexOf(path) + 1; + segment.SegmentIndex = paths.IndexOf(path) + 2; if (path.Brush is SolidColorBrush) { @@ -1639,7 +1684,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 +1700,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 +1715,35 @@ namespace Tango.MachineStudio.Developer.ViewModels LoadSelectedJob(); } + private void DisplayJobEmbroideryFile(Job job) + { + _notification.ShowModalDialog(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 diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml new file mode 100644 index 000000000..a753453f9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml.cs new file mode 100644 index 000000000..7d0771098 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryDisplayView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Developer.Views +{ + /// + /// Interaction logic for EmbroideryDisplayView.xaml + /// + public partial class EmbroideryDisplayView : UserControl + { + public EmbroideryDisplayView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml index 220e7d3ab..d084aabcf 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml @@ -47,7 +47,7 @@ - public partial class EmbroideryImportView : UserControl { + public byte[] EmbroideryImageBytes { get; set; } + public EmbroideryImportView() { InitializeComponent(); } + + private void OnImportClick(object sender, RoutedEventArgs e) + { + var source = UIHelper.TakeSnapshot(editor); + EmbroideryImageBytes = source.ToJpegBytes(50); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 9ba41f688..1dea01de7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -438,13 +438,13 @@ - -