466 lines
13 KiB
C#
466 lines
13 KiB
C#
using System;
|
||
using System.ComponentModel;
|
||
using System.Drawing;
|
||
using System.Drawing.Drawing2D;
|
||
using System.Windows.Forms;
|
||
using static AgroBase.Models.Enums;
|
||
|
||
namespace AgroBase.Forms.IHM.Controls.Operacao
|
||
{
|
||
public class HmiWheelStatusCard : UserControl
|
||
{
|
||
private readonly Label _lblTitulo;
|
||
|
||
private readonly CheckBox _chkDir;
|
||
private readonly Label _lblDirSp;
|
||
private readonly Label _lblDirAtual;
|
||
private readonly Label _lblDirStatus;
|
||
|
||
private readonly CheckBox _chkMov;
|
||
private readonly Label _lblMovSp;
|
||
private readonly Label _lblMovAtual;
|
||
private readonly Label _lblMovStatus;
|
||
|
||
private Color _borderColor = HmiTheme.Border;
|
||
|
||
public HmiWheelStatusCard()
|
||
{
|
||
SetStyle(
|
||
ControlStyles.AllPaintingInWmPaint |
|
||
ControlStyles.UserPaint |
|
||
ControlStyles.OptimizedDoubleBuffer |
|
||
ControlStyles.ResizeRedraw,
|
||
true
|
||
);
|
||
|
||
DoubleBuffered = true;
|
||
BackColor = HmiTheme.SurfaceRaised;
|
||
|
||
Margin = new Padding(2, 0, 2, 0);
|
||
Padding = new Padding(3);
|
||
MinimumSize = Size.Empty;
|
||
|
||
var root = new TableLayoutPanel
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
BackColor = Color.Transparent,
|
||
ColumnCount = 1,
|
||
RowCount = 4,
|
||
Margin = Padding.Empty,
|
||
Padding = Padding.Empty
|
||
};
|
||
|
||
root.ColumnStyles.Add(
|
||
new ColumnStyle(SizeType.Percent, 100F)
|
||
);
|
||
|
||
// Título pequeno, liberando espaço para os dados.
|
||
root.RowStyles.Add(
|
||
new RowStyle(SizeType.Absolute, 18F)
|
||
);
|
||
|
||
root.RowStyles.Add(
|
||
new RowStyle(SizeType.Absolute, 1F)
|
||
);
|
||
|
||
root.RowStyles.Add(
|
||
new RowStyle(SizeType.Percent, 50F)
|
||
);
|
||
|
||
root.RowStyles.Add(
|
||
new RowStyle(SizeType.Percent, 50F)
|
||
);
|
||
|
||
_lblTitulo = new Label
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
AutoSize = false,
|
||
AutoEllipsis = false,
|
||
UseMnemonic = false,
|
||
|
||
BackColor = Color.FromArgb(28, 34, 38),
|
||
ForeColor = HmiTheme.Text,
|
||
|
||
Font = new Font(
|
||
"Segoe UI",
|
||
7.8F,
|
||
FontStyle.Bold
|
||
),
|
||
|
||
Text = "EF",
|
||
TextAlign = ContentAlignment.MiddleCenter,
|
||
|
||
Margin = Padding.Empty,
|
||
Padding = Padding.Empty
|
||
};
|
||
|
||
var divisorTitulo = new Panel
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
BackColor = HmiTheme.Border,
|
||
Margin = Padding.Empty
|
||
};
|
||
|
||
var pnlDir = CriarBloco(
|
||
"DIR",
|
||
HmiTheme.Manual,
|
||
out _chkDir,
|
||
out _lblDirSp,
|
||
out _lblDirAtual,
|
||
out _lblDirStatus
|
||
);
|
||
|
||
var pnlMov = CriarBloco(
|
||
"MOV",
|
||
HmiTheme.Info,
|
||
out _chkMov,
|
||
out _lblMovSp,
|
||
out _lblMovAtual,
|
||
out _lblMovStatus
|
||
);
|
||
|
||
_lblDirSp.Text = "SP +0,0°";
|
||
_lblDirAtual.Text = "AT +0,0°";
|
||
_lblDirStatus.Text = "Parado";
|
||
_lblDirStatus.ForeColor = HmiTheme.Success;
|
||
|
||
_lblMovSp.Text = "SP 0 rpm";
|
||
_lblMovAtual.Text = "AT 0 rpm";
|
||
_lblMovStatus.Text = "Sem freio";
|
||
_lblMovStatus.ForeColor = HmiTheme.TextMuted;
|
||
|
||
root.Controls.Add(_lblTitulo, 0, 0);
|
||
root.Controls.Add(divisorTitulo, 0, 1);
|
||
root.Controls.Add(pnlDir, 0, 2);
|
||
root.Controls.Add(pnlMov, 0, 3);
|
||
|
||
Controls.Add(root);
|
||
|
||
// Força os elementos críticos para frente.
|
||
_lblTitulo.BringToFront();
|
||
_chkDir.BringToFront();
|
||
_chkMov.BringToFront();
|
||
}
|
||
|
||
private static Panel CriarBloco(
|
||
string titulo,
|
||
Color corTitulo,
|
||
out CheckBox check,
|
||
out Label lblSp,
|
||
out Label lblAtual,
|
||
out Label lblStatus)
|
||
{
|
||
var panel = new Panel
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
BackColor = Color.Transparent,
|
||
Margin = Padding.Empty,
|
||
Padding = new Padding(2, 1, 2, 1)
|
||
};
|
||
|
||
var layout = new TableLayoutPanel
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
BackColor = Color.Transparent,
|
||
ColumnCount = 1,
|
||
RowCount = 4,
|
||
Margin = Padding.Empty,
|
||
Padding = Padding.Empty
|
||
};
|
||
|
||
layout.ColumnStyles.Add(
|
||
new ColumnStyle(SizeType.Percent, 100F)
|
||
);
|
||
|
||
layout.RowStyles.Add(
|
||
new RowStyle(SizeType.Absolute, 18F)
|
||
);
|
||
|
||
layout.RowStyles.Add(
|
||
new RowStyle(SizeType.Percent, 30F)
|
||
);
|
||
|
||
layout.RowStyles.Add(
|
||
new RowStyle(SizeType.Percent, 30F)
|
||
);
|
||
|
||
layout.RowStyles.Add(
|
||
new RowStyle(SizeType.Percent, 40F)
|
||
);
|
||
|
||
var header = new Panel
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
BackColor = Color.Transparent,
|
||
Margin = Padding.Empty,
|
||
Padding = Padding.Empty
|
||
};
|
||
|
||
var lblTitulo = new Label
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
AutoSize = false,
|
||
BackColor = Color.Transparent,
|
||
ForeColor = corTitulo,
|
||
|
||
Font = new Font(
|
||
"Segoe UI",
|
||
6.6F,
|
||
FontStyle.Bold
|
||
),
|
||
|
||
Text = titulo,
|
||
TextAlign = ContentAlignment.MiddleLeft,
|
||
|
||
Margin = Padding.Empty,
|
||
Padding = Padding.Empty
|
||
};
|
||
|
||
check = CriarCheck();
|
||
|
||
// Dock Right funciona melhor aqui que coluna estreita.
|
||
check.Dock = DockStyle.Right;
|
||
check.Width = 22;
|
||
|
||
header.Controls.Add(lblTitulo);
|
||
header.Controls.Add(check);
|
||
|
||
check.BringToFront();
|
||
|
||
lblSp = CriarLabelDado("SP 0");
|
||
lblAtual = CriarLabelDado("AT 0");
|
||
|
||
lblStatus = CriarLabelDado("Parado");
|
||
lblStatus.Font = new Font(
|
||
"Segoe UI",
|
||
5.8F,
|
||
FontStyle.Bold
|
||
);
|
||
|
||
layout.Controls.Add(header, 0, 0);
|
||
layout.Controls.Add(lblSp, 0, 1);
|
||
layout.Controls.Add(lblAtual, 0, 2);
|
||
layout.Controls.Add(lblStatus, 0, 3);
|
||
|
||
panel.Controls.Add(layout);
|
||
|
||
return panel;
|
||
}
|
||
|
||
private static Label CriarLabelDado(string texto)
|
||
{
|
||
return new Label
|
||
{
|
||
Dock = DockStyle.Fill,
|
||
AutoSize = false,
|
||
AutoEllipsis = false,
|
||
UseMnemonic = false,
|
||
|
||
BackColor = Color.Transparent,
|
||
ForeColor = HmiTheme.TextMuted,
|
||
|
||
Font = new Font(
|
||
"Segoe UI",
|
||
5.7F,
|
||
FontStyle.Regular
|
||
),
|
||
|
||
Text = texto,
|
||
TextAlign = ContentAlignment.MiddleLeft,
|
||
|
||
Margin = Padding.Empty,
|
||
Padding = Padding.Empty
|
||
};
|
||
}
|
||
|
||
private static CheckBox CriarCheck()
|
||
{
|
||
var check = new CheckBox
|
||
{
|
||
Appearance = Appearance.Button,
|
||
AutoSize = false,
|
||
|
||
Width = 22,
|
||
Height = 17,
|
||
|
||
Checked = true,
|
||
|
||
FlatStyle = FlatStyle.Flat,
|
||
BackColor = Color.FromArgb(30, 90, 46),
|
||
ForeColor = HmiTheme.Success,
|
||
|
||
Text = "✓",
|
||
TextAlign = ContentAlignment.MiddleCenter,
|
||
|
||
Font = new Font(
|
||
"Segoe UI Symbol",
|
||
6.2F,
|
||
FontStyle.Bold
|
||
),
|
||
|
||
Margin = Padding.Empty,
|
||
Padding = Padding.Empty,
|
||
|
||
Cursor = Cursors.Hand,
|
||
UseVisualStyleBackColor = false
|
||
};
|
||
|
||
check.FlatAppearance.BorderSize = 1;
|
||
check.FlatAppearance.BorderColor = HmiTheme.Success;
|
||
check.FlatAppearance.CheckedBackColor =
|
||
Color.FromArgb(30, 90, 46);
|
||
|
||
check.CheckedChanged += delegate
|
||
{
|
||
if (check.Checked)
|
||
{
|
||
check.Text = "✓";
|
||
check.ForeColor = HmiTheme.Success;
|
||
check.BackColor = Color.FromArgb(30, 90, 46);
|
||
check.FlatAppearance.BorderColor = HmiTheme.Success;
|
||
}
|
||
else
|
||
{
|
||
check.Text = "×";
|
||
check.ForeColor = HmiTheme.Danger;
|
||
check.BackColor = HmiTheme.Surface;
|
||
check.FlatAppearance.BorderColor = HmiTheme.Danger;
|
||
}
|
||
};
|
||
|
||
return check;
|
||
}
|
||
|
||
public void AtualizarDados(
|
||
bool dir_em_uso,
|
||
double dir_ang_sp,
|
||
double dir_ang_at,
|
||
Sentido dir_sentido,
|
||
bool mov_em_uso,
|
||
double mov_vel_sp,
|
||
double mov_vel_at,
|
||
bool mov_freio
|
||
)
|
||
{
|
||
CheckDir.Checked = dir_em_uso;
|
||
DirecionalSp = $"{dir_ang_sp}";
|
||
DirecionalAtual = $"{dir_ang_at}";
|
||
StatusDirecional = $"{dir_sentido}";
|
||
|
||
CheckMov.Checked = mov_em_uso;
|
||
MovimentoSp = $"{mov_vel_sp}";
|
||
MovimentoAtual = $"{mov_vel_at}";
|
||
StatusMovimento = mov_freio ? "Freado" : "Livre";
|
||
}
|
||
|
||
protected override void OnPaint(PaintEventArgs e)
|
||
{
|
||
base.OnPaint(e);
|
||
|
||
e.Graphics.SmoothingMode =
|
||
SmoothingMode.AntiAlias;
|
||
|
||
using (var pen = new Pen(_borderColor, 1F))
|
||
{
|
||
e.Graphics.DrawRectangle(
|
||
pen,
|
||
0,
|
||
0,
|
||
Math.Max(1, Width - 1),
|
||
Math.Max(1, Height - 1)
|
||
);
|
||
}
|
||
}
|
||
|
||
[Category("Conteúdo")]
|
||
public string Titulo
|
||
{
|
||
get { return _lblTitulo.Text; }
|
||
set
|
||
{
|
||
_lblTitulo.Text = value ?? string.Empty;
|
||
_lblTitulo.Invalidate();
|
||
_lblTitulo.BringToFront();
|
||
}
|
||
}
|
||
|
||
[Category("Conteúdo")]
|
||
public string DirecionalSp
|
||
{
|
||
get { return _lblDirSp.Text; }
|
||
set { _lblDirSp.Text = "SP " + (value ?? string.Empty); }
|
||
}
|
||
|
||
[Category("Conteúdo")]
|
||
public string DirecionalAtual
|
||
{
|
||
get { return _lblDirAtual.Text; }
|
||
set { _lblDirAtual.Text = "AT " + (value ?? string.Empty); }
|
||
}
|
||
|
||
[Category("Conteúdo")]
|
||
public string StatusDirecional
|
||
{
|
||
get { return _lblDirStatus.Text; }
|
||
set { _lblDirStatus.Text = value ?? string.Empty; }
|
||
}
|
||
|
||
[Category("Conteúdo")]
|
||
public string MovimentoSp
|
||
{
|
||
get { return _lblMovSp.Text; }
|
||
set { _lblMovSp.Text = "SP " + (value ?? string.Empty); }
|
||
}
|
||
|
||
[Category("Conteúdo")]
|
||
public string MovimentoAtual
|
||
{
|
||
get { return _lblMovAtual.Text; }
|
||
set { _lblMovAtual.Text = "AT " + (value ?? string.Empty); }
|
||
}
|
||
|
||
[Category("Conteúdo")]
|
||
public string StatusMovimento
|
||
{
|
||
get { return _lblMovStatus.Text; }
|
||
set { _lblMovStatus.Text = value ?? string.Empty; }
|
||
}
|
||
|
||
[Category("Aparência")]
|
||
public Color CorStatusDirecional
|
||
{
|
||
get { return _lblDirStatus.ForeColor; }
|
||
set { _lblDirStatus.ForeColor = value; }
|
||
}
|
||
|
||
[Category("Aparência")]
|
||
public Color CorStatusMovimento
|
||
{
|
||
get { return _lblMovStatus.ForeColor; }
|
||
set { _lblMovStatus.ForeColor = value; }
|
||
}
|
||
|
||
[Category("Aparência")]
|
||
public Color BorderColor
|
||
{
|
||
get { return _borderColor; }
|
||
set
|
||
{
|
||
_borderColor = value;
|
||
Invalidate();
|
||
}
|
||
}
|
||
|
||
[Browsable(false)]
|
||
public CheckBox CheckMov
|
||
{
|
||
get { return _chkMov; }
|
||
}
|
||
|
||
[Browsable(false)]
|
||
public CheckBox CheckDir
|
||
{
|
||
get { return _chkDir; }
|
||
}
|
||
}
|
||
} |