From a2fcd642758c9506188160856a0f9cc0dc48be38 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 7 Oct 2018 13:05:29 +0300 Subject: Working on RML module. --- .../Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs') 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 be46e2148..9e8286fa5 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 @@ -210,15 +210,12 @@ namespace Tango.MachineStudio.RML.ViewModels ActiveProcessParametersTableView = CollectionViewSource.GetDefaultView(ActiveProcessParametersGroup.ProcessParametersTables); ActiveProcessParametersTableView.SortDescriptions.Add(new SortDescription(nameof(ProcessParametersTable.TableIndex), ListSortDirection.Ascending)); - CalibrationDataViewVM = new CalibrationDataViewVM(); + CalibrationDataViewVM = new CalibrationDataViewVM(_notification); LiquidTypesRmls = ActiveRML.LiquidTypesRmls; foreach (var liquidTypeRml in LiquidTypesRmls) { - CalibrationDataVM catVM = new CalibrationDataVM(); - catVM.Name = liquidTypeRml.LiquidType.Name; - catVM.Color = liquidTypeRml.LiquidType.Color; - catVM.LiquidType = liquidTypeRml.LiquidType; + CalibrationDataVM catVM = new CalibrationDataVM(liquidTypeRml.LiquidType); if (liquidTypeRml.DefaultCatData != null) { @@ -359,9 +356,7 @@ namespace Tango.MachineStudio.RML.ViewModels _active_context.LiquidTypesRmls.Add(liquidFactor); - CalibrationDataVM catVM = new CalibrationDataVM(); - catVM.Name = liquidFactor.LiquidType.Name; - catVM.Color = liquidFactor.LiquidType.Color; + CalibrationDataVM catVM = new CalibrationDataVM(liquidFactor.LiquidType); CalibrationDataViewVM.LiquidsCalibrationData.Add(catVM); -- cgit v1.3.1 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 !!!!!!! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes .../ViewModels/MainViewVM.cs | 116 ++++++++++++++++++--- .../Tango.MachineStudio.RML/Views/RmlView.xaml | 7 ++ .../Tango.MachineStudio.RML/Views/RmlsView.xaml | 44 +++++++- .../Visual_Studio/Tango.BL/Builders/RmlBuilder.cs | 6 +- .../Tango.BL/Builders/RmlsCollectionBuilder.cs | 16 ++- 7 files changed, 167 insertions(+), 22 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index d52564e7f..1df70c623 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 61a924927..613fd4ca7 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ 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 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.BL/Builders/RmlBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/RmlBuilder.cs index 0fe653a67..a67a2cf7a 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/RmlBuilder.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/RmlBuilder.cs @@ -34,7 +34,11 @@ namespace Tango.BL.Builders return AddStep(2, () => { var group = Context.ProcessParametersTablesGroups.Where(x => x.RmlGuid == Entity.Guid && x.Active).FirstOrDefault(); - Context.ProcessParametersTables.Where(x => x.ProcessParametersTablesGroupGuid == group.Guid).OrderBy(x => x.TableIndex).ToList(); + + if (group != null) + { + Context.ProcessParametersTables.Where(x => x.ProcessParametersTablesGroupGuid == group.Guid).OrderBy(x => x.TableIndex).ToList(); + } }); } diff --git a/Software/Visual_Studio/Tango.BL/Builders/RmlsCollectionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/RmlsCollectionBuilder.cs index 9fb84fcc0..d6eabbae4 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/RmlsCollectionBuilder.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/RmlsCollectionBuilder.cs @@ -69,9 +69,23 @@ namespace Tango.BL.Builders { foreach (var rml in Entities.ToList()) { - Context.LiquidTypesRmls.Where(x => x.RmlGuid == rml.Guid).ToList(); + Context.LiquidTypesRmls.Where(x => x.RmlGuid == rml.Guid).Include(x => x.LiquidType).OrderBy(x => x.LiquidType.Code).ToList(); } }); } + + public virtual RmlsCollectionBuilder WithMediaProperties() + { + return AddStep(6, () => + { + Context.MediaMaterials.ToList(); + Context.MediaColors.ToList(); + Context.MediaPurposes.ToList(); + Context.MediaConditions.ToList(); + Context.LinearMassDensityUnits.ToList(); + Context.FiberShapes.ToList(); + Context.FiberSynths.ToList(); + }); + } } } -- cgit v1.3.1