aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-10-07 15:41:33 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-10-07 15:41:33 +0300
commitbdfe1503bafb8634d29f7229a8b5378d472ac540 (patch)
treec9c36e94bca4d93202ada0f25830972e7d856dd1 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels
parente32bafa30d3b5bf083851196b0c9b94202628a6c (diff)
downloadTango-bdfe1503bafb8634d29f7229a8b5378d472ac540.tar.gz
Tango-bdfe1503bafb8634d29f7229a8b5378d472ac540.zip
Completed RML Module !!!!!!!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs116
1 files changed, 101 insertions, 15 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 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
/// </summary>
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<ProcessParametersTable>(RemoveProcessParametersTable);
- AddLiquidFactorCommand = new RelayCommand(AddLiquidFactor);
- RemoveLiquidFactorCommand = new RelayCommand<LiquidTypesRml>(RemoveLiquidFactor);
+ BackToRmlsCommand = new RelayCommand(BackToRmls, () => IsFree);
+ AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable, () => IsFree);
+ RemoveProcessParametersTableCommand = new RelayCommand<ProcessParametersTable>(RemoveProcessParametersTable, () => IsFree);
+ AddLiquidFactorCommand = new RelayCommand(AddLiquidFactor, () => IsFree);
+ RemoveLiquidFactorCommand = new RelayCommand<LiquidTypesRml>(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()