2024-10-29 19:53:27 +00:00
using AgroBase.Forms ;
using AgroBase.Models ;
2024-07-12 19:44:56 +00:00
using AgroBase.Services ;
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
2024-07-26 19:54:25 +00:00
using static AgroBase . Models . Enums ;
2024-07-12 19:44:56 +00:00
namespace AgroMonitor.Forms
{
public partial class frmAjustesOperacao : Form
{
2024-11-25 12:14:59 +00:00
AsyncTaskTimerModel tmrDadosMapa ;
2024-07-12 19:44:56 +00:00
string path = Variaveis . CaminhoSistema + Variaveis . CaminhoOperacoes + "\\" + MapasVariaveisModel . NomeArquivoMapaInterativoSaida ;
2024-10-29 19:53:27 +00:00
UltrasonicA05Configuracoes ConfigUltrassom = UltrasonicA05Helper . CarregarConfiguracaoPadrao ( ConfiguracaoSensorUltrassonico . NaoUtilizado ) ;
2024-12-17 15:32:53 +00:00
bool carregarOpPadrao = true ;
2025-03-28 16:58:07 +00:00
MapaDinamicoModel MapaDinamico ;
2024-07-12 19:44:56 +00:00
public frmAjustesOperacao ( )
{
InitializeComponent ( ) ;
2025-03-28 16:58:07 +00:00
MapaDinamico = new MapaDinamicoModel ( this , pnlZoomMapa ) ;
2024-07-12 19:44:56 +00:00
}
private void frmAjustesOperacao_Load ( object sender , EventArgs e )
{
2024-10-29 19:53:27 +00:00
cmbConfiguracaoUltrassom . Items . Clear ( ) ;
cmbConfiguracaoUltrassom . Items . AddRange ( Enum . GetNames ( typeof ( ConfiguracaoSensorUltrassonico ) ) ) ;
cmbConfiguracaoUltrassom . SelectedIndex = 0 ;
2024-07-12 19:44:56 +00:00
cmbModosOperacao . Items . Clear ( ) ;
cmbModosOperacao . Items . AddRange ( Enum . GetNames ( typeof ( ModoOperacao ) ) ) ;
cmbModosOperacao . SelectedIndex = 0 ;
}
private void frmAjustesOperacao_FormClosing ( object sender , FormClosingEventArgs e )
{
2024-11-25 19:26:00 +00:00
tmrDadosMapa ? . Dispose ( ) ;
2024-07-12 19:44:56 +00:00
}
private void cmbModosOperacao_SelectedIndexChanged ( object sender , EventArgs e )
{
2024-12-17 15:32:53 +00:00
AtualizarDadosOperacao ( ) ;
2024-07-12 19:44:56 +00:00
}
2024-12-17 15:32:53 +00:00
private void AtualizarDadosOperacao ( )
2024-07-12 19:44:56 +00:00
{
2024-12-17 15:32:53 +00:00
if ( carregarOpPadrao )
2024-07-12 19:44:56 +00:00
{
2024-12-06 20:19:59 +00:00
OperacaoModel . CarregarParametrosOperacaoPadrao ( ( ModoOperacao ) cmbModosOperacao . SelectedIndex ) ;
2024-07-12 19:44:56 +00:00
}
foreach ( var chb in pnlModulos . Controls . OfType < CheckBox > ( ) )
{
string disp = chb . Name . Replace ( "chb" , "" ) ;
T_Code Dispositivo = ( T_Code ) Enum . Parse ( typeof ( T_Code ) , disp ) ;
2024-12-13 19:39:31 +00:00
chb . Checked = Variaveis . OperacaoEmAndamento . ModulosMandatorios . Any ( x = > x . Dispositivo = = Dispositivo & & x . Mandatorio ) ;
2024-07-12 19:44:56 +00:00
}
2024-12-06 20:19:59 +00:00
double velMaxRoda = FuncoesMatematicas . CalculaVelocidadeRPM ( VariaveisEquipamento . RPM_Max_Roda ) ;
double velocidadeMax = FuncoesMatematicas . CalculaVelocidadeRPM ( Variaveis . OperacaoEmAndamento . Controle . RPM_Max ) ;
2024-10-29 19:53:27 +00:00
int percentMax = ( int ) FuncoesMatematicas . Map ( velocidadeMax , 0.0 , velMaxRoda , 0 , 100.0 ) ;
2024-12-06 20:19:59 +00:00
double velocidadeMin = FuncoesMatematicas . CalculaVelocidadeRPM ( Variaveis . OperacaoEmAndamento . Controle . RPM_Min ) ;
2024-10-29 19:53:27 +00:00
int percentMin = ( int ) FuncoesMatematicas . Map ( velocidadeMin , 0.0 , velMaxRoda , 0 , 100.0 ) ;
2024-07-12 19:44:56 +00:00
txtDescricao . Text = Variaveis . OperacaoEmAndamento . Descricao ;
2024-10-29 19:53:27 +00:00
nudVelMax . Value = percentMax ;
nudVelMin . Value = percentMin ;
2024-07-15 19:02:36 +00:00
txtAnguloMaximo . Text = Variaveis . OperacaoEmAndamento . Controle . Angulo_Max . ToString ( "0" ) ;
txtVelocidadeDirecional . Text = Variaveis . OperacaoEmAndamento . Controle . VelocidadeMP . ToString ( "0" ) ;
txtPercentualAtuacao . Text = ( Variaveis . OperacaoEmAndamento . Controle . PercentualInicioPulverizacao * 100 ) . ToString ( "0" ) ;
2024-07-12 19:44:56 +00:00
txtCapacidadeReservatorio . Text = Variaveis . OperacaoEmAndamento . CapacidadeReservatorio . ToString ( "0" ) ;
2024-07-15 19:02:36 +00:00
txtPressaoLinha . Text = Variaveis . OperacaoEmAndamento . Controle . PressaoLinha . ToString ( "0" ) ;
txtDuracaoAtuacao . Text = Variaveis . OperacaoEmAndamento . Controle . TempoAtuacao . ToString ( "0" ) ;
2024-10-29 19:53:27 +00:00
if ( Variaveis . OperacaoEmAndamento . DispSen ! = null )
{
ConfigUltrassom = Variaveis . OperacaoEmAndamento . DispSen . Dados . ConfiguracaoSensorUltrassom ;
cmbConfiguracaoUltrassom . SelectedIndex = ( int ) ConfigUltrassom . Configuracao ;
2024-12-11 13:15:14 +00:00
}
chbSonarAtivado . Checked = Variaveis . OperacaoEmAndamento . Controle . SonarAtivado ;
2025-03-28 16:58:07 +00:00
string nomeOpPadrao = "OP_" + DateTime . Now . ToString ( "dd_MM_yyyy_mm_ss" ) ;
txtDescricao . Text = nomeOpPadrao ;
2024-07-12 19:44:56 +00:00
}
private void btnProximo_Click ( object sender , EventArgs e )
{
tabControl1 . SelectedIndex = 1 ;
}
private void btnCarregarMapa_Click ( object sender , EventArgs e )
{
List < string > ruasSelecionadas = new List < string > ( ) ;
Variaveis . OperacaoEmAndamento . Mapa = new MapasModel ( ) ;
Variaveis . OperacaoEmAndamento . Mapa . pnlMapa = pnlMapa ;
Variaveis . OperacaoEmAndamento . Mapa . lblMapa = lblMapaCarregado ;
tabControl1 . SelectedIndex = 1 ;
Variaveis . OperacaoEmAndamento . Mapa . btnCarregar_Click ( sender , e ) ;
2025-02-06 19:01:41 +00:00
if ( tmrDadosMapa = = null | | ! tmrDadosMapa . IsRunning )
2024-07-12 19:44:56 +00:00
{
2024-11-25 19:26:00 +00:00
tmrDadosMapa = new AsyncTaskTimerModel ( "tmrDadosMapa" , tmrDadosMapa_Tick , 500 , this ) ;
2024-07-12 19:44:56 +00:00
tmrDadosMapa . Start ( ) ;
}
}
2024-11-25 12:14:59 +00:00
private async Task tmrDadosMapa_Tick ( )
2024-07-12 19:44:56 +00:00
{
if ( Variaveis . OperacaoEmAndamento . Mapa . mapaService . DadosMapa = = null )
{
return ;
}
//GPSService.AtualizarRuasSelecionadas(new List<string>() { "183", "182", "181" });
2025-02-03 19:54:39 +00:00
Variaveis . OperacaoEmAndamento . Mapa . AtualizarRuasSelecionadas ( ) ;
2024-07-12 19:44:56 +00:00
lblDistanciaTotal . Text = $"Distância total: {Variaveis.OperacaoEmAndamento.Mapa.mapaService.DadosMapa.features.Sum(x => x.properties.Length).ToString(" 0.00 ")} m" ;
2025-02-06 19:01:41 +00:00
lblDistanciaOperacao . Text = $"Distância da operação: {(Variaveis.OperacaoEmAndamento.Trajetoria?.DistanciaTotal ?? 0).ToString(" 0.00 ")} m" ;
2024-07-12 19:44:56 +00:00
double . TryParse ( txtVelocidadeSemErvas . Text , out double velocidadeSemErvas ) ;
double . TryParse ( txtVelocidadeComErvas . Text , out double velocidadeComErvas ) ;
2025-02-06 19:01:41 +00:00
Variaveis . OperacaoEmAndamento . Trajetoria ? . AtualizarTempoEstimado ( FuncoesMatematicas . ConverteKmhParaMs ( velocidadeSemErvas ) , FuncoesMatematicas . ConverteKmhParaMs ( velocidadeComErvas ) ) ;
string tempo = Variaveis . OperacaoEmAndamento . Trajetoria ? . TempoEstimadoOperacao ;
2024-07-12 19:44:56 +00:00
lblTempoEstimado . Text = $"Tempo estimado: {tempo}" ;
2025-03-28 16:58:07 +00:00
if ( chbMapaDinamico . Checked )
{
var _Trajetoria = Variaveis . OperacaoEmAndamento . Trajetoria ;
GPSModel posicao = _Trajetoria . RuasPlantacao . Any ( ) ? _Trajetoria . RuasPlantacao [ 0 ] [ _Trajetoria . ExtremoMaisProximoMapa = = 0 ? 0 : _Trajetoria . RuasPlantacao [ 0 ] . Count - 1 ] : GPSService . UltimaLeitura ;
MapaDinamico . AtualizarDados (
null ,
( float ) 0 ,
( float ) 0 ,
posicao ,
_Trajetoria . _TrajetoriaDinamica ,
_Trajetoria . CorredorAtual . Pontos ,
Variaveis . OperacaoEmAndamento . GPSTrajetoria ,
_Trajetoria . RuasPlantacao
) ;
}
2024-07-12 19:44:56 +00:00
}
private void btnSalvar_Click ( object sender , EventArgs e )
{
2025-03-06 20:15:56 +00:00
int . TryParse ( txtQtdCameras . Text , out int qtdCameras ) ;
2024-07-12 19:44:56 +00:00
bool sucesso = Variaveis . OperacaoEmAndamento . SalvarParametrizacaoOperacao (
txtDescricao . Text ,
txtCapacidadeReservatorio . Text ,
txtPressaoLinha . Text ,
txtDuracaoAtuacao . Text ,
txtPercentualAtuacao . Text ,
txtAnguloMaximo . Text ,
txtVelocidadeDirecional . Text ,
2024-10-29 19:53:27 +00:00
( int ) nudVelMax . Value ,
( int ) nudVelMin . Value ,
2024-12-11 13:15:14 +00:00
ConfigUltrassom ,
2025-03-06 20:15:56 +00:00
chbSonarAtivado . Checked ,
qtdCameras
2024-07-12 19:44:56 +00:00
) ;
if ( ! sucesso )
{
txtDescricao . Focus ( ) ;
}
}
2024-10-03 18:21:30 +00:00
private async void btnCarregar_Click ( object sender , EventArgs e )
2024-07-12 19:44:56 +00:00
{
2024-10-03 18:21:30 +00:00
await CarregarOperacao ( ) ;
2024-07-12 19:44:56 +00:00
}
private async Task CarregarOperacao ( )
{
2025-04-02 20:37:56 +00:00
( bool carregado , List < string > ruasSelecionadas ) = Variaveis . OperacaoEmAndamento . CarregarParametrizacaoOperacao ( pnlMapa , lblMapaCarregado ) ;
bool condicaoOperacaoCarregada ( ) = > Variaveis . OperacaoEmAndamento . Trajetoria ? . CorredorAtual ! = null ;
bool resultado = await FuncoesGlobais . AguardarCondicaoAsync ( condicaoOperacaoCarregada , 5000 , 200 ) ;
if ( ! resultado )
{
MessageBox . Show ( $"Erro ao carregar operação!{Environment.NewLine}Erro ao carregar a trajetória do mapa!" , "Erro" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
return ;
}
if ( carregado & & resultado )
2024-07-12 19:44:56 +00:00
{
tabControl1 . SelectedIndex = 1 ;
2024-12-17 15:32:53 +00:00
carregarOpPadrao = false ;
cmbModosOperacao . SelectedIndex = ( int ) Variaveis . OperacaoEmAndamento . Modo ;
2024-07-12 19:44:56 +00:00
MessageBox . Show ( "Operação carregada com sucesso!" , "Sucesso" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2025-03-28 16:58:07 +00:00
tmrDadosMapa ? . Dispose ( ) ;
2024-11-25 19:26:00 +00:00
tmrDadosMapa = new AsyncTaskTimerModel ( "tmrDadosMapa" , tmrDadosMapa_Tick , 500 , this ) ;
2025-03-28 16:58:07 +00:00
tmrDadosMapa ? . Start ( ) ;
2024-07-12 19:44:56 +00:00
2024-12-17 15:32:53 +00:00
await Task . Delay ( 2000 ) ;
2024-07-12 19:44:56 +00:00
if ( ruasSelecionadas . Any ( ) )
{
await Task . Delay ( 1000 ) ;
GPSService . AtualizarRuasSelecionadas ( ruasSelecionadas ) ;
File . Delete ( path ) ;
}
2024-12-17 15:32:53 +00:00
carregarOpPadrao = true ;
2024-07-12 19:44:56 +00:00
}
}
private void chbModulo_CheckedChanged ( object sender , EventArgs e )
{
CheckBox chb = ( CheckBox ) sender ;
string ModID = chb . Name . Replace ( "chb" , "" ) ;
T_Code Dispositivo = ( T_Code ) Enum . Parse ( typeof ( T_Code ) , ModID ) ;
if ( Variaveis . OperacaoEmAndamento . ModulosMandatorios . Any ( x = > x . Dispositivo = = Dispositivo ) )
{
Variaveis . OperacaoEmAndamento . ModulosMandatorios . First ( x = > x . Dispositivo = = Dispositivo ) . Mandatorio = chb . Checked ;
}
else
{
Variaveis . OperacaoEmAndamento . ModulosMandatorios . Add ( new OperacaoModulosMandatoriosModel ( )
{
Dispositivo = Dispositivo ,
Conectado = false ,
Mandatorio = chb . Checked ,
Utilizar = chb . Checked ,
} ) ;
}
2024-10-29 19:53:27 +00:00
2024-12-12 22:04:05 +00:00
if ( Dispositivo = = T_Code . A05 | | Dispositivo = = T_Code . Knt )
2024-10-29 19:53:27 +00:00
{
gpbSensoriamento . Enabled = chb . Checked ;
}
2024-07-12 19:44:56 +00:00
}
2024-10-29 19:53:27 +00:00
private void btnConfigurar_Click ( object sender , EventArgs e )
{
frmA05Config frm = new frmA05Config ( ConfigUltrassom ) ;
frm . ShowDialog ( ) ;
ConfigUltrassom = frm . ConfiguracaoSensores ;
}
private void cmbConfiguracaoUltrassom_SelectedIndexChanged ( object sender , EventArgs e )
{
ConfiguracaoSensorUltrassonico Config = ( ConfiguracaoSensorUltrassonico ) cmbConfiguracaoUltrassom . SelectedIndex ;
rtbDescricao . Text = UltrasonicA05Helper . DescricaoConfiguracoes [ Config ] ;
if ( Config ! = ConfigUltrassom . Configuracao )
{
ConfigUltrassom = UltrasonicA05Helper . CarregarConfiguracaoPadrao ( Config ) ;
}
}
private void nudVelMax_ValueChanged ( object sender , EventArgs e )
{
int Percentual = ( int ) ( ( NumericUpDown ) sender ) . Value ;
2025-02-06 19:01:41 +00:00
double velocidadeMs = FuncoesMatematicas . CalculaVelocidadeMsPercentual ( Percentual ) ;
double Velocidade = FuncoesMatematicas . ConverteMsParaKmh ( velocidadeMs ) ;
2024-10-29 19:53:27 +00:00
txtVelocidadeSemErvas . Text = Velocidade . ToString ( "0.00" ) ;
}
private void nudVelMin_ValueChanged ( object sender , EventArgs e )
{
int Percentual = ( int ) ( ( NumericUpDown ) sender ) . Value ;
2025-02-06 19:01:41 +00:00
double velocidadeMs = FuncoesMatematicas . CalculaVelocidadeMsPercentual ( Percentual ) ;
double Velocidade = FuncoesMatematicas . ConverteMsParaKmh ( velocidadeMs ) ;
2024-10-29 19:53:27 +00:00
txtVelocidadeComErvas . Text = Velocidade . ToString ( "0.00" ) ;
}
2025-03-28 16:58:07 +00:00
private void chbMapaDinamico_CheckedChanged ( object sender , EventArgs e )
{
pnlZoomMapa . Visible = chbMapaDinamico . Checked ;
}
2024-07-12 19:44:56 +00:00
}
}