aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs105
1 files changed, 104 insertions, 1 deletions
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<IMainView>, 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
/// </summary>
public RelayCommand PushProcessParametersCommand { get; set; }
+ /// <summary>
+ /// Gets or sets the import embroidery file command.
+ /// </summary>
+ 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
+
+ /// <summary>
+ /// Imports embroidery file.
+ /// </summary>
+ private void ImportEmbroideryFile()
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Title = "Select embroidery file";
+ dlg.Filter = EMB_FORMATS;
+ if (dlg.ShowDialog().Value)
+ {
+ _notification.ShowModalDialog<EmbroideryImportViewVM, EmbroideryImportView>(
+ 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<EmbroideryPath> 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)