diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels')
4 files changed, 56 insertions, 23 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorParametersVewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorParametersVewVM.cs index e13e016c5..2ab1f81f1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorParametersVewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorParametersVewVM.cs @@ -419,7 +419,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { if (SelectedMachineGUID == null) { - _notification.ShowWarning(LogManager.Log($"Please, select machine.", LogCategory.Warning)); + // _notification.ShowWarning(LogManager.Log($"Please, select machine.", LogCategory.Warning)); IsFree = false; return; } @@ -671,47 +671,80 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels if (listValues.Count < 2 || factor <= 0) return new DataPoint(0, 0); - var test = listValues.GroupBy(x => x.InkNlCm, x => isLtype ? x.L : x.B, (Ink, Value) => new { InkValuep = Ink, ColorValue = Value.Average() }).ToList(); - var distinctItems = listValues.GroupBy(x => x.InkNlCm, x => isLtype ? x.L : x.B, (Ink, Value) => new { InkValuep = Ink, ColorValue = Value }).Select(y => new ColorProcessData { InkNlCm = y.InkValuep, L = y.ColorValue.Average() }).ToList(); - + //var test = listValues.GroupBy(x => x.InkNlCm, x => isLtype ? x.L : x.B, (Ink, Value) => new { InkValuep = Ink, ColorValue = Value.Average() }).ToList(); + //var distinctItems = listValues.GroupBy(x => x.InkNlCm, x => isLtype ? x.L : x.B, (Ink, Value) => new { InkValuep = Ink, ColorValue = Value }).Select(y => new ColorProcessData { InkNlCm = y.InkValuep, L = y.ColorValue.Average() }).ToList(); + + var sortedItems = isLtype? listValues.OrderBy(x=>x.InkNlCm).ThenByDescending(x=>x.L).ToList() : listValues.OrderBy(x => x.InkNlCm).ThenBy(x => x.B).Select(y => new ColorProcessData { InkNlCm = y.InkNlCm, L = isLtype ? y.L : y.B }).ToList(); double calculatedX = 0.0; - ColorProcessData prevItem = distinctItems[0]; - for (int index = 1; index < distinctItems.Count; index++) + ColorProcessData prevItem = sortedItems[0]; + for (int index = 1; index < sortedItems.Count; index++) { - var item = distinctItems[index]; + var item = sortedItems[index]; - if (prevItem.L > item.L && (factor > prevItem.L || (factor <= prevItem.L && factor >= item.L)) - || (prevItem.L <= item.L && (factor > prevItem.L || (factor >= prevItem.L && factor <= item.L))) - || ((index + 1) == distinctItems.Count && calculatedX == 0.0)) + //if (prevItem.L > item.L && (factor > prevItem.L || (factor <= prevItem.L && factor >= item.L)) + // || (prevItem.L <= item.L && + // ( (factor >= prevItem.L && factor <= item.L) || (factor <= prevItem.L && !isLtype))) + // || ((index + 1) == distinctItems.Count && calculatedX == 0.0)) + //{ + // calculatedX = CalculateXValue(factor, new DataPoint(prevItem.InkNlCm, prevItem.L), new DataPoint(item.InkNlCm, item.L)); + // //Yellow line is ascending line( up line), others - descending line(down) + // // if (isLtype) + // break; + + //} + if ((prevItem.L > item.L && (factor <= prevItem.L && factor >= item.L)) + || (prevItem.L <= item.L && (factor >= prevItem.L && factor <= item.L))) { calculatedX = CalculateXValue(factor, new DataPoint(prevItem.InkNlCm, prevItem.L), new DataPoint(item.InkNlCm, item.L)); //Yellow line is ascending line( up line), others - descending line(down) - if (isLtype) - break; + // if (isLtype) + break; } - prevItem = item; + if(prevItem.InkNlCm != item.InkNlCm) + prevItem = item; } return new DataPoint(calculatedX, factor); ; } + /// <summary> + /// Calculates the x value - Point of Intersection of Two Lines, factor = y of second line + /// </summary> private double CalculateXValue(double factor, DataPoint leftPoint, DataPoint rightPoint) { - double deltaX = rightPoint.X - leftPoint.X; + //double deltaX = rightPoint.X - leftPoint.X; + double deltaX = leftPoint.X - rightPoint.X; double deltaY = rightPoint.Y - leftPoint.Y; + + double a1 = deltaY; + double b1 = deltaX; + double c1 = a1 * (leftPoint.X) + b1 * (leftPoint.Y); - // prevents division by zero exceptions. - if (deltaX == 0) - return 0.0; + double a2 = 0.0; + double b2 = deltaX; + double c2 = b2 * (factor); - double slope = deltaY / deltaX; + double determinant = a1 * b2; + if (determinant == 0) + { + return leftPoint.X; + } + + double x = (b2 * c1 - b1 * c2) / determinant; + double y = (a1 * c2 - a2 * c1) / determinant; + + // prevents division by zero exceptions. + //if (deltaX == 0) + // return leftPoint.X; + // double slope = deltaY / deltaX; // double c = leftPoint.Y - slope * leftPoint.X; // double cX = (factor - c) / slope; - return (leftPoint.X + (factor - leftPoint.Y) / slope); - + //return (leftPoint.X + (factor - leftPoint.Y) / slope); + //double y = (a1 * c2 - a2 * c1) / determinant; + return (b2 * c1 - b1 * c2) / determinant; } #endregion 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 index f305d5139..9841ee674 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/ColorShadeViewVM.cs @@ -165,7 +165,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { if (SelectedMachineGUID == null) { - _notification.ShowWarning(LogManager.Log($"Please, select machine.", LogCategory.Warning)); + // _notification.ShowWarning(LogManager.Log($"Please, select machine.", LogCategory.Warning)); IsFree = false; return; } 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 853a415a3..164d37b74 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 @@ -1046,7 +1046,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { SelectedMachine = Machines.SingleOrDefault(x => x.SerialNumber == settings.LastVirtualMachineSerialNumber); } - else + if(SelectedMachine == null) { SelectedMachine = Machines.First(); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs index f639eb6e7..8a75c526f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs @@ -256,7 +256,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { if (String.IsNullOrEmpty(SelectedMachineGUID)) { - _notification.ShowWarning(LogManager.Log($" Please, select machine.", LogCategory.Warning)); + // _notification.ShowWarning(LogManager.Log($" Please, select machine.", LogCategory.Warning)); return; } |
