using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit.Import.Html;
using GeoSigmaDrawLib;
using MeshProcess;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace KepGridEditor
{
///
/// The form well adjust setting.
///
public partial class FormWellAdjustSetting : DevExpress.XtraEditors.XtraForm
{
///
/// Gets or sets the well radius.
///
public double WellRadius { get; set; } = 100;
///
/// Gets or sets the value range.
///
public double ValueRange { get; set; } = 10;
///
/// Gets or sets the decreasing factor.
///
public double DecreasingFactor { get; set; } = 0;
///
/// Gets or sets the dilution factor (for RBF/IDW mode).
///
public double DilutionFactor { get; set; } = 1.0;
///
/// Gets the currently selected mode.
///
public string SelectedMode => comboBoxEditMode.EditValue?.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 BindingList PointDatas = new BindingList(); // 原始数据
///
/// 用于存储选中的井点数据
///
public List SelectedWellPoints { get; private set; } = new List();
///
/// Initializes a new instance of the class.
///
public FormWellAdjustSetting()
{
InitializeComponent();
// 在窗体加载后初始化界面状态
this.Load += FormWellAdjustSetting_Load;
// 初始化文本框显示
this.txtRadius.Text = $"{WellRadius}";
this.txtDiffrence.Text = $"{ValueRange}";
this.txtFactor.Text = $"{DecreasingFactor}";
this.textEditDilution.Text = $"{DilutionFactor}";
this.gridControl.DataSource = PointDatas;
gridView.OptionsSelection.MultiSelect = true;
gridView.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
gridView.OptionsSelection.CheckBoxSelectorColumnWidth = 30;
gridView.OptionsSelection.ShowCheckBoxSelectorInColumnHeader = DevExpress.Utils.DefaultBoolean.True;
}
///
/// Initializes a new instance of the class with initial values.
///
/// The well radius.
/// The value range.
/// The decreasing factor.
public FormWellAdjustSetting(double wellRadius, double valueRange, double decreasingFactor)
: this()
{
this.WellRadius = wellRadius;
this.ValueRange = valueRange;
this.DecreasingFactor = decreasingFactor;
this.txtRadius.Text = $"{WellRadius}";
this.txtDiffrence.Text = $"{ValueRange}";
this.txtFactor.Text = $"{this.DecreasingFactor}";
}
public void LoadData(List xList, List yList, List zList, List tzList, List nameList)
{
PointDatas.Clear();
int count = xList.Count;
if (yList.Count < count) count = yList.Count;
if (zList.Count < count) count = zList.Count;
// tzList 可能为空或长度不同,根据业务逻辑处理
for (int i = 0; i < count; i++)
{
string name = (nameList != null && i < nameList.Count) ? nameList[i] : $"井{i + 1}";
double tx = xList[i];
double ty = yList[i];
double tz = zList[i]; // 真实Z
double ttz = (tzList != null && i < tzList.Count) ? tzList[i] : 0; // 图Z
PointDatas.Add(new WellPointData
{
Name = name,
X = tx,
Y = ty,
Z = tz,
TZ = ttz
// Error 属性会自动计算,不需要手动赋值
});
}
// 刷新表格
gridControl.RefreshDataSource();
gridView.SelectAll();
}
///
/// 窗体加载事件:设置默认选项并更新UI
///
private void FormWellAdjustSetting_Load(object sender, EventArgs e)
{
if (comboBoxEditMode.Properties.Items.Contains("默认"))
{
comboBoxEditMode.EditValue = "默认";
UpdateUIForCurrentMode();
}
}
///
/// 根据当前选择的模式,更新控件的启用状态
///
private void UpdateUIForCurrentMode()
{
string mode = SelectedMode;
bool isDefault = mode == "默认";
bool isRfbOrIdw = (mode == "RBF" || mode == "IDW");
// --- 默认模式:启用前三个参数 ---
txtRadius.Enabled = isDefault;
txtFactor.Enabled = isDefault;
labelControl1.Enabled = isDefault;
labelControl3.Enabled = isDefault;
// --- RBF / IDW 模式:仅启用抽稀倍数 ---
textEditDilution.Enabled = isRfbOrIdw;
labelControl4.Enabled = isRfbOrIdw;
// 可选:让非活动控件看起来更不显眼
txtRadius.Properties.Appearance.BackColor = isDefault ? SystemColors.Window : SystemColors.Control;
txtFactor.Properties.Appearance.BackColor = isDefault ? SystemColors.Window : SystemColors.Control;
textEditDilution.Properties.Appearance.BackColor = isRfbOrIdw ? SystemColors.Window : SystemColors.Control;
}
///
/// 当算法模式改变时,更新界面控件的可用性
///
private void comboBoxEditMode_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateUIForCurrentMode();
}
///
/// 确定按钮点击事件
///
private void btnOK_Click(object sender, EventArgs e)
{
try
{
SelectedWellPoints.Clear();
int[] selectedRows = gridView.GetSelectedRows();
if (selectedRows != null && selectedRows.Length > 0)
{
foreach (int rowHandle in selectedRows)
{
if (rowHandle >= 0)
{
var rowData = gridView.GetRow(rowHandle) as WellPointData;
if (rowData != null)
{
PointDataInterop interopPoint = new PointDataInterop();
// 赋值属性
interopPoint.Name = rowData.Name;
interopPoint.X = rowData.X;
interopPoint.Y = rowData.Y;
interopPoint.Z = rowData.Z;
interopPoint.TZ = rowData.TZ;
SelectedWellPoints.Add(interopPoint);
}
}
}
}
string mode = SelectedMode;
if (mode == "默认")
{
this.WellRadius = Convert.ToDouble(this.txtRadius.Text);
this.ValueRange = Convert.ToDouble(this.txtDiffrence.Text);
this.DecreasingFactor = Convert.ToDouble(this.txtFactor.Text);
DilutionFactor = 0; // 不使用
}
else
{
// RBF 或 IDW 模式:只读取抽稀倍数
if (!double.TryParse(textEditDilution.Text.Trim(), out double dilution) || dilution < 1)
throw new ArgumentException($"【{mode}抽稀倍数】必须是大于1的数值。");
// 保存结果
DilutionFactor = dilution;
// 其他参数不保存或设为默认
this.ValueRange = Convert.ToDouble(this.txtDiffrence.Text);
DecreasingFactor = 0;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
///
/// 取消按钮点击事件
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
}