diff options
| author | Avi Levkovich <avi@twine-s.com> | 2020-06-23 09:42:30 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2020-06-23 09:42:30 +0300 |
| commit | 6138caa64d75f6580790095e1cdbbb00ed58d795 (patch) | |
| tree | bb8eccbc637d7e133ade69238ff64f790e2efdd9 /Software/Visual_Studio/MachineStudio/Modules | |
| parent | d215fe8f95a8522ff8ef915d5666087a2f271f2e (diff) | |
| parent | da3c540b1b9079a3357a7a9b7f37d07127ce0b09 (diff) | |
| download | Tango-6138caa64d75f6580790095e1cdbbb00ed58d795.tar.gz Tango-6138caa64d75f6580790095e1cdbbb00ed58d795.zip | |
merge conflicts
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
4 files changed, 166 insertions, 37 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs index 74c6bba3e..87eba8ba2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Models/CalibrationMeasurementModel.cs @@ -42,33 +42,33 @@ namespace Tango.MachineStudio.RML.Models public class CalibrationMeasurementModel : ExtendedObject { #region properties - private int _l; + private double _l; - public int L + public double L { get { return _l; } set { _l = value; RaisePropertyChangedAuto(); } } - private int _a; + private double _a; - public int A + public double A { get { return _a; } set { _a = value; RaisePropertyChangedAuto(); } } - private int _b; + private double _b; - public int B + public double B { get { return _b; } set { _b = value; RaisePropertyChangedAuto(); } } - private int _ink; + private double _ink; - public int Ink + public double Ink { get { return _ink; } set { _ink = value; RaisePropertyChangedAuto(); } @@ -77,10 +77,7 @@ namespace Tango.MachineStudio.RML.Models public CalibrationMeasurementModel() { - _ink = 0; - L = 0; - A = 0; - B = 0; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs index 24867122e..d44ef7a0c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/ColorCalibrationViewVM.cs @@ -14,12 +14,17 @@ using OxyPlot.Wpf; using OxyPlot.Annotations; using Tango.ColorCalibration; using Tango.PMR.ColorLab; +using Tango.Logging; +using Tango.MachineStudio.Common.Notifications; +using System.Text.RegularExpressions; namespace Tango.MachineStudio.RML.ViewModels { public class ColorCalibrationViewVM : ExtendedObject { private IColorCalibrator _calibrator; + private INotificationProvider _notification; + #region Properties private Rml _rml; @@ -65,9 +70,24 @@ namespace Tango.MachineStudio.RML.ViewModels public double Factor { get { return _factor; } - set { _factor = value; } + set { _factor = value; RaisePropertyChangedAuto(); } + } + + private string _errorMessage; + + public string ErrorMessage + { + get { return _errorMessage; } + set { _errorMessage = value; RaisePropertyChangedAuto(); } } + private bool _hasError; + public bool HasError + { + get { return _hasError; } + set { _hasError = value; RaisePropertyChangedAuto(); } + } + public RelayCommand CreateGraphCommand { get; set; } @@ -138,8 +158,9 @@ namespace Tango.MachineStudio.RML.ViewModels #endregion - public ColorCalibrationViewVM() + public ColorCalibrationViewVM(INotificationProvider notification) { + _notification = notification; Measurements = new ObservableCollection<CalibrationMeasurementModel>() { new CalibrationMeasurementModel(), @@ -147,6 +168,7 @@ namespace Tango.MachineStudio.RML.ViewModels new CalibrationMeasurementModel(), }; Factor = 0; + HasError = false; CreateGraphCommand = new RelayCommand(CreateGraph); this.Points = new List<DataPoint>(); TargetPoints = new List<DataPoint>(); @@ -161,38 +183,47 @@ namespace Tango.MachineStudio.RML.ViewModels private double GetLiquidFactor() { - try{ - CalibrationInput conversionInput = new CalibrationInput(); - Measurements.ToList().ForEach(x => conversionInput.Measurements.Add(new CalibrationMeasurement{ L = x.L, A = x.A, B = x.B, NanoliterPerCentimeter = x.Ink })); - conversionInput.LiquidType = PMR.ColorLab.LiquidType.TryParse(_liquidType.Type.ToString(), out PMR.ColorLab.LiquidType outValue) ? outValue : PMR.ColorLab.LiquidType.Black; - - LAB lab; - if (ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab)) - { - conversionInput.TargetL = lab.L; - conversionInput.TargetA = lab.A; - conversionInput.TargetB = lab.B; - } - CalibrationOutput result = _calibrator.GetLiquidFactor(conversionInput); - return result.LiquidFactor; + try + { + CalibrationInput conversionInput = new CalibrationInput(); + Measurements.ToList().ForEach(x => conversionInput.Measurements.Add(new CalibrationMeasurement { L = x.L, A = x.A, B = x.B, NanoliterPerCentimeter = x.Ink })); + conversionInput.LiquidType = PMR.ColorLab.LiquidType.TryParse(_liquidType.Type.ToString(), out PMR.ColorLab.LiquidType outValue) ? outValue : PMR.ColorLab.LiquidType.Black; + + + LAB lab; + if (ColorCalibrationExt.TargetLiquidTypeToLAB.TryGetValue(_liquidType.Type, out lab)) + { + conversionInput.TargetL = lab.L; + conversionInput.TargetA = lab.A; + conversionInput.TargetB = lab.B; + } + CalibrationOutput result = _calibrator.GetLiquidFactor(conversionInput); + + ErrorMessage = Regex.Replace(result.ErrorMessage, "[^A-Za-z0-9_., ]+", ""); + + HasError = false == String.IsNullOrEmpty(ErrorMessage); + return result.LiquidFactor; } catch (Exception ex ) { + HasError = true; + ErrorMessage = "Error occurred while trying to call GetLiquidFactor."; LogManager.Log(ex, "Error occurred while trying to call GetLiquidFactor."); } return 0.0; } + #region CreateGraph + private async void CreateGraph(object obj) { if (_liquidType == null) return; - LAB lab; string labType = ColorCalibrationExt.DisplayLiquidTypeToLABType[_liquidType.Type]; await Task.Factory.StartNew(() => { - Factor = GetLiquidFactor(); + Factor = GetLiquidFactor( ); }); Points.Clear(); @@ -213,6 +244,93 @@ namespace Tango.MachineStudio.RML.ViewModels XStep = (int)(Points.Count / 6); RaisePropertyChanged("CalibrationType"); PlotControl.InvalidatePlot(true); + + //await Task.Factory.StartNew(() => + //{ + // DataPoint ? intersectionpoints = FindIntersection(Points.ToArray(), TargetPoints.ToArray()); + // if(intersectionpoints == null) + // { + // InvokeUI(() => + // { + // _notification.ShowWarning(LogManager.Log($"No intersect target value with input values", LogCategory.Warning)); + // }); + // } + //}); + } + + #endregion + + #region Intersect + + public DataPoint? FindIntersection(DataPoint[] line1, DataPoint[] line2) + { + for (int i = 0; i < line1.Length; i++) + { + int nextI = i; + nextI++; + if (nextI == line1.Length) break; + + for (int j = 0; j < line2.Length; j++) + { + int nextJ = j; + nextJ++; + if (nextJ == line2.Length) break; + DataPoint? d = CheckIntersecting(line1[i], line1[nextI], line2[j], line2[nextJ]); + return d; + + } + } + return null; + } + + public DataPoint? CheckIntersecting(DataPoint A, DataPoint B, DataPoint C, DataPoint D) + { + // Line AB represented as a1x + b1y = c1 + double a1 = B.Y - A.Y; + double b1 = A.X - B.X; + double c1 = a1 * (A.X) + b1 * (A.Y); + + // Line CD represented as a2x + b2y = c2 + double a2 = D.Y - C.Y; + double b2 = C.X - D.X; + double c2 = a2 * (C.X) + b2 * (C.Y); + + double determinant = a1 * b2 - a2 * b1; + + if (determinant == 0) + { + // The lines are parallel. This is simplified + } + else + { + double x = (b2 * c1 - b1 * c2) / determinant; + double y = (a1 * c2 - a2 * c1) / determinant; + + // check if the point lies on given line segment + /* To check if "x" is between "a" and "b"; + int m = (a+b)/2; + if(Math.abs(x-m) <= (Math.abs(a-m))) + { + } + */ + double mx1 = (A.X + B.X) / 2; + double mx2 = (C.X + D.X) / 2; + double my1 = (A.Y + B.Y) / 2; + double my2 = (C.Y + D.Y) / 2; + if (Math.Abs(x - mx1) <= Math.Abs(A.X - mx1) + && Math.Abs(x - mx2) <= Math.Abs(C.X - mx2) + && Math.Abs(y - my1) <= Math.Abs(A.Y - my1) + && Math.Abs(y - my2) <= Math.Abs(C.Y - my2)) + { + return new DataPoint(x, y); + } + + } + return null; + } + + #endregion + } } 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 4939cbb48..36398a593 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 @@ -380,7 +380,7 @@ namespace Tango.MachineStudio.RML.ViewModels LiquidTypesRmls = LiquidTypesRmls, }; - ColorCalibrationVM = new ColorCalibrationViewVM() + ColorCalibrationVM = new ColorCalibrationViewVM(_notification) { RML = ActiveRML, LiquidTypes = LiquidTypesRmls.Where(x => x.LiquidType.HasPigment).ToList().Select(y => y.LiquidType).ToList(), diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml index 815e7a5f9..ffe3bf68e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/ColorCalibrationView.xaml @@ -13,12 +13,13 @@ mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> - <UserControl.Resources> - <converters:EmptyStringToNullConverter x:Key="EmptyStringToNullConverter" /> - <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> - </UserControl.Resources> + <UserControl.Resources> + <converters:EmptyStringToNullConverter x:Key="EmptyStringToNullConverter" /> + <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> + <converters:BooleanToVisibilityInverseConverter x:Key="BooleanToVisibilityInverseConverter"/> + </UserControl.Resources> - <Grid> + <Grid> <DockPanel> <Border DockPanel.Dock="Top" Background="{StaticResource TransparentBackgroundBrush200}" Margin="20 0" Padding="5" CornerRadius="5"> <Border.Effect> @@ -106,7 +107,7 @@ <oxy:Plot Title="{Binding CalibrationType}" x:Name="CalibrationPlot"> <oxy:Plot.Series > <oxy:LineSeries ItemsSource="{Binding Points}" Color="#73B6EC" MarkerFill="SteelBlue" MarkerType="Circle" /> - <oxy:LineSeries ItemsSource="{Binding TargetPoints}" Color="#E14141" MarkerType="None" /> + <oxy:LineSeries ItemsSource="{Binding TargetPoints}" Color="#E14141" MarkerFill="#E14141" MarkerType="Circle" /> </oxy:Plot.Series> <oxy:Plot.Axes> <oxy:LinearAxis Position="Bottom" Title = "nl/cm" MajorGridlineStyle="Solid" MinorGridlineStyle="Dot" IsZoomEnabled="True"/> @@ -115,6 +116,19 @@ </oxy:Plot> </Border> </Grid> + <Grid Grid.Column="2" Margin="40 0 0 0"> + <StackPanel Orientation="Vertical"> + <TextBlock FontSize="16" HorizontalAlignment="Left" Foreground="{StaticResource MainWindow.Foreground}" Height="50" Visibility="{Binding HasError, Converter={StaticResource BooleanToVisibilityInverseConverter}}"> + <Run FontWeight="DemiBold"> Factor: </Run> + <Run Text="{Binding Factor}"></Run> + <LineBreak /> + </TextBlock> + <TextBlock FontSize="16" Foreground="{StaticResource MainWindow.Foreground}" FontWeight="SemiBold" Visibility="{Binding HasError, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0 20 10 20" >Warning:</TextBlock> + <Border BorderThickness="1" CornerRadius="4" BorderBrush="{StaticResource DarkGrayBrush}" Visibility="{Binding HasError, Converter={StaticResource BooleanToVisibilityConverter}}"> + <TextBlock Margin="5" Foreground="{StaticResource RedBrush300}" Text="{Binding ErrorMessage}" Height="75" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" /> + </Border> + </StackPanel> + </Grid> </Grid> </DockPanel> </Grid> |
