agrobot_base/AgroBase/OperationControl/Controls/Pulverizador/PulverizadorIndicator.xaml.cs

163 lines
6.2 KiB
C#

using AgroBase.Models;
using OperationControl.Controls.Pulverizador;
using OperationControl.Models;
using System.Collections.ObjectModel;
using System.Windows;
using UserControl = System.Windows.Controls.UserControl;
namespace OperationControl.Controls
{
public partial class PulverizadorIndicator : UserControl
{
public PulverizadorIndicator()
{
InitializeComponent();
RebuildBicos();
}
private void BicoLequeIndicator_Loaded(object sender, RoutedEventArgs e)
{
if (sender is BicoLequeIndicator bicoCtrl)
{
bicoCtrl.OnBicoClicked -= BicoCtrl_OnBicoClicked;
bicoCtrl.OnBicoClicked += BicoCtrl_OnBicoClicked;
}
}
private void BicoCtrl_OnBicoClicked(int index)
{
if (!(VariaveisControleOperacao.RoverEmFoco?.Controle?.PulverizadorAutomatico ?? false))
{
System.Windows.MessageBox.Show("Para acionar os bicos manualmente, é necessário que o Pulverizador Automático esteja desligado", "Pulverizador automático", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
var bico = VariaveisControleOperacao.RoverEmFoco?.DadosLeitura?.Atuador?.Bicos?.FirstOrDefault(x => x.Posicao == (index + 1));
if (bico != null)
{
VariaveisControleOperacao.EnviarComandoAtuador(bico.ID, !bico.ComandoEstado);
}
}
public double DistanciaEntreBicosCm
{
get => (double)GetValue(DistanciaEntreBicosCmProperty);
set => SetValue(DistanciaEntreBicosCmProperty, value);
}
public static readonly DependencyProperty DistanciaEntreBicosCmProperty =
DependencyProperty.Register(nameof(DistanciaEntreBicosCm), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(50.0));
public double ComprimentoBarraCm
{
get => (double)GetValue(ComprimentoBarraCmProperty);
set => SetValue(ComprimentoBarraCmProperty, value);
}
public static readonly DependencyProperty ComprimentoBarraCmProperty =
DependencyProperty.Register(nameof(ComprimentoBarraCm), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(103.7));
public double AlturaBarra
{
get => (double)GetValue(AlturaBarraProperty);
set => SetValue(AlturaBarraProperty, value);
}
public static readonly DependencyProperty AlturaBarraProperty =
DependencyProperty.Register(nameof(AlturaBarra), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(50.0));
public bool IsBombaOn
{
get => (bool)GetValue(IsBombaOnProperty);
set => SetValue(IsBombaOnProperty, value);
}
public static readonly DependencyProperty IsBombaOnProperty =
DependencyProperty.Register(nameof(IsBombaOn), typeof(bool), typeof(PulverizadorIndicator), new PropertyMetadata(false));
public double PressaoLinha
{
get => (double)GetValue(PressaoLinhaProperty);
set => SetValue(PressaoLinhaProperty, value);
}
public static readonly DependencyProperty PressaoLinhaProperty =
DependencyProperty.Register(nameof(PressaoLinha), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(0.0));
public double TempoAtuado
{
get => (double)GetValue(TempoAtuadoProperty);
set => SetValue(TempoAtuadoProperty, value);
}
public static readonly DependencyProperty TempoAtuadoProperty =
DependencyProperty.Register(nameof(TempoAtuado), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(0.0));
public double VazaoInstantanea
{
get => (double)GetValue(VazaoInstantaneaProperty);
set => SetValue(VazaoInstantaneaProperty, value);
}
public static readonly DependencyProperty VazaoInstantaneaProperty =
DependencyProperty.Register(nameof(VazaoInstantanea), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(0.0));
public int QtdBicos
{
get => (int)GetValue(QtdBicosProperty);
set => SetValue(QtdBicosProperty, value);
}
public static readonly DependencyProperty QtdBicosProperty =
DependencyProperty.Register(nameof(QtdBicos), typeof(int), typeof(PulverizadorIndicator),
new PropertyMetadata(VariaveisEquipamento.QuantidadeBicosPulverizadores, OnQtdBicosChanged));
public double LarguraRuaCm
{
get => (double)GetValue(LarguraRuaCmProperty);
set => SetValue(LarguraRuaCmProperty, value);
}
public static readonly DependencyProperty LarguraRuaCmProperty =
DependencyProperty.Register(nameof(LarguraRuaCm), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(150.0));
public double ErroLateralCm
{
get => (double)GetValue(ErroLateralCmProperty);
set => SetValue(ErroLateralCmProperty, value);
}
public static readonly DependencyProperty ErroLateralCmProperty =
DependencyProperty.Register(nameof(ErroLateralCm), typeof(double), typeof(PulverizadorIndicator), new PropertyMetadata(0.0));
public ObservableCollection<BicoModel> Bicos { get; } = new();
private static void OnQtdBicosChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is PulverizadorIndicator ctl)
ctl.RebuildBicos();
}
private void RebuildBicos()
{
Bicos.Clear();
int quantidade = QtdBicos < 0 ? 0 : QtdBicos;
for (int i = 0; i < quantidade; i++)
{
Bicos.Add(new BicoModel
{
Index = i,
AnguloControle = 0,
OpeningAngle = 110,
IsCommandOn = false,
IsSpraying = false,
Vazao = 0,
TempoAtuado = 0,
Atuacoes = 0
});
}
}
}
}