From 485f8da4b55ae19f0a21792314ae2b096d48dab4 Mon Sep 17 00:00:00 2001 From: Roy Date: Sun, 4 Mar 2018 02:26:30 +0200 Subject: Implemented Embroidery Editor. Implemented Create job from embroidery file. --- .../Images/sewing-machine.png | Bin 0 -> 1655 bytes .../Tango.MachineStudio.Developer.csproj | 19 ++++ .../ViewModels/EmbroideryImportViewVM.cs | 40 ++++++++ .../ViewModels/MainViewVM.cs | 105 ++++++++++++++++++++- .../Views/EmbroideryImportView.xaml | 59 ++++++++++++ .../Views/EmbroideryImportView.xaml.cs | 28 ++++++ .../Views/JobView.xaml | 8 +- .../Views/JobView.xaml.cs | 2 + .../Views/MachineJobSelectionView.xaml | 12 ++- 9 files changed, 266 insertions(+), 7 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/sewing-machine.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryImportViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/sewing-machine.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/sewing-machine.png new file mode 100644 index 000000000..3d2864fc3 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Images/sewing-machine.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 8c9f297a3..7bf4d22cd 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 @@ -120,7 +120,11 @@ + + + EmbroideryImportView.xaml + MainView.xaml @@ -137,6 +141,10 @@ RunningJobView.xaml + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -180,6 +188,10 @@ + + {bdbbe284-f564-4f51-af41-3df0434cec62} + Tango.EmbroideryUI + {37e4ceab-b54b-451f-b535-04cf7da9c459} ColorMine @@ -192,6 +204,10 @@ {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL + + {40085232-aced-4cbe-945b-90ba8153c151} + Tango.BrushPicker + {a2f5af44-29ff-45d6-9d25-ecda5cce88b5} Tango.ColorPicker @@ -317,5 +333,8 @@ + + + \ No newline at end of file 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 new file mode 100644 index 000000000..a0f4314dc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/EmbroideryImportViewVM.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.EmbroideryUI; +using Tango.MachineStudio.Common.Notifications; +using Tango.PMR.Embroidery; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class EmbroideryImportViewVM : DialogViewVM + { + private String _fileName; + + public String FileName + { + get { return _fileName; } + set { _fileName = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand ImportCommand { get; set; } + + public EmbroideryFile EmbroideryFile { get; set; } + + public ObservableCollection Paths { get; set; } + + public EmbroideryImportViewVM() : base() + { + ImportCommand = new RelayCommand(Import); + } + + private void Import() + { + Accept(); + } + } +} 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 31c20eda4..c265c7d25 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 @@ -25,6 +25,9 @@ using Tango.Settings; using Tango.SharedUI; using Tango.Transport; using Tango.BL; +using Microsoft.Win32; +using Tango.PMR.Embroidery; +using Tango.EmbroideryUI; namespace Tango.MachineStudio.Developer.ViewModels { @@ -35,6 +38,7 @@ 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 INotificationProvider _notification; private TimeSpan _runningJobEstimatedDuration; @@ -568,6 +572,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public RelayCommand PushProcessParametersCommand { get; set; } + /// + /// Gets or sets the import embroidery file command. + /// + public RelayCommand ImportEmbroideryFileCommand { get; set; } + #endregion #region Constructors @@ -638,6 +647,7 @@ namespace Tango.MachineStudio.Developer.ViewModels DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null); 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); ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; } @@ -1438,7 +1448,7 @@ namespace Tango.MachineStudio.Developer.ViewModels Job newJob = new Job(); newJob.Name = jobName; newJob.CreationDate = DateTime.UtcNow; - newJob.User = _authentication.CurrentUser; + newJob.UserGuid = _authentication.CurrentUser.Guid; newJob.Rml = _machineDbContext.Rmls.FirstOrDefault(); newJob.WindingMethod = _machineDbContext.WindingMethods.FirstOrDefault(); newJob.SpoolType = _machineDbContext.SpoolTypes.FirstOrDefault(); @@ -1569,6 +1579,99 @@ namespace Tango.MachineStudio.Developer.ViewModels #endregion + #region Embroidery + + /// + /// Imports embroidery file. + /// + private void ImportEmbroideryFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select embroidery file"; + dlg.Filter = EMB_FORMATS; + if (dlg.ShowDialog().Value) + { + _notification.ShowModalDialog( + new EmbroideryImportViewVM() { FileName = dlg.FileName }, + (vm) => + { + String jobName = _notification.ShowTextInput("Please provide a job name", "Name"); + + if (jobName != null) + { + AddJobFromEmbroideryFile(jobName, vm.Paths.ToList(), vm.EmbroideryFile); + } + }, + () => + { + + }); + } + } + + private async void AddJobFromEmbroideryFile(String jobName, List paths, EmbroideryFile embroideryFile) + { + LogManager.Log(String.Format("Adding new job from embroidery file {0}...", jobName)); + + Job job = new Job(); + job.Name = jobName; + job.Name = jobName; + job.CreationDate = DateTime.UtcNow; + job.UserGuid = _authentication.CurrentUser.Guid; + job.Rml = _machineDbContext.Rmls.FirstOrDefault(); + job.WindingMethod = _machineDbContext.WindingMethods.FirstOrDefault(); + job.SpoolType = _machineDbContext.SpoolTypes.FirstOrDefault(); + job.Machine = SelectedMachine; + + 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; + + if (path.Brush is SolidColorBrush) + { + var brush = (path.Brush as SolidColorBrush); + + segment.BrushStops.Add(new BrushStop() + { + 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()), + }); + } + else + { + var brush = (path.Brush as LinearGradientBrush); + + foreach (var stop in brush.GradientStops) + { + segment.BrushStops.Add(new BrushStop() + { + StopIndex = brush.GradientStops.IndexOf(stop), + Red = stop.Color.R, + Green = stop.Color.G, + Blue = stop.Color.B, + OffsetPercent = stop.Offset, + ColorSpace = _machineDbContext.ColorSpaces.ToList().SingleOrDefault(x => x.Code == BL.Entities.ColorSpaces.RGB.ToInt32()), + }); + } + } + + job.Segments.Add(segment); + } + + SelectedMachine.Jobs.Add(job); + LogManager.Log("Saving selected machine to database..."); + await SelectedMachine.SaveAsync(_machineDbContext); + SelectedMachineJob = job; + LoadSelectedJob(); + } + + #endregion + #region Override Methods protected override void RaisePropertyChangedAuto([CallerMemberName] string caller = null) 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 new file mode 100644 index 000000000..220e7d3ab --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + Import Embroidery File + + + + + + + + + + + + + + Region Brush + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.xaml.cs new file mode 100644 index 000000000..c34b6fef7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/EmbroideryImportView.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 EmbroideryImportDialog.xaml + /// + public partial class EmbroideryImportView : UserControl + { + public EmbroideryImportView() + { + InitializeComponent(); + } + } +} 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 49444750f..9ba41f688 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 @@ -377,7 +377,7 @@ - + @@ -385,7 +385,7 @@ - + @@ -1102,7 +1102,7 @@ - + @@ -1128,7 +1128,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs index b2ca55217..905caa96d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -18,6 +18,7 @@ using Tango.DragAndDrop; using Tango.BL.Entities; using Tango.MachineStudio.Developer.Converters; using Tango.MachineStudio.Developer.ViewModels; +using Tango.BL; namespace Tango.MachineStudio.Developer.Views { @@ -72,6 +73,7 @@ namespace Tango.MachineStudio.Developer.Views { new BrushStop() { + ColorSpace = new ColorSpace(), Color = Colors.White, } }, diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml index 49735d345..2115f2503 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml @@ -88,6 +88,7 @@ + -- cgit v1.3.1