diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2022-05-02 16:49:31 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2022-05-02 16:49:31 +0300 |
| commit | 643e13480ee25f02e8bf88a8d8e152780545bf3b (patch) | |
| tree | 475e687705349d57df716be054412a074e6e6295 /Software/Visual_Studio/MachineStudio | |
| parent | c7d7c3cbd8f6a2b03301c69cbd7a9ee6d1edd858 (diff) | |
| parent | 516438dede5ffce6f2685e85d2b793a604eebd72 (diff) | |
| download | Tango-643e13480ee25f02e8bf88a8d8e152780545bf3b.tar.gz Tango-643e13480ee25f02e8bf88a8d8e152780545bf3b.zip | |
merged vica jobs v2 fixes and ms rml extension fixes.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
11 files changed, 393 insertions, 63 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ColorCalibrationView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ColorCalibrationView.xaml index 0d8acbc53..e853e2075 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ColorCalibrationView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ColorCalibrationView.xaml @@ -39,7 +39,20 @@ <commonControls:MachineView Width="500" Margin="0 40 0 0" DataContext="{Binding Machine}" /> <StackPanel Margin="40 40"> <TextBlock FontSize="16">MEDIA</TextBlock> - <ComboBox ItemsSource="{Binding Rmls}" SelectedItem="{Binding SelectedRML}" FontSize="16" IsEnabled="{Binding Machine,Converter={StaticResource NullObjectToBooleanConverter}}" Background="Transparent" Style="{StaticResource TransparentComboBoxStyle}" > + + <controls:SearchComboBox ItemsSource="{Binding Rmls}" SelectedItem="{Binding SelectedRML}" FontSize="16" IsEnabled="{Binding Machine,Converter={StaticResource NullObjectToBooleanConverter}}" HorizontalContentAlignment="Stretch" SearchProperty="Name" > + + <ComboBox.ItemTemplate> + <DataTemplate> + <StackPanel> + <TextBlock Text="{Binding Name}" FontWeight="Bold" FontStyle="Italic" Foreground="{StaticResource MainWindow.Foreground}"></TextBlock> + <TextBlock FontSize="11" Text="{Binding Manufacturer}" Foreground="{StaticResource GrayBrush}"></TextBlock> + </StackPanel> + </DataTemplate> + </ComboBox.ItemTemplate> + </controls:SearchComboBox> + + <!--<ComboBox ItemsSource="{Binding Rmls}" SelectedItem="{Binding SelectedRML}" FontSize="16" IsEnabled="{Binding Machine,Converter={StaticResource NullObjectToBooleanConverter}}" Background="Transparent" Style="{StaticResource TransparentComboBoxStyle}" > <ComboBox.ItemTemplate> <DataTemplate> @@ -49,7 +62,7 @@ </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> - </ComboBox> + </ComboBox>--> <TextBlock FontSize="16" Margin="0 40 0 0">LIQUID FACTORS</TextBlock> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Excel/ColorCalibrationDataExcel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Excel/ColorCalibrationDataExcel.cs new file mode 100644 index 000000000..0a5caa0b7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Excel/ColorCalibrationDataExcel.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.ThreadExtensions.Excel +{ + //Property Names should be the same as define names in excel file. Each define name should be unique by worksheet. + public class CyanColorCalibrationDataExcel + { + public double Ink_C { get; set; } + public double L_C { get; set; } + public double A_C { get; set; } + public double B_C { get; set; } + public double X_C { get; set; } + public double Y_C { get; set; } + + public CyanColorCalibrationDataExcel() + { + Ink_C= 0; + L_C = A_C = B_C = X_C = Y_C = 0; + } + } + + public class MagentaColorCalibrationDataExcel + { + public double Ink_M { get; set; } + public double L_M { get; set; } + public double A_M { get; set; } + public double B_M { get; set; } + public double X_M { get; set; } + public double Y_M { get; set; } + + public MagentaColorCalibrationDataExcel() + { + Ink_M = 0; + L_M = A_M = B_M = X_M = Y_M = 0; + } + } + + public class YellowColorCalibrationDataExcel + { + public double Ink_Y { get; set; } + public double L_Y { get; set; } + public double A_Y { get; set; } + public double B_Y { get; set; } + public double X_Y { get; set; } + public double Y_Y { get; set; } + + public YellowColorCalibrationDataExcel() + { + Ink_Y = 0; + L_Y = A_Y = B_Y = X_Y = Y_Y = 0; + } + } + + public class BlackColorCalibrationDataExcel + { + public double Ink_B { get; set; } + public double L_B { get; set; } + public double A_B { get; set; } + public double B_B { get; set; } + public double X_B { get; set; } + public double Y_B { get; set; } + + public BlackColorCalibrationDataExcel() + { + Ink_B = 0; + L_B = A_B = B_B = X_B = Y_B = 0; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/UserModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/UserModel.cs new file mode 100644 index 000000000..5fbda6f12 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Models/UserModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.ThreadExtensions.Models +{ + public class UserModel + { + public String Guid { get; set; } + + public string Name { get; set; } + } +} 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 ae05ca02c..f8d6419f6 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 @@ -104,6 +104,7 @@ <Compile Include="Converters\ColorWithPercentToBrushConverter.cs" /> <Compile Include="Converters\ComboBoxVisibleConverter.cs" /> <Compile Include="Converters\NumericFieldConverter.cs" /> + <Compile Include="Excel\ColorCalibrationDataExcel.cs" /> <Compile Include="Excel\ColorDataExcelModel.cs" /> <Compile Include="Excel\ColorParametrsExcelModel.cs" /> <Compile Include="Models\CalibrationPlotModel.cs" /> @@ -115,6 +116,7 @@ <Compile Include="Models\RmlExtensionModel.cs" /> <Compile Include="Excel\TestResultsExcelModel.cs" /> <Compile Include="Excel\ThreadCharacteristicsExelModel.cs" /> + <Compile Include="Models\UserModel.cs" /> <Compile Include="ViewModelLocator.cs" /> <Compile Include="ViewModels\AddItemDialogVM.cs" /> <Compile Include="ViewModels\CalibrationDataVM.cs" /> @@ -234,6 +236,7 @@ <LastGenOutput>Settings.Designer.cs</LastGenOutput> </None> <EmbeddedResource Include="Templates\ExportRMLTemplate.xlsx" /> + <EmbeddedResource Include="Templates\ColorDataFileTemplate.xlsx" /> </ItemGroup> <ItemGroup> <Resource Include="Images\threads.png" /> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Templates/ColorDataFileTemplate.xlsx b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Templates/ColorDataFileTemplate.xlsx Binary files differnew file mode 100644 index 000000000..968ae39b7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Templates/ColorDataFileTemplate.xlsx diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs index b8fab210c..493d8015a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/CalibrationDataVM.cs @@ -12,6 +12,12 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { public class CalibrationDataPointVM : ExtendedObject { + public double Ink { get; set; } + public double L { get; set; } + public double A { get; set; } + public double B { get; set; } + + private double _x; public double X 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 a2a119e29..b259c4ebb 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 @@ -154,7 +154,10 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels var index = 1; foreach (var nw in items.Zip(calibrationPoints, Tuple.Create)) { - CyanCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2 }); + CyanCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() + { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2, + Ink = nw.Item1.InkPercentage, L = nw.Item1.L, A = nw.Item1.A, B = nw.Item1.B + }); } SynchronizedObservableCollection<RmlExtensionColorCalibrationsTestsLiquidData> data = RmlExtensionColorCalibrationsTest.RmlExtensionColorCalibrationsTestsLiquidData; @@ -189,7 +192,13 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels var index = 1; foreach (var nw in items.Zip(calibrationPoints, Tuple.Create)) { - MagentaCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2 }); + MagentaCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() + { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2, + Ink = nw.Item1.InkPercentage, + L = nw.Item1.L, + A = nw.Item1.A, + B = nw.Item1.B + }); } SynchronizedObservableCollection<RmlExtensionColorCalibrationsTestsLiquidData> data = RmlExtensionColorCalibrationsTest.RmlExtensionColorCalibrationsTestsLiquidData; @@ -223,7 +232,13 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels var index = 1; foreach (var nw in items.Zip(calibrationPoints, Tuple.Create)) { - YellowCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2 }); + YellowCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() + { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2, + Ink = nw.Item1.InkPercentage, + L = nw.Item1.L, + A = nw.Item1.A, + B = nw.Item1.B + }); } SynchronizedObservableCollection<RmlExtensionColorCalibrationsTestsLiquidData> data = RmlExtensionColorCalibrationsTest.RmlExtensionColorCalibrationsTestsLiquidData; @@ -257,7 +272,13 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels var index = 1; foreach (var nw in items.Zip(calibrationPoints, Tuple.Create)) { - BlackCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2 }); + BlackCalibrationData.CalibrationPoints.Add(new CalibrationDataPointVM() + { Index = index++, X = nw.Item1.InkPercentage, Y = nw.Item2, + Ink = nw.Item1.InkPercentage, + L = nw.Item1.L, + A = nw.Item1.A, + B = nw.Item1.B + }); } SynchronizedObservableCollection<RmlExtensionColorCalibrationsTestsLiquidData> data = RmlExtensionColorCalibrationsTest.RmlExtensionColorCalibrationsTestsLiquidData; @@ -377,7 +398,8 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels calibrationTable.CalibrationPoints.Clear(); var index = 1; points.ForEach(x => { - calibrationTable.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = x.Ink, Y = x.CalculatedPoint }); + calibrationTable.CalibrationPoints.Add(new CalibrationDataPointVM() { Index = index++, X = System.Math.Round(x.Ink,2), Y = System.Math.Round(x.CalculatedPoint, 2), + Ink = System.Math.Round(x.Ink,2), L = System.Math.Round(x.L,2), A = System.Math.Round(x.A, 2), B = System.Math.Round(x.B,2)}); calibrationPoints.Add(x.CalculatedPoint); }); UpdatePlots(plot, items, calibrationPoints); @@ -408,8 +430,15 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { _notification.ShowError("Linearizion process failed. " + result.ErrorMessage); }); + for( int i =0; i< result.InkPercentage.Count; i++) + { + result.InkPercentage[i] = 0.0; + } + } + for (int i = 0; i < result.InkPercentage.Count; i++) + { + result.InkPercentage[i] = Math.Round(result.InkPercentage[i], 2); } - return result.InkPercentage.ToList(); } catch (Exception ex) @@ -420,5 +449,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels } #endregion + + } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs index 3f4d8a415..2144d05f5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorCalibrationViewVM.cs @@ -21,6 +21,10 @@ using Tango.Logging; using Tango.BL.Enumerations; using Tango.PMR.ColorLab; using Tango.BL.Calibration; +using System.IO; +using Tango.Core.Helpers; +using Tango.Documents; +using Tango.MachineStudio.ThreadExtensions.Excel; namespace Tango.MachineStudio.ThreadExtensions.ViewModels @@ -154,7 +158,8 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels public RelayCommand CreateColorDataImportExcelTemplateCommand { get; set; } public RelayCommand ApplyToRMLCommand { get; set; } public RelayCommand ApplyToMachineCalibrationCommand { get; set; } - + public RelayCommand ExportColorCalibrationToExcelCommand { get; set; } + public RelayCommand SaveCommand { get; set; } public RelayCommand AddTabCommand { get; set; } @@ -174,7 +179,8 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels ApplyToRMLCommand = new RelayCommand(ApplyToRML); ApplyToMachineCalibrationCommand = new RelayCommand(ApplyToMachineCalibration); SaveCommand = new RelayCommand(Save, () => IsFree); - + ExportColorCalibrationToExcelCommand = new RelayCommand(ExportColorCalibrationToExcel, () => IsFree); + AddTabCommand = new RelayCommand(() => AddNewTab()); RemoveTabCommand = new RelayCommand<ColorCalibrationTabVM>(RemoveTab); RenameTabCommand = new RelayCommand(RenameTab); @@ -221,22 +227,44 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { if(SelectedTab != null && ActiveRML != null) { - var liquidTypesRmls = ActiveRML.LiquidTypesRmls; - var calibrationDataVM = SelectedTab.CyanCalibrationData; - ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Cyan, SelectedTab.CyanCalibrationData); - ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Magenta, SelectedTab.MagentaCalibrationData); - ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Yellow, SelectedTab.YellowCalibrationData); - ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Black, SelectedTab.BlackCalibrationData); - Save(); + { + try + { + IsFree = false; + DateTime lastUpdated = DateTime.UtcNow; + var rml = new RmlBuilder(_active_context).Set(ActiveRML.Guid).WithLiquidFactors().Build(); + if (rml != null) + { + var liquidTypesRmls = rml.LiquidTypesRmls; + var calibrationDataVM = SelectedTab.CyanCalibrationData; + ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Cyan, SelectedTab.CyanCalibrationData); + ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Magenta, SelectedTab.MagentaCalibrationData); + ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Yellow, SelectedTab.YellowCalibrationData); + ApplayCalibrationDataToliquidTypesRml(liquidTypesRmls, LiquidTypes.Black, SelectedTab.BlackCalibrationData); + _active_context.SaveChanges(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not apply to RML color calibrations."); + _notification.ShowError($"An error occurred while trying to apply to RML color calibrations.\n{ex.Message}"); + } + finally + { + IsFree = true; + } + } } } private void ApplayCalibrationDataToliquidTypesRml(SynchronizedObservableCollection<LiquidTypesRml> liquidTypesRmls, LiquidTypes type, CalibrationDataVM calibrationDataVM) { - if (calibrationDataVM.CalibrationPoints.Count == 0) + if (calibrationDataVM.CalibrationPoints.Count == 0 || liquidTypesRmls.Count == 0) return; var liquidTypeRml = liquidTypesRmls.SingleOrDefault(x => x.LiquidType.Type == type); + if(liquidTypeRml == null) + return; CalibrationData calData = new CalibrationData(); calData.LiquidType = (PMR.ColorLab.LiquidType)liquidTypeRml.LiquidType.Code; calData.CalibrationPoints.Clear(); @@ -250,19 +278,36 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { if (SelectedTab != null) { - var idsPack = Machine.IdsPacks. + try + { + IsFree = false; + DateTime lastUpdated = DateTime.UtcNow; + var machine = new MachineBuilder(_active_context).Set(Machine.Guid).WithConfiguration().WithCats().Build(); + var idsPack = machine.Configuration.IdsPacks.Where(z => !z.IsEmpty). Where(x => ActiveRML.LiquidTypesRmls.ToList().Exists(y => x.LiquidType != null && y.LiquidType.Guid == x.LiquidType.Guid)) .OrderBy(x => x.PackIndex).ToList(); - ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Cyan, SelectedTab.CyanCalibrationData); - ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Magenta, SelectedTab.MagentaCalibrationData); - ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Yellow, SelectedTab.YellowCalibrationData); - ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Black, SelectedTab.BlackCalibrationData); - Save(); + var cats = machine.Cats.Where(x => x.RmlGuid == ActiveRML.Guid).ToList(); + + ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Cyan, SelectedTab.CyanCalibrationData, cats); + ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Magenta, SelectedTab.MagentaCalibrationData, cats); + ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Yellow, SelectedTab.YellowCalibrationData, cats); + ApplayCalibrationDataToToMachineRml(idsPack, LiquidTypes.Black, SelectedTab.BlackCalibrationData, cats); + _active_context.SaveChanges(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not update color calibrations."); + _notification.ShowError($"An error occurred while trying to save color calibrations.\n{ex.Message}"); + } + finally + { + IsFree = true; + } } } - private void ApplayCalibrationDataToToMachineRml(List<IdsPack> idsPacks, LiquidTypes type, CalibrationDataVM calibrationDataVM) + private void ApplayCalibrationDataToToMachineRml(List<IdsPack> idsPacks, LiquidTypes type, CalibrationDataVM calibrationDataVM, List< Cat> cats) { if (calibrationDataVM.CalibrationPoints.Count == 0) return; @@ -271,19 +316,19 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels if (idsPack != null) { - var cat = idsPack.LiquidType.Cats.FirstOrDefault(x => x.MachineGuid == Machine.Guid && x.RmlGuid == ActiveRML.Guid); ; - + //cat.RmlGuid = ActiveRML.Guid; + // cat.MachineGuid = Machine.Guid; + var cat = cats.FirstOrDefault( x=> x.LiquidTypeGuid == idsPack.LiquidTypeGuid); if (cat == null) { cat = new Cat(); cat.Name = "untitled"; + cat.RmlGuid = ActiveRML.Guid; + cat.MachineGuid = Machine.Guid; + cat.LiquidTypeGuid = idsPack.LiquidTypeGuid; _active_context.Cats.Add(cat); } - - cat.RmlGuid = ActiveRML.Guid; - cat.MachineGuid = Machine.Guid; - cat.LiquidType = idsPack.LiquidType; - + CalibrationData calData = new CalibrationData(); calData.LiquidType = (PMR.ColorLab.LiquidType)idsPack.LiquidType.Code; calData.CalibrationPoints.AddRange(calibrationDataVM.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y })); @@ -525,6 +570,139 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels } #endregion + #region Export / Import Excel + public void ExportColorCalibrationToExcel() + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Filter = "Excel Documents|*.xlsx"; + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem("Exporting Color Calibration to file...")) + { + Task.Factory.StartNew(() => + { + try + { + IsFree = false; + + Stream stream = null; + bool dispose = false; + String file = AssemblyHelper.GetCurrentAssemblyFolder() + "\\Templates\\ColorDataFileTemplate.xlsx"; + + if (File.Exists(file)) + { + stream = File.OpenRead(file); + dispose = true; + } + else + { + stream = EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.ThreadExtensions.Templates.ColorDataFileTemplate.xlsx"); + } + + byte[] data = new byte[stream.Length]; + stream.Read(data, 0, data.Length); + File.WriteAllBytes(dlg.FileName, data); + + if (dispose) + { + stream.Dispose(); + } + + ExcelWriter writer = new ExcelWriter(dlg.FileName); + //ActiveRMLExtension = await new RmlExtensionsBuilder(_active_context) + // .Set(guid) + // .WithUser() + // .BuildAsync(); + + //ActiveRML = new RmlBuilder(_active_context) + // .Set(SelectedRMLExtension.RMLGuid) + // .Build(); + + List<CyanColorCalibrationDataExcel> cyanDataExelModels = new List<CyanColorCalibrationDataExcel>(); + + foreach(var value in SelectedTab.CyanCalibrationData.CalibrationPoints) + { + CyanColorCalibrationDataExcel cyan_model = new CyanColorCalibrationDataExcel(); + cyan_model.Ink_C = value.Ink; + cyan_model.L_C = value.L; + cyan_model.A_C = value.A; + cyan_model.B_C = value.B; + cyan_model.X_C = value.X; + cyan_model.Y_C = value.Y; + + cyanDataExelModels.Add(cyan_model); + } + + writer.WriteData(cyanDataExelModels, "Cyan", 1); + + List<MagentaColorCalibrationDataExcel> magentaDataExelModels = new List<MagentaColorCalibrationDataExcel>(); + foreach (var value in SelectedTab.MagentaCalibrationData.CalibrationPoints) + { + MagentaColorCalibrationDataExcel model = new MagentaColorCalibrationDataExcel(); + model.Ink_M = value.Ink; + model.L_M = value.L; + model.A_M = value.A; + model.B_M = value.B; + model.X_M = value.X; + model.Y_M = value.Y; + magentaDataExelModels.Add(model); + } + writer.WriteData(magentaDataExelModels, "Magenta", 1); + + List<YellowColorCalibrationDataExcel> yellowDataExelModels = new List<YellowColorCalibrationDataExcel>(); + foreach (var value in SelectedTab.YellowCalibrationData.CalibrationPoints) + { + YellowColorCalibrationDataExcel model = new YellowColorCalibrationDataExcel(); + model.Ink_Y = value.Ink; + model.L_Y = value.L; + model.A_Y = value.A; + model.B_Y = value.B; + model.X_Y = value.X; + model.Y_Y = value.Y; + yellowDataExelModels.Add(model); + } + writer.WriteData(yellowDataExelModels, "Yellow", 1); + + List<BlackColorCalibrationDataExcel> blackDataExelModels = new List<BlackColorCalibrationDataExcel>(); + foreach (var value in SelectedTab.BlackCalibrationData.CalibrationPoints) + { + BlackColorCalibrationDataExcel model = new BlackColorCalibrationDataExcel(); + model.Ink_B = value.Ink; + model.L_B = value.L; + model.A_B = value.A; + model.B_B = value.B; + model.X_B = value.X; + model.Y_B = value.Y; + blackDataExelModels.Add(model); + } + writer.WriteData(blackDataExelModels, "Black", 1); + + writer.Dispose(); + + InvokeUI(() => + { + _notification.ShowInfo("Color Calibration exported successfully."); + }); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error exporting Color Calibration to {dlg.FileName}"); + + InvokeUI(() => + { + _notification.ShowError($"An error occurred while trying to export the Color Calibration. Make sure the selected excel file is closed and data is valid.\n{ex.FlattenMessage()}"); + }); + } + finally + { + IsFree = true; + } + }); + } + } + } + + #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 47965deb4..853a415a3 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 @@ -45,10 +45,9 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels private IAuthenticationProvider _authentication; private IActionLogManager _actionLogManager; - private ObservablesContext _rmlExtentions_context; private ObservablesContext _active_context; - private List<User> _allUsers; + private List<UserModel> _allUsers; #region properties //private ObservableCollection<RmlsExtension> _rmlsExtension; @@ -228,14 +227,14 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels set { _industrySector = value; RaisePropertyChangedAuto(); } } - private String _Filter; + private String _RMLFilter; /// <summary> /// Gets or sets the search filter. /// </summary> - public String Filter + public String RMLFilter { - get { return _Filter; } - set { _Filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } + get { return _RMLFilter; } + set { _RMLFilter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } } private async void OnFilterChanged() @@ -337,7 +336,8 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels private async void BackToThreadExtensionViews(object obj) { - if (_notification.ShowQuestion("Are you sure you want to exit the RML without saving changes?")) + + //if ( _notification.ShowQuestion("Are you sure you want to exit the RML without saving changes?")) { View.NavigateTo(RMLExtensionNavigationView.RMLExtensionsView); await LoadRmlExtentions(); @@ -796,10 +796,10 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels public bool CanEdit { get { return _canEdit; } - set { _canEdit = value; RaisePropertyChangedAuto(); } + set { _canEdit = value; + RaisePropertyChangedAuto(); } } - public MainViewVM(INotificationProvider notificationProvider, IAuthenticationProvider authentication, IActionLogManager actionLogManager) { _notification = notificationProvider; @@ -853,7 +853,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels AddGlossLevelItemCommand = new RelayCommand(AddGlossLevelItem); EditGlossLevelItemCommand = new RelayCommand(EditGlossLevelItem); - + } @@ -861,6 +861,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { var env = SettingsManager.Default.GetOrCreate<MachineStudioSettings>().DeploymentSlot; CanEdit = env == Web.DeploymentSlot.DEV || env == Web.DeploymentSlot.TEST || env == Web.DeploymentSlot.PROCESS; + } @@ -868,22 +869,31 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels private async Task LoadRmlExtentions() { - var filter = Filter.ToStringOrEmpty().ToLower(); + var filter = RMLFilter.ToStringOrEmpty().ToLower(); try { IsFree = false; - - using (_notification.PushTaskItem("Loading RmlExtentions...")) + using (ObservablesContext db = ObservablesContext.CreateDefault()) { - if (_rmlExtentions_context != null) _rmlExtentions_context.Dispose(); - _rmlExtentions_context = ObservablesContext.CreateDefault(); - - Brands = _rmlExtentions_context.YarnBrands.ToObservableCollection(); - _allUsers = await _rmlExtentions_context.Users.Include(x => x.Contact).ToListAsync(); - var q = (from c in _rmlExtentions_context.Rmls.Where(x => x.Name.ToLower().Contains(filter)) - join p in _rmlExtentions_context.RmlsExtensions on c.Guid equals p.RmlsGuid into ps + if (Brands == null) + Brands = db.YarnBrands.ToObservableCollection(); + if (_allUsers == null) + { + _allUsers = new List<UserModel>(); + var users = await db.Users.Include(x => x.Contact).ToListAsync(); + foreach (var user in users) + { + UserModel model = new UserModel(); + model.Guid = user.Guid; + model.Name = user.Contact.FullName; + _allUsers.Add(model); + } + } + + var q = (from c in db.Rmls.Where(x => x.Name.ToLower().Contains(filter)) + join p in db.RmlsExtensions on c.Guid equals p.RmlsGuid into ps from p in ps.DefaultIfEmpty() select new { RML = c, RMLExtesion = p }).Distinct().ToList().DistinctBy(x => x.RML.Guid) .Select(x => new RmlExtensionModel() @@ -894,7 +904,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels Manufacturer = x.RML.Manufacturer, Brand = x.RMLExtesion == null ? "" : (Brands.Where(y => y.Guid == x.RMLExtesion.YarnBrandGuid).Select(z => z.Name).FirstOrDefault()), LinearDensity = (int)x.RML.FiberSize, - CreatedBy = x.RMLExtesion == null ? "" : _allUsers.SingleOrDefault(y => y.Guid == x.RMLExtesion.UsersGuid).Contact.FullName, + CreatedBy = x.RMLExtesion == null ? "" : _allUsers.SingleOrDefault(y => y.Guid == x.RMLExtesion.UsersGuid).Name, Created = x.RMLExtesion == null ? DateTime.Now : x.RMLExtesion.Created, LastUpdated = x.RMLExtesion == null ? DateTime.Now : x.RMLExtesion.LastUpdated, Status = x.RMLExtesion == null ? RMLExtensionStatus.New : x.RMLExtesion.RMLStatus, @@ -902,7 +912,6 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels }).ToList(); RmlExtensions = q; - } } catch (Exception ex) @@ -1011,7 +1020,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels .BuildAsync(); ActiveRML = new RmlBuilder(_active_context).Set(SelectedRMLExtension.RMLGuid).WithLiquidFactors().Build(); - + if (!String.IsNullOrEmpty(ActiveRML.Manufacturer) && false == Manufacturers.Any(x => x == ActiveRML.Manufacturer)) { _active_context.YarnManufacturers.Add(new YarnManufacturer() { Name = ActiveRML.Manufacturer }); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorCalibrationView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorCalibrationView.xaml index 407ad2e9f..04a2dace2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorCalibrationView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/ColorCalibrationView.xaml @@ -168,6 +168,12 @@ <TextBlock VerticalAlignment="Center" Margin="10 0 0 0" Text="Apply to Machine"></TextBlock> </StackPanel> </Button> + <Button DockPanel.Dock="Right" HorizontalAlignment="Right" Width="180" Height="36" Margin="0 0 26 0" VerticalAlignment="Center" Command="{Binding ExportColorCalibrationToExcelCommand}" ToolTip="Save color calibration in Excel"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon Kind="ContentSaveAll" Width="24" Height="24" /> + <TextBlock VerticalAlignment="Center" Margin="10 0 0 0" Text="Save to excel"></TextBlock> + </StackPanel> + </Button> </DockPanel> <Grid Grid.Row="1" > <Grid.RowDefinitions> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/RMLExtensionsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/RMLExtensionsView.xaml index 3ab0d2d24..255fd80d1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/RMLExtensionsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/Views/RMLExtensionsView.xaml @@ -22,19 +22,19 @@ </UserControl.Resources> <Grid IsEnabled="{Binding IsFree}"> - <DockPanel Margin="100 100 100 50" MaxWidth="1200"> + <DockPanel Margin="100 100 100 50" MaxWidth="1500"> <Grid DockPanel.Dock="Top"> <Image Source="../Images/threads.png" Width="300" Margin="10" /> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0 0 10 30"> <materialDesign:PackIcon Kind="Magnify" Width="26" Height="26"/> - <TextBox Width="300" materialDesign:HintAssist.Hint="Search by name" Text="{Binding Filter,UpdateSourceTrigger=PropertyChanged,Delay=500}"></TextBox> + <TextBox x:Name="textBoxSearch" Width="300" materialDesign:HintAssist.Hint="Search by name" Text="{Binding RMLFilter, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged,Delay=500}"></TextBox> </StackPanel> </Grid> <Grid DockPanel.Dock="Bottom"> <StackPanel> <Grid> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> - <Button Margin="50 0 0 0" MinWidth="200" Height="60" Command="{Binding ManageRmlExtensionCommand}"> + <Button Margin="50 0 0 0" MinWidth="200" Height="60" Command="{Binding ManageRmlExtensionCommand}" FocusVisualStyle="{x:Null}"> <StackPanel Orientation="Horizontal"> <materialDesign:PackIcon Kind="Pencil" Width="24" Height="24" /> <TextBlock Margin="10 0 0 0" FontSize="18">EDIT</TextBlock> @@ -42,14 +42,10 @@ </Button> </StackPanel> </Grid> - - <StackPanel Orientation="Horizontal" Margin="0 40 0 0"> - - </StackPanel> </StackPanel> </Grid> <Grid> - <DataGrid Margin="0 0 0 10" BorderBrush="Silver" IsReadOnly="True" BorderThickness="1" RowHeight="60" Background="{StaticResource TransparentBackgroundBrush}" AlternatingRowBackground="{StaticResource Transparent200}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding RmlExtensions}" SelectedItem="{Binding SelectedRMLExtension}"> + <DataGrid Margin="0 0 0 10" BorderBrush="Silver" IsReadOnly="True" BorderThickness="1" SelectionUnit="FullRow" RowHeight="60" Background="{StaticResource TransparentBackgroundBrush}" AlternatingRowBackground="{StaticResource Transparent200}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding RmlExtensions}" SelectedItem="{Binding SelectedRMLExtension}" HorizontalScrollBarVisibility="Disabled"> <DataGrid.CellStyle> <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}"> <Setter Property="BorderThickness" Value="0"/> |
