101 lines
3.7 KiB
C#
101 lines
3.7 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace OperationControl.Controls.Pulverizador
|
|
{
|
|
public class BarraTopConverter : IMultiValueConverter
|
|
{
|
|
public double MinAlturaCm { get; set; } = 50.0;
|
|
public double MaxAlturaCm { get; set; } = 80.0;
|
|
public double TopMinPx { get; set; } = 18.0;
|
|
public double TopMaxPx { get; set; } = 62.0;
|
|
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (values.Length < 2)
|
|
return new Thickness(0);
|
|
|
|
if (values[0] is not double alturaCm || values[1] is not double areaHeight)
|
|
return new Thickness(0);
|
|
|
|
if (MaxAlturaCm <= MinAlturaCm)
|
|
return new Thickness(0);
|
|
|
|
double extraOffset = 0.0;
|
|
if (parameter != null)
|
|
double.TryParse(parameter.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out extraOffset);
|
|
|
|
double h = Math.Max(MinAlturaCm, Math.Min(MaxAlturaCm, alturaCm));
|
|
double t = (h - MinAlturaCm) / (MaxAlturaCm - MinAlturaCm);
|
|
|
|
double maxTop = Math.Min(TopMaxPx, Math.Max(TopMinPx, areaHeight - 20));
|
|
double top = maxTop - (t * (maxTop - TopMinPx));
|
|
|
|
return new Thickness(0, top + extraOffset, 0, 0);
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
public class RuaWidthFisicaConverter : IMultiValueConverter
|
|
{
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (values.Length < 3) return 0.0;
|
|
|
|
if (values[0] is not double totalWidth ||
|
|
values[1] is not double larguraRuaCm ||
|
|
values[2] is not double comprimentoBarraCm ||
|
|
totalWidth <= 0 || comprimentoBarraCm <= 0 || larguraRuaCm <= 0)
|
|
{
|
|
return 0.0;
|
|
}
|
|
|
|
double pxPorCm = totalWidth / comprimentoBarraCm;
|
|
double widthPx = larguraRuaCm * pxPorCm;
|
|
|
|
if (widthPx > totalWidth)
|
|
widthPx = totalWidth;
|
|
|
|
return widthPx;
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
|
|
public class RuaOffsetFisicaConverter : IMultiValueConverter
|
|
{
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (values.Length < 4)
|
|
return new Thickness(0);
|
|
|
|
if (values[0] is not double totalWidth ||
|
|
values[1] is not double erroLateralCm ||
|
|
values[2] is not double larguraRuaCm ||
|
|
values[3] is not double comprimentoBarraCm ||
|
|
totalWidth <= 0 || comprimentoBarraCm <= 0)
|
|
{
|
|
return new Thickness(0);
|
|
}
|
|
|
|
double pxPorCm = totalWidth / comprimentoBarraCm;
|
|
double widthPx = Math.Min(totalWidth, Math.Max(0, larguraRuaCm * pxPorCm));
|
|
|
|
double center = totalWidth / 2.0;
|
|
|
|
// erro > 0 = robô está para a direita, então a rua aparece deslocando para a esquerda
|
|
double roadCenter = center - erroLateralCm * pxPorCm;
|
|
double left = roadCenter - widthPx / 2.0;
|
|
|
|
return new Thickness(left, 0, 0, 0);
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
=> throw new NotImplementedException();
|
|
}
|
|
} |