You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/UCDraw/KepGridEditor/FormSmoothSetting.cs

132 lines
4.3 KiB
C#

1 month ago
using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraLayout.Utils;
namespace KepGridEditor
{
public partial class FormSmoothSetting : XtraForm
{
public FormSmoothSetting()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterParent;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
// 绑定算法切换事件
cboAlgorithm.SelectedIndexChanged += CboAlgorithm_SelectedIndexChanged;
// 默认选中第一项 (迭代高斯)
cboAlgorithm.SelectedIndex = 0;
}
private void CboAlgorithm_SelectedIndexChanged(object sender, EventArgs e)
{
// 0: 迭代高斯, 1: 系数平滑
if (cboAlgorithm.SelectedIndex == 0)
{
// 显示高斯容器,隐藏系数容器
gcGaussian.Visible = true;
gcNewAlgo.Visible = false;
}
else
{
// 显示系数容器,隐藏高斯容器
gcGaussian.Visible = false;
gcNewAlgo.Visible = true;
}
}
// 算法索引 (0: Gaussian, 1: Coefficient)
public int SelectedAlgorithmIndex
{
get => cboAlgorithm.SelectedIndex;
set => cboAlgorithm.SelectedIndex = value;
}
// 高斯参数:半径
public double GaussianRadius
{
get => double.TryParse(txtGaussianRadius.Text, out double val) ? val : 0;
set => txtGaussianRadius.Text = value.ToString();
}
// 高斯参数:迭代次数
public int IterationCount
{
get => int.TryParse(txtIterationCount.Text, out int val) ? val : 0;
set => txtIterationCount.Text = value.ToString();
}
// 系数参数:平滑系数
public double SmoothCoefficient
{
get => double.TryParse(txtSmoothCoefficient.Text, out double val) ? val : 0;
set => txtSmoothCoefficient.Text = value.ToString();
}
// 系数参数:平滑次数
public int SmoothTimes
{
get => int.TryParse(txtSmoothTimes.Text, out int val) ? val : 0;
set => txtSmoothTimes.Text = value.ToString();
}
// 通用参数:羽化宽度
public int FeatherWidth
{
get => int.TryParse(txtFeatherWidth.Text, out int val) ? val : 0;
set => txtFeatherWidth.Text = value.ToString();
}
// 平滑区域 (0:无, 1:内, 2:外)
public int SmoothRegionIndex
{
get => rdoSmoothRegion.SelectedIndex;
set => rdoSmoothRegion.SelectedIndex = value;
}
private void btnOK_Click(object sender, EventArgs e)
{
// 校验逻辑
if (SelectedAlgorithmIndex == 0) // 迭代高斯
{
if (GaussianRadius < 0)
{
XtraMessageBox.Show("高斯半径不能小于0", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (IterationCount <= 0)
{
XtraMessageBox.Show("迭代次数必须大于0", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
else if (SelectedAlgorithmIndex == 1) // 系数平滑
{
if (SmoothCoefficient <= 0)
{
XtraMessageBox.Show("平滑系数必须大于0", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (SmoothTimes <= 0)
{
XtraMessageBox.Show("平滑次数必须大于0", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
}