From bdfe1503bafb8634d29f7229a8b5378d472ac540 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 7 Oct 2018 15:41:33 +0300 Subject: Completed RML Module !!!!!!! --- .../ViewModels/MainViewVM.cs | 116 ++++++++++++++++++--- .../Tango.MachineStudio.RML/Views/RmlView.xaml | 7 ++ .../Tango.MachineStudio.RML/Views/RmlsView.xaml | 44 +++++++- 3 files changed, 147 insertions(+), 20 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') 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 9e8286fa5..70073ad62 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 @@ -1,4 +1,5 @@ -using System; +using Microsoft.Win32; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -8,6 +9,7 @@ using System.Threading.Tasks; using System.Windows.Data; using Tango.BL; using Tango.BL.Builders; +using Tango.BL.Calibration; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.MachineStudio.ColorLab.ViewModels; @@ -15,6 +17,7 @@ using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.RML.Contracts; using Tango.MachineStudio.RML.Views; +using Tango.PMR.ColorLab; namespace Tango.MachineStudio.RML.ViewModels { @@ -154,18 +157,21 @@ namespace Tango.MachineStudio.RML.ViewModels /// public RelayCommand BackToRmlsCommand { get; set; } + public RelayCommand SaveCommand { get; set; } + public MainViewVM(INotificationProvider notificationProvider) { _notification = notificationProvider; ManageRmlCommand = new RelayCommand(() => LoadActiveRML(SelectedRML.Guid), () => SelectedRML != null); RemoveRmlCommand = new RelayCommand(RemoveSelectedRml); AddRmlCommand = new RelayCommand(AddNewRml); - BackToRmlsCommand = new RelayCommand(BackToRmls); - AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable); - RemoveProcessParametersTableCommand = new RelayCommand(RemoveProcessParametersTable); - AddLiquidFactorCommand = new RelayCommand(AddLiquidFactor); - RemoveLiquidFactorCommand = new RelayCommand(RemoveLiquidFactor); + BackToRmlsCommand = new RelayCommand(BackToRmls, () => IsFree); + AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable, () => IsFree); + RemoveProcessParametersTableCommand = new RelayCommand(RemoveProcessParametersTable, () => IsFree); + AddLiquidFactorCommand = new RelayCommand(AddLiquidFactor, () => IsFree); + RemoveLiquidFactorCommand = new RelayCommand(RemoveLiquidFactor, () => IsFree); CreateCalibrationDataExcelTemplateCommand = new RelayCommand(CreateCalibrationDataExcelTemplate); + SaveCommand = new RelayCommand(Save, () => IsFree); } public override void OnApplicationReady() @@ -175,13 +181,10 @@ namespace Tango.MachineStudio.RML.ViewModels private async void LoadRmls() { - using (_rmls_context = ObservablesContext.CreateDefault()) - { - await Task.Factory.StartNew(() => - { - Rmls = _rmls_context.Rmls.ToList().ToObservableCollection(); - }); - } + if (_rmls_context != null) _rmls_context.Dispose(); + + _rmls_context = ObservablesContext.CreateDefault(); + Rmls = await new RmlsCollectionBuilder(_rmls_context).Set().WithLiquidFactors().WithMediaProperties().BuildAsync(); } private async void LoadActiveRML(String guid) @@ -264,6 +267,8 @@ namespace Tango.MachineStudio.RML.ViewModels _active_context.Dispose(); } + _active_context = ObservablesContext.CreateDefault(); + LoadRmlProperties(); Rml rml = new Rml(); @@ -277,6 +282,19 @@ namespace Tango.MachineStudio.RML.ViewModels rml.LinearMassDensityUnit = LinearMassDensityUnits.FirstOrDefault(); rml.FiberShape = FiberShapes.FirstOrDefault(); rml.FiberSynth = FiberSynths.FirstOrDefault(); + + ProcessParametersTablesGroup group = new ProcessParametersTablesGroup(); + group.Name = "Active Group"; + group.Active = true; + group.ProcessParametersTables.Add(new ProcessParametersTable() + { + Name = "Process Table 1", + }); + + group.Rml = rml; + + _active_context.ProcessParametersTablesGroups.Add(group); + _active_context.ProcessParametersTables.Add(group.ProcessParametersTables[0]); _active_context.Rmls.Add(rml); await _active_context.SaveChangesAsync(); LoadActiveRML(rml.Guid); @@ -286,9 +304,28 @@ namespace Tango.MachineStudio.RML.ViewModels } } - private void RemoveSelectedRml() + private async void RemoveSelectedRml() { + if (_notification.ShowQuestion("Removing the selected RML will result in the loss of all related process parameters and default calibration data. Are you sure you want to delete the selected RML?")) + { + IsFree = false; + using (_notification.PushTaskItem("Removing RML...")) + { + try + { + await SelectedRML.DeleteCascadeAsync(_rmls_context); + LoadRmls(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error removing selected RML {SelectedRML.Name}."); + _notification.ShowError($"An error occurred while trying to remove the selected RML.\n{ex.Message}"); + } + } + + IsFree = true; + } } private void AddProcessParametersTable() @@ -379,7 +416,56 @@ namespace Tango.MachineStudio.RML.ViewModels private void CreateCalibrationDataExcelTemplate() { - + SaveFileDialog dlg = new SaveFileDialog(); + try + { + dlg.Title = $"Create excel template file"; + dlg.Filter = "Excel Files|*.xlsx"; + dlg.DefaultExt = ".xlsx"; + dlg.FileName = "Calibration File Template"; + if (dlg.ShowDialog().Value) + { + CalibrationHelper.CreateCalibrationDataExcelTemplate(dlg.FileName); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error generating excel calibration template file " + dlg.FileName); + _notification.ShowError("An error occurred while trying to generate the calibration file."); + } + } + + private async void Save() + { + IsFree = false; + + try + { + using (_notification.PushTaskItem("Saving RML...")) + { + foreach (var calDataVM in CalibrationDataViewVM.LiquidsCalibrationData) + { + var liquidTypeRml = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType == calDataVM.LiquidType); + CalibrationData calData = new CalibrationData(); + calData.LiquidType = (PMR.ColorLab.LiquidType)liquidTypeRml.LiquidType.Code; + calData.CalibrationPoints.AddRange(calDataVM.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y })); + liquidTypeRml.PutCalibrationData(calData); + } + + ActiveRML.LastUpdated = DateTime.UtcNow; + + await _active_context.SaveChangesAsync(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error saving RML {ActiveRML.Name}"); + _notification.ShowError($"An error occurred while trying to save the current RML.\n{ex.Message}"); + } + + LoadActiveRML(ActiveRML.Guid); + + IsFree = true; } private void BackToRmls() diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml index 2ddd060f8..d72b6c7d3 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlView.xaml @@ -31,6 +31,13 @@ + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml index b597c1dd2..06a28c1e4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml @@ -4,7 +4,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:global="clr-namespace:Tango.MachineStudio.RML" + xmlns:observables="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:vm="clr-namespace:Tango.MachineStudio.RML.ViewModels" + xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.MachineStudio.RML.Views" @@ -13,6 +15,7 @@ + @@ -38,8 +41,8 @@ @@ -54,9 +57,40 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.3.1