From afdaadac0ddb76b5e905ef5eeda581ade4324f9b Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 19 Jan 2022 16:00:37 +0200 Subject: #5831 RML extension- Color shade window --- .../Models/ColorShadesModel.cs | 42 +++ .../Tango.MachineStudio.ThreadExtensions.csproj | 10 + .../ViewModels/ColorCalibrationTabVM.cs | 12 - .../ViewModels/ColorShadeTabVM.cs | 121 ++++++ .../ViewModels/ColorShadeViewVM.cs | 406 +++++++++++++++++++++ .../ViewModels/MainViewVM.cs | 22 +- .../Views/ColorShadeView.xaml | 162 ++++++++ .../Views/ColorShadeView.xaml.cs | 28 ++ .../Resources/ColorShadesTemplate.xlsx | Bin 0 -> 10366 bytes .../Builders/RMLExtensionColorShadeBuilder.cs | 61 ++++ .../Tango.BL/Calibration/CalibrationHelper.cs | 11 + .../Tango.BL/Calibration/ColorShadesTemplate.xlsx | Bin 0 -> 10366 bytes .../Entities/RmlExtensionColorShadesTestsData.cs | 22 ++ Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 4 +- 14 files changed, 887 insertions(+), 14 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/ColorShadesModel.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeTabVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeViewVM.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml.cs create mode 100644 Software/Visual_Studio/Resources/ColorShadesTemplate.xlsx create mode 100644 Software/Visual_Studio/Tango.BL/Builders/RMLExtensionColorShadeBuilder.cs create mode 100644 Software/Visual_Studio/Tango.BL/Calibration/ColorShadesTemplate.xlsx (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/ColorShadesModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/ColorShadesModel.cs new file mode 100644 index 000000000..cc4351891 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/ColorShadesModel.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Documents; + +namespace Tango.MachineStudio.ThreadExtensions.Models +{ + public class ColorShadesModel + { + public class ColorShadesDataItem + { + public double ColorNumber { get; set; } + public double L { get; set; } + public double A { get; set; } + public double B { get; set; } + public double C { get; set; } + public double M { get; set; } + public double Y { get; set; } + public double L2 { get; set; } + public double A2 { get; set; } + public double B2 { get; set; } + } + + public void GetDataFromFile(string fileName, out List items, ref string errors) + { + items = null; + try + { + using (ExcelReader reader = new ExcelReader(fileName)) + { + items = reader.GetDataByIndex("Sheet1", 2); + } + } + catch (Exception ex) + { + errors = ex.Message; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Tango.MachineStudio.ThreadExtensions.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Tango.MachineStudio.ThreadExtensions.csproj index 4af5d899b..065dec29e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Tango.MachineStudio.ThreadExtensions.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Tango.MachineStudio.ThreadExtensions.csproj @@ -99,6 +99,7 @@ + @@ -111,6 +112,7 @@ + @@ -123,6 +125,10 @@ ColorParametersView.xaml + + ColorShadeView.xaml + + ComboboxEditable.xaml @@ -161,6 +167,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs index 0a27281ca..a2a119e29 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationTabVM.cs @@ -314,18 +314,6 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels var points = liquidData.RmlExtensionColorCalibrationsTestsLiquidDataPoints.OrderBy(y => y.Ink).ToList(); LoadDataPlots(points, GetPlot(liquidType), GetCalibrationDataVM(liquidType)); - //if (points.Count > 0) - //{ - // List items = new List(); - // points.ForEach(x => items.Add(new ColorLinearizationModel.LinearizationDataItem() { InkPercentage = x.Ink, L = x.L, A = x.A, B = x.B })); - // items.OrderBy(y => y.InkPercentage).ToList(); - // var index = 1; - // List calibrationPoints = new List(); - // points.ForEach(x => calibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = x.Ink, Y = x.CalculatedPoint })); - - - // CreatePlots(ConvertLiquidTypeToPMR(liquidType), GetPlot(liquidType), items, GetCalibrationDataVM(liquidType)); - //} } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeTabVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeTabVM.cs new file mode 100644 index 000000000..df0ba521c --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeTabVM.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.SharedUI; +using Tango.MachineStudio.ThreadExtensions.Models; +using Tango.BL.Enumerations; +using Tango.Core.Commands; +using Microsoft.Win32; +using Tango.MachineStudio.Common.Notifications; +using Tango.BL.ActionLogs; +using Tango.BL.Entities; +using Tango.Core; + +namespace Tango.MachineStudio.ThreadExtensions.ViewModels +{ + public class ColorShadeTabVM : ViewModel + { + private INotificationProvider _notification; + private IActionLogManager _actionLogManager; + + #region Properties + + private string _name; + /// + /// Gets or sets the name of the thread. Using in print + /// + public string Name + { + get { return _name; } + set + { + _name = value; + if (RmlExtensionColorShadesTest != null) + RmlExtensionColorShadesTest.Name = _name; + RaisePropertyChangedAuto(); + } + } + + private int _tabIndex; + + public int TabIndex + { + get { return _tabIndex; } + set + { + _tabIndex = value; + RaisePropertyChangedAuto(); + } + } + + + private bool _isSelected; + /// + /// Gets or sets a value indicating whether this instance is selected. + /// + public bool IsSelected + { + get { return _isSelected; } + set { _isSelected = value; RaisePropertyChangedAuto(); } + } + + private RmlExtensionColorShadesTest _rmlExtensionColorShadesTest; + + public RmlExtensionColorShadesTest RmlExtensionColorShadesTest + { + get { return _rmlExtensionColorShadesTest; } + set + { + _rmlExtensionColorShadesTest = value; + RaisePropertyChangedAuto(); + } + } + + /// + /// Gets or sets last points before save. Used in Save to remove points before save new. + /// + /// + /// The removed points. + /// + public List RemovedDataList { get; set; } + + #endregion + + RelayCommand ImportColorsCommand { get; set; } + + public ColorShadeTabVM(INotificationProvider notification, IActionLogManager actionLogManager) + { + _notification = notification; + _actionLogManager = actionLogManager; + ImportColorsCommand = new RelayCommand(ImportColors); + } + + private void ImportColors(object obj) + { + List items; + + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select data file"; + dlg.Filter = "Excel |*.xlsx"; + items = null; + if (dlg.ShowDialogCenter() && dlg.FileName.IsNotNullOrEmpty()) + { + ColorShadesModel model = new ColorShadesModel(); + string errors = ""; + model.GetDataFromFile(dlg.FileName, out items, ref errors); + if (false == String.IsNullOrEmpty(errors) || items == null || items.Count == 0) + { + _notification.ShowError("An error occurred while trying to import data form the selected excel file. Please check the file format if valid and is available to read."); + + } + else + { + //Settings data to object + } + + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeViewVM.cs new file mode 100644 index 000000000..b1dac5ce9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeViewVM.cs @@ -0,0 +1,406 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.ActionLogs; +using Tango.BL.Builders; +using Tango.BL.Entities; +using Tango.Core; +using Tango.MachineStudio.Common.Notifications; +using Tango.SharedUI; +using Tango.AutoComplete.Editors; +using Tango.MachineStudio.ThreadExtensions.Models; +using Tango.Core.Commands; +using Microsoft.Win32; +using Tango.Logging; +using Tango.MachineStudio.ThreadExtensions.ViewModels; +using System.Collections.ObjectModel; +using Tango.BL.Calibration; + +namespace Tango.MachineStudio.ThreadExtensions.ViewModels +{ + public class ColorShadeViewVM : ViewModel + { + private INotificationProvider _notification; + private IActionLogManager _actionLogManager; + + private ObservablesContext _active_context; + public event EventHandler SaveColorShadesEvent; + + #region Properties + + + private RmlExtensionColorShade _colorShade; + + public RmlExtensionColorShade RmlExtensionColorShade + { + get { return _colorShade; } + set { _colorShade = value; + RaisePropertyChangedAuto(); + } + } + + private ObservableCollection _colorShadeTabs; + + public ObservableCollection ColorShadeTabs + { + get { return _colorShadeTabs; } + set { _colorShadeTabs = value; } + } + + private ColorShadeTabVM _selectedTab; + + public ColorShadeTabVM SelectedTab + { + get { return _selectedTab; } + set + { + _selectedTab = value; + RaisePropertyChangedAuto(); + + foreach (var tab in _colorShadeTabs.Where(x => x != _selectedTab)) + { + tab.IsSelected = false; + } + + if (_selectedTab != null) + { + _selectedTab.IsSelected = true; + } + } + } + + private string _RMLExtentionGUID; + + public string RMLExtentionGUID + { + get { return _RMLExtentionGUID; } + set + { + _RMLExtentionGUID = value; + } + } + + private string _RMLGUID; + + public string RMLGUID + { + get { return _RMLGUID; } + set + { + _RMLGUID = value; + } + } + + protected string _selectedMachineGuid; + /// + /// Gets or sets the selected machine. + /// + public String SelectedMachineGUID + { + get { return _selectedMachineGuid; } + set + { + if (value != null && _selectedMachineGuid != value) + { + _selectedMachineGuid = value; + SelectedMachineChanged(); + RaisePropertyChangedAuto(); + InvalidateRelayCommands(); + } + } + } + + + private bool _isViewLoaded; + /// + /// Gets or sets a value indicating whether this instance is view loaded. Used to update charts. + /// + public bool IsViewLoaded + { + get { return _isViewLoaded; } + set + { + if (_isViewLoaded != value) + { + _isViewLoaded = value; + } + } + } + + #endregion + + #region commands + public RelayCommand CreateColorDataImportExcelTemplateCommand { get; set; } + + public RelayCommand SaveCommand { get; set; } + + public RelayCommand AddTabCommand { get; set; } + + public RelayCommand RemoveTabCommand { get; set; } + + public RelayCommand RenameTabCommand { get; set; } + + #endregion + + public ColorShadeViewVM(INotificationProvider notification, IActionLogManager actionLogManager) + { + _notification = notification; + _actionLogManager = actionLogManager; + ColorShadeTabs = new ObservableCollection(); + + SaveCommand = new RelayCommand(Save, () => IsFree); + + AddTabCommand = new RelayCommand(() => AddNewTab()); + RemoveTabCommand = new RelayCommand(RemoveTab); + RenameTabCommand = new RelayCommand(RenameTab); + + CreateColorDataImportExcelTemplateCommand = new RelayCommand(CreateColorDataImportExcelTemplate); + } + + #region Loading + public async void LoadColorShades() + { + if (SelectedMachineGUID == null) + { + _notification.ShowWarning(LogManager.Log($"Please, select machine.", LogCategory.Warning)); + IsFree = false; + return; + } + if (RMLGUID == null) + { + IsFree = false; + return; + } + try + { + IsFree = false; + if (_active_context != null) + { + _active_context.Dispose(); + } + + _active_context = ObservablesContext.CreateDefault(); + + ColorShadeTabs.Clear(); + LogManager.Log("Loading color shade view ..."); + using (_notification.PushTaskItem("Loading Color Shade View ...")) + { + var testResults = await new RMLExtensionColorShadeBuilder(_active_context).SetAll().ForRMLExtension(RMLExtentionGUID).ForMachine(SelectedMachineGUID).WithTests().BuildAsync(); + RmlExtensionColorShade = testResults.OrderBy(x => x.ID).ToList().FirstOrDefault(); + if (RmlExtensionColorShade == null) + { + RmlExtensionColorShade = new RmlExtensionColorShade() { RmlsExtensionsGuid = RMLExtentionGUID, MachineGuid = SelectedMachineGUID }; + _active_context.RmlExtensionColorShades.Add(RmlExtensionColorShade); + _active_context.SaveChanges(); + } + + foreach (var test in RmlExtensionColorShade.RmlExtensionColorShadesTests) + { + ColorShadeTabs.Add(new ColorShadeTabVM(_notification, _actionLogManager) { RmlExtensionColorShadesTest = test, Name = test.Name }); + if (ColorShadeTabs.Count == 1) + SelectedTab = ColorShadeTabs[0]; + } + if (ColorShadeTabs.Count == 0) + { + SelectedTab = CreateNewColorShadeTabVM("Untitled", 1); + ColorShadeTabs.Add(SelectedTab); + _active_context.SaveChanges(); + } + if (IsViewLoaded) + { + // ColorShadeTabs.ToList().ForEach(x => x.InitData()); + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error loading Color Calibration tests.\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } + } + + private ColorShadeTabVM CreateNewColorShadeTabVM(string name, int index) + { + ColorShadeTabVM newtab = new ColorShadeTabVM(_notification, _actionLogManager) { Name = name, TabIndex = index }; + + newtab.RmlExtensionColorShadesTest = new RmlExtensionColorShadesTest() + { + RmlExtensionColorShadesGuid = RMLExtentionGUID, + Name = name + }; + if (RmlExtensionColorShade != null) + { + RmlExtensionColorShade.RmlExtensionColorShadesTests.Add(newtab.RmlExtensionColorShadesTest); + } + + return newtab; + } + #endregion + + #region Methods + + private void OnRMLExtensionGUIDChanged() + { + } + + private void SelectedMachineChanged() + { + SelectedTab = null; + LoadColorShades(); + } + + private void CreateColorDataImportExcelTemplate() + { + SaveFileDialog dlg = new SaveFileDialog(); + try + { + dlg.Title = $"Create excel template file"; + dlg.Filter = "Excel Files|*.xlsx"; + dlg.DefaultExt = ".xlsx"; + dlg.FileName = "Color Shades File Template"; + if (dlg.ShowDialog().Value) + { + CalibrationHelper.CreateColorShadesInputExcelTemplate(dlg.FileName); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error generating excel color shades template file " + dlg.FileName); + _notification.ShowError("An error occurred while trying to generate the color shades file."); + } + } + + #endregion + + #region Tabs modification + + /// + /// Removes the specified tab. + /// + /// The tab. + private void RemoveTab(ColorShadeTabVM tab) + { + if (ColorShadeTabs.Count == 1) + return; + if (_notification.ShowQuestion("Are you sure you want to delete the selected tab?")) + { + _active_context.RmlExtensionColorShadesTestsData.RemoveRange(tab.RmlExtensionColorShadesTest.RmlExtensionColorShadesTestsData.ToList()); + + //_active_context.RmlExtensionColorCalibrationsTestsLiquidData.RemoveRange(tab.RmlExtensionColorCalibrationsTest.RmlExtensionColorCalibrationsTestsLiquidData); + tab.RmlExtensionColorShadesTest.RmlExtensionColorShadesTestsData = null; + + RmlExtensionColorShade.RmlExtensionColorShadesTests.Remove(tab.RmlExtensionColorShadesTest); + _active_context.RmlExtensionColorShadesTests.Remove(tab.RmlExtensionColorShadesTest); + + ColorShadeTabs.Remove(tab); + SelectedTab = ColorShadeTabs.LastOrDefault(); + _active_context.SaveChanges(); + } + } + + /// + /// Adds a new tab. + /// + private bool AddNewTab(String name = null) + { + if (ColorShadeTabs.Count > 7) + { + //_notification.ShowError("Cannot exceed the maximum number of 8 tabs. You can remove a tab, or create a new project."); + return false; + } + + if (name == null) + { + name = _notification.ShowTextInput("Enter tab name", "Tab Name", "Test"); + } + + if (!String.IsNullOrWhiteSpace(name)) + { + var tab = CreateNewColorShadeTabVM(name, (ColorShadeTabs.Count + 1)); + _active_context.SaveChanges(); + ColorShadeTabs.Add(tab); + SelectedTab = tab; + return true; + } + else + { + return false; + } + } + + /// + /// Renames the tab. + /// + /// The tab. + private void RenameTab() + { + if (SelectedTab != null) + { + var name = _notification.ShowTextInput("Enter tab name", "Tab Name", SelectedTab.Name); + + if (!String.IsNullOrWhiteSpace(name)) + { + SelectedTab.Name = name; + } + } + } + + #endregion + + #region Save + + public async void Save() + { + if (SelectedMachineGUID == null) + { + _notification.ShowWarning(LogManager.Log($"Could not save Color Shades. Please, select machine before save.", LogCategory.Warning)); + return; + } + + try + { + IsFree = false; + DateTime lastUpdated = DateTime.UtcNow; + RmlExtensionColorShade.LastUpdated = lastUpdated; + + foreach (var tab in ColorShadeTabs) + { + tab.RmlExtensionColorShadesTest.LastUpdated = lastUpdated; + //var removedPoints = tab.RemovedPoints; + //foreach (var liquidData in tab.RmlExtensionColorCalibrationsTest.RmlExtensionColorCalibrationsTestsLiquidData) + //{ + // var liquidtype = _liquids.Where(l => l.Guid == liquidData.LiquidTypeGuid).FirstOrDefault(); + // if (liquidtype != null && removedPoints.ContainsKey(liquidtype.Type)) + // { + // _active_context.RmlExtensionColorCalibrationsTestsLiquidDataPoints.RemoveRange(removedPoints[liquidtype.Type]); + // } + // liquidData.LastUpdated = lastUpdated; + //} + //tab.RemovedPoints.Clear(); + } + await _active_context.SaveChangesAsync(); + + // LoadColorParameters(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not update color shades."); + _notification.ShowError($"An error occurred while trying to save color shades.\n{ex.Message}"); + } + finally + { + IsFree = true; + EventHandler handler = SaveColorShadesEvent; + handler?.Invoke(this, new EventArgs()); + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs index 1cc6e1dcc..47965deb4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs @@ -264,6 +264,14 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels set { _colorCalibrationViewVM = value; RaisePropertyChangedAuto(); } } + private ColorShadeViewVM _solorShadeViewVM; + public ColorShadeViewVM ColorShadeViewVM + { + get { return _solorShadeViewVM; } + set { _solorShadeViewVM = value; RaisePropertyChangedAuto(); } + } + + protected MachineModel _selectedMachine; /// /// Gets or sets the selected machine. @@ -1051,7 +1059,12 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels ColorCalibrationViewVM.ActiveRML = ActiveRML; ColorCalibrationViewVM.RMLGUID = ActiveRML.Guid; ColorCalibrationViewVM.Machine = SelectedMachine; - + + ColorShadeViewVM = new ColorShadeViewVM(_notification, _actionLogManager); + ColorShadeViewVM.RMLExtentionGUID = guid; + ColorShadeViewVM.RMLGUID = ActiveRML.Guid; + ColorShadeViewVM.SelectedMachineGUID = SelectedMachine != null ? SelectedMachine.Guid : null; ; + if (ActiveRMLExtension.RMLStatus == RMLExtensionStatus.New) { ColorParametersVewVM.SaveColorParameters -= UpdateStatus; @@ -1060,6 +1073,8 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels TestResultsViewVM.SaveTestResults += UpdateStatus; ColorCalibrationViewVM.SaveColorCalibration -= UpdateStatus; ColorCalibrationViewVM.SaveColorCalibration += UpdateStatus; + ColorShadeViewVM.SaveColorShadesEvent -= UpdateStatus; + ColorShadeViewVM.SaveColorShadesEvent += UpdateStatus; } View.NavigateTo(RMLExtensionNavigationView.RMLExtentionView); @@ -1123,6 +1138,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels ColorParametersVewVM.SaveColorParameters -= UpdateStatus; TestResultsViewVM.SaveTestResults -= UpdateStatus; ColorCalibrationViewVM.SaveColorCalibration -= UpdateStatus; + ColorShadeViewVM.SaveColorShadesEvent -= UpdateStatus; ActiveRMLExtension.RMLStatus = RMLExtensionStatus.InProgress; ActiveRMLExtension.LastUpdated = DateTime.UtcNow; @@ -1153,6 +1169,10 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { ColorCalibrationViewVM.Machine = SelectedMachine; } + if(ColorShadeViewVM != null) + { + ColorShadeViewVM.SelectedMachineGUID = SelectedMachine.Guid; + } } #endregion diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml new file mode 100644 index 000000000..70df4d6bf --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml.cs new file mode 100644 index 000000000..2a8079cfe --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorShadeView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.ThreadExtensions.Views +{ + /// + /// Interaction logic for ColorShadeView.xaml + /// + public partial class ColorShadeView : UserControl + { + public ColorShadeView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/Resources/ColorShadesTemplate.xlsx b/Software/Visual_Studio/Resources/ColorShadesTemplate.xlsx new file mode 100644 index 000000000..cf98c2b1b Binary files /dev/null and b/Software/Visual_Studio/Resources/ColorShadesTemplate.xlsx differ diff --git a/Software/Visual_Studio/Tango.BL/Builders/RMLExtensionColorShadeBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/RMLExtensionColorShadeBuilder.cs new file mode 100644 index 000000000..0f1894b4a --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/RMLExtensionColorShadeBuilder.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class RMLExtensionColorShadeBuilder : EntityCollectionBuilderBase + { + public RMLExtensionColorShadeBuilder(ObservablesContext context) : base(context) + { + } + + public virtual RMLExtensionColorShadeBuilder ForRMLExtension(String rmlExtensionGUID) + { + return AddQueryStep(0, (query) => + { + if (rmlExtensionGUID != null) + { + return query.Where(x => x.RmlsExtensionsGuid == rmlExtensionGUID); + } + else + { + return query; + } + }); + } + public virtual RMLExtensionColorShadeBuilder ForMachine(String machineGUID) + { + return AddQueryStep(1, (query) => + { + if (machineGUID != null) + { + return query.Where(x => x.MachineGuid == machineGUID); + } + else + { + return query; + } + }); + } + public virtual RMLExtensionColorShadeBuilder WithTests() + { + return AddStep(2, () => + { + foreach (var result in Entities.ToList()) + { + var testsList = Context.RmlExtensionColorShadesTests.Where(x => x.RmlExtensionColorShadesGuid == result.Guid).Include(y => y.RmlExtensionColorShadesTestsData).OrderBy(z => z.ID).ToList(); + + //foreach (var test in testsList) + //{ + // var b = Context.RmlExtensionColorShadesTestsData.Where(x => x.RmlExtensionColorShadesTestsGuid == test.Guid).ToList(); + //} + } + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Calibration/CalibrationHelper.cs b/Software/Visual_Studio/Tango.BL/Calibration/CalibrationHelper.cs index b75a9751d..ced98dbff 100644 --- a/Software/Visual_Studio/Tango.BL/Calibration/CalibrationHelper.cs +++ b/Software/Visual_Studio/Tango.BL/Calibration/CalibrationHelper.cs @@ -72,5 +72,16 @@ namespace Tango.BL.Calibration stream.CopyTo(fs); } } + + public static void CreateColorShadesInputExcelTemplate(String fileName) + { + var stream = EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.BL.Calibration.ColorShadesTemplate.xlsx"); + + using (FileStream fs = new FileStream(fileName, FileMode.Create)) + { + stream.Seek(0, SeekOrigin.Begin); + stream.CopyTo(fs); + } + } } } diff --git a/Software/Visual_Studio/Tango.BL/Calibration/ColorShadesTemplate.xlsx b/Software/Visual_Studio/Tango.BL/Calibration/ColorShadesTemplate.xlsx new file mode 100644 index 000000000..cf98c2b1b Binary files /dev/null and b/Software/Visual_Studio/Tango.BL/Calibration/ColorShadesTemplate.xlsx differ diff --git a/Software/Visual_Studio/Tango.BL/Entities/RmlExtensionColorShadesTestsData.cs b/Software/Visual_Studio/Tango.BL/Entities/RmlExtensionColorShadesTestsData.cs index 3d9c77b11..ac2c44f15 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/RmlExtensionColorShadesTestsData.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/RmlExtensionColorShadesTestsData.cs @@ -7,10 +7,32 @@ // the code is regenerated. Do not modify! // //------------------------------------------------------------------------------ +using ColorMine.ColorSpaces; +using Newtonsoft.Json; +using System.Windows.Media; +using System.ComponentModel.DataAnnotations.Schema; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; namespace Tango.BL.Entities { public class RmlExtensionColorShadesTestsData : RmlExtensionColorShadesTestsDataBase { + public RmlExtensionColorShadesTestsData() : base() + { + } + + + [NotMapped] + [JsonIgnore] + public SolidColorBrush ColorBrush + { + get { + Lab lab = new Lab(L, A, B); + Rgb rgb = (Rgb)lab.ToRgb(); + return new SolidColorBrush(Color.FromRgb((byte)rgb.R, (byte)rgb.G, (byte)rgb.B)); + } + } } } \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index e76aff050..bcc6e303e 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -117,6 +117,7 @@ + @@ -736,6 +737,7 @@ Designer + Designer @@ -801,7 +803,7 @@ - + \ No newline at end of file -- cgit v1.3.1