diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index c2637b527..a76799881 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -20,6 +20,7 @@ using Tango.MachineStudio.RML.Models; using Tango.MachineStudio.RML.Views; using Tango.PMR.ColorLab; using System.Data.Entity; +using Tango.Core.ExtensionMethods; namespace Tango.MachineStudio.RML.ViewModels { @@ -178,11 +179,14 @@ namespace Tango.MachineStudio.RML.ViewModels public RelayCommand SaveCommand { get; set; } + public RelayCommand CloneRmlCommand { get; set; } + public MainViewVM(INotificationProvider notificationProvider) { _notification = notificationProvider; ManageRmlCommand = new RelayCommand(() => LoadActiveRML(SelectedRML.Guid), () => SelectedRML != null); - RemoveRmlCommand = new RelayCommand(RemoveSelectedRml); + RemoveRmlCommand = new RelayCommand(RemoveSelectedRml, () => SelectedRML != null); + CloneRmlCommand = new RelayCommand(CloneSelectedRml, () => SelectedRML != null); AddRmlCommand = new RelayCommand(AddNewRml); BackToRmlsCommand = new RelayCommand(BackToRmls, () => IsFree); AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable, () => IsFree); @@ -443,6 +447,74 @@ namespace Tango.MachineStudio.RML.ViewModels } } + private async void CloneSelectedRml() + { + String name = _notification.ShowTextInput("Enter thread name", "thread name"); + + if (!String.IsNullOrWhiteSpace(name)) + { + using (_notification.PushTaskItem("Cloning thread...")) + { + try + { + IsFree = false; + + using (var context = ObservablesContext.CreateDefault()) + { + var rml = await new RmlBuilder(context).Set(SelectedRML.Guid).WithActiveParametersGroup().WithLiquidFactors().BuildAsync(); + + Rml cloned = new Rml(); + rml.MapPrimitivesWithStrings(cloned); + + cloned.Code = Rmls.Max(x => x.Code) + 1; + cloned.Guid = Guid.NewGuid().ToString(); + cloned.ID = 0; + cloned.Name = name; + + ProcessParametersTablesGroup group = new ProcessParametersTablesGroup(); + group.Name = rml.GetActiveProcessGroup().Name; + group.Active = true; + + foreach (var p in rml.GetActiveProcessGroup().ProcessParametersTables) + { + var pc = new ProcessParametersTable(); + p.MapPrimitivesTo(pc); + pc.Name = p.Name; + + group.ProcessParametersTables.Add(pc); + } + + cloned.ProcessParametersTablesGroups.Add(group); + + foreach (var liquidFactor in rml.LiquidTypesRmls) + { + LiquidTypesRml l = new LiquidTypesRml(); + l.DefaultCatData = liquidFactor.DefaultCatData; + l.LiquidType = liquidFactor.LiquidType; + l.MaxNlPerCm = liquidFactor.MaxNlPerCm; + cloned.LiquidTypesRmls.Add(l); + } + + context.Rmls.Add(cloned); + await context.SaveChangesAsync(); + } + + LoadRmls(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error cloning thread."); + _notification.ShowError($"An error occurred while trying to clone the selected thread\n{ex.Message}"); + } + finally + { + IsFree = true; + } + } + + } + } + private void AddProcessParametersTable() { var name = _notification.ShowTextInput("Enter table name", "Name"); |
