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.
1015 lines
37 KiB
C#
1015 lines
37 KiB
C#
using DevExpress.Dialogs.Core.Base.ComInterfaces;
|
|
using DevExpress.XtraBars;
|
|
using DevExpress.XtraEditors;
|
|
using DevExpress.XtraEditors.Repository;
|
|
using DevExpress.XtraVerticalGrid.Rows;
|
|
using DevExpress.XtraWaitForm;
|
|
using GeoSigmaDrawLib;
|
|
using MeshProcess;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Reflection.Metadata.Ecma335;
|
|
using System.Windows.Forms;
|
|
|
|
namespace KepGridEditor
|
|
{
|
|
public delegate void EditorMouseMoveEventHandler(double mouseX, double mouseY);
|
|
/// <summary>
|
|
/// The form main.
|
|
/// </summary>
|
|
public partial class FormMain : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
/// <summary>
|
|
/// 鼠标移动事件
|
|
/// </summary>
|
|
public EditorMouseMoveEventHandler EditorMouseMoveEvent;
|
|
/// <summary>
|
|
/// 模块进程名称
|
|
/// </summary>
|
|
public static string ProcessName { get; set; } = "智能等网交互系统";
|
|
public EventHandler PushDataClick;
|
|
private GeoSigmaXY geo;
|
|
private IntPtr pxy = IntPtr.Zero;
|
|
private CalculateZDialog calculateZDialog;
|
|
|
|
private FormVolumeStats volumeStatsForm;
|
|
|
|
private FormTrend trendForm;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="FormMain"/> class.
|
|
/// </summary>
|
|
public FormMain()
|
|
{
|
|
InitializeComponent();
|
|
this.KeyPreview = true;
|
|
this.Text = ProcessName;
|
|
this.trvLayer.ExpandAll();
|
|
|
|
this.barEditItem1.EditValue = false;
|
|
this.ppgParameter.SelectedObject = meshEditor.EditorParameter;
|
|
|
|
//RepositoryItemColorEdit riColorEditor = new RepositoryItemColorEdit();
|
|
//RepositoryItemPopupContainerEdit riColorEditor = new RepositoryItemPopupContainerEdit();
|
|
//PopupContainerControl popupContainer = new PopupContainerControl();
|
|
//UCColorDialog uCColor = new UCColorDialog();
|
|
//popupContainer.Controls.Add(uCColor);
|
|
////popupContainer.Size = new System.Drawing.Size(424, 474);
|
|
//popupContainer.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
|
//popupContainer.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
|
//popupContainer.AutoSize = true;
|
|
//riColorEditor.PopupControl = popupContainer;
|
|
//this.ppgParameter.DefaultEditors.Add(typeof(Color), riColorEditor);
|
|
// Create a repository item which represents an in-place CheckEdit control.
|
|
RepositoryItemCheckEdit riCheckEdit = new RepositoryItemCheckEdit();
|
|
// Represent check boxes as radio buttons.
|
|
riCheckEdit.CheckStyle = DevExpress.XtraEditors.Controls.CheckStyles.Standard;
|
|
// Associate the Boolean data type with the created repository item.
|
|
this.ppgParameter.DefaultEditors.Add(typeof(Boolean), riCheckEdit);
|
|
|
|
//this.bttonFitting.Enabled = false;
|
|
this.bttnTrend.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
|
|
|
|
this.meshEditor.UpdateVolumeChanged += UpdateVolumeChanged;
|
|
this.meshEditor.UpdateTrendPtChanged += UpdateTrendPtChanged;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="FormMain"/> class.
|
|
/// </summary>
|
|
/// <param name="pXy">The p xy.</param>
|
|
public FormMain(GeoSigmaXY geo, string contourLayer, string faultLayer, string pointLayer, string otherLineLayer)
|
|
: this()
|
|
{
|
|
this.geo = geo;
|
|
this.pxy = this.geo.GetDrawerXy();
|
|
|
|
if (!string.IsNullOrEmpty(contourLayer))
|
|
{
|
|
this.meshEditor.ContourLayerName = string.Copy(contourLayer);
|
|
}
|
|
else
|
|
{
|
|
this.meshEditor.ContourLayerName = string.Empty;
|
|
}
|
|
if (!string.IsNullOrEmpty(faultLayer))
|
|
{
|
|
this.meshEditor.FaultLayerName = string.Copy(faultLayer);
|
|
}
|
|
else
|
|
{
|
|
this.meshEditor.FaultLayerName = string.Empty;
|
|
}
|
|
if (!string.IsNullOrEmpty(pointLayer))
|
|
{
|
|
this.meshEditor.PointLayerName = string.Copy(pointLayer);
|
|
}
|
|
else
|
|
{
|
|
this.meshEditor.PointLayerName = string.Empty;
|
|
}
|
|
if (!string.IsNullOrEmpty(otherLineLayer))
|
|
{
|
|
this.meshEditor.OtherLineLayerName = otherLineLayer;
|
|
}
|
|
else
|
|
{
|
|
this.meshEditor.OtherLineLayerName = string.Empty;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 打开文件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void bbtnOpenFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor.OpenFile();
|
|
this.ppgParameter.SelectedObject = null;
|
|
this.ppgParameter.SelectedObject = meshEditor.EditorParameter;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Form1_S the load.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
if (pxy != IntPtr.Zero)
|
|
{
|
|
meshEditor.InitEditor();
|
|
meshEditor.OpenDraw(pxy, 0);
|
|
// 打开时启用 “断层填充” 和 “断层边缘优化”,使得打开等网系统即呈现最佳显示效果
|
|
meshEditor.EnableFillFault(true);
|
|
meshEditor.OffsetFault();
|
|
|
|
this.ppgParameter.SelectedObject = null;
|
|
this.ppgParameter.SelectedObject = meshEditor.EditorParameter;
|
|
}
|
|
meshEditor.SetMouseMoveEvent(EditorMouseMoveEvent);
|
|
Application.Idle += Application_Idle;
|
|
|
|
|
|
// 只允许输入正整数或小数(可根据需要调整正则)
|
|
this.repositoryItemTextEdit2.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;
|
|
this.repositoryItemTextEdit2.Mask.EditMask = @"\d+([.]\d+)?";
|
|
this.repositoryItemTextEdit2.Mask.ShowPlaceHolders = false;
|
|
}
|
|
/// <summary>
|
|
/// Application_S the idle.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void Application_Idle(object sender, EventArgs e)
|
|
{
|
|
if (meshEditor != null)
|
|
{
|
|
this.bbtnUndo.Enabled = meshEditor.CanUndo();
|
|
this.bbtnRedo.Enabled = meshEditor.CanRedo();
|
|
this.btxtOptimize.Enabled = bbtnOptimizeMesh.Down;
|
|
|
|
this.bbtnDragUpPolygon.Enabled = bbtnPolygonOperator.Down;
|
|
this.bbtnDragDownPolygon.Enabled = bbtnPolygonOperator.Down;
|
|
this.bbtnSmoothPolygon.Enabled = bbtnPolygonOperator.Down;
|
|
|
|
// 直接根据状态指挥最大化按钮的启用情况
|
|
bool isCloning = (meshEditor.CommandStatus == OperaCommandType.GridCloneStamp ||
|
|
meshEditor.CommandStatus == OperaCommandType.GridCloneStampCircle);
|
|
|
|
// 只有在状态不一致时才赋值,防止不必要的界面重绘
|
|
if (this.MaximizeBox == isCloning)
|
|
{
|
|
this.MaximizeBox = !isCloning;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// btns the view all_ item click.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void btnViewAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor?.ZoomView();
|
|
}
|
|
|
|
/// <summary>
|
|
/// bbtns the undo_ item click.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnUndo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor.Undo();
|
|
ppgParameter.Refresh();
|
|
}
|
|
|
|
/// <summary>
|
|
/// bbtns the redo_ item click.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnRedo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor.Redo();
|
|
ppgParameter.Refresh();
|
|
}
|
|
|
|
/// <summary>
|
|
/// bbtns the drag up_ item click.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnDragUp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor.StartDragUp();
|
|
}
|
|
|
|
/// <summary>
|
|
/// bbtns the drag down_ item click.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnDragDown_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor.StartDragDown();
|
|
}
|
|
|
|
/// <summary>
|
|
/// bbtns the draw away_ item click.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnDrawAway_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor.StartDragAway();
|
|
}
|
|
/// <summary>
|
|
/// 平滑按钮点击事件
|
|
/// </summary>
|
|
/// <param name="sender">事件按钮</param>
|
|
/// <param name="e">事件参数</param>
|
|
private void bbtnSmooth_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor.StartSmooth();
|
|
}
|
|
/// <summary>
|
|
/// 数据回传事件
|
|
/// </summary>
|
|
/// <param name="sender">事件按钮</param>
|
|
/// <param name="e">事件参数</param>
|
|
private void bbtnSendBackData_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
WriteBack();
|
|
PushDataClick?.Invoke(sender, e);
|
|
}
|
|
|
|
private void WriteBack()
|
|
{
|
|
List<long> destroyPositions = new List<long>();
|
|
List<long> insertedPositions = new List<long>();
|
|
|
|
meshEditor.PushbackData(meshEditor.ContourLayerName, destroyPositions, insertedPositions, meshEditor.LineLayerName, meshEditor.LineLayerNoName);
|
|
|
|
geo.DestroyAndInsertElement(destroyPositions.ToArray(), insertedPositions.ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭按钮单击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void bbtnClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
/// <summary>
|
|
/// 参数修改事件
|
|
/// </summary>
|
|
/// <param name="s">属性控件</param>
|
|
/// <param name="e">事件参数</param>
|
|
private void ppgParameter_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
|
|
{
|
|
var editorParameter = this.ppgParameter.SelectedObject as GridEditorParameter;
|
|
if (editorParameter == null)
|
|
return;
|
|
|
|
string propName = e.Row.Properties.FieldName; // 用字段名匹配而不是 Caption
|
|
|
|
switch (propName)
|
|
{
|
|
case nameof(GridEditorParameter.DecimalNumber):
|
|
{
|
|
int num = editorParameter.DecimalNumber;
|
|
if (num > 0 && num < 10)
|
|
{
|
|
int oldNum = meshEditor.GetDecimalNumber();
|
|
if (num != oldNum)
|
|
{
|
|
meshEditor.SetDecimalNumber(num);
|
|
ppgParameter.Refresh();
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
case nameof(GridEditorParameter.WellPointColor):
|
|
meshEditor.SetWellColor(editorParameter.WellPointColor);
|
|
break;
|
|
|
|
case nameof(GridEditorParameter.FontSize):
|
|
meshEditor.SetWellTxtSize((float)editorParameter.FontSize);
|
|
break;
|
|
|
|
case nameof(GridEditorParameter.EnablePickMeshZ):
|
|
meshEditor.EnablePickMeshZ(editorParameter.EnablePickMeshZ);
|
|
break;
|
|
|
|
case nameof(GridEditorParameter.EnableFillFault):
|
|
meshEditor.EnableFillFault(editorParameter.EnableFillFault);
|
|
break;
|
|
|
|
case nameof(GridEditorParameter.OperatorRadius):
|
|
case nameof(GridEditorParameter.Strength):
|
|
case nameof(GridEditorParameter.ComputeType):
|
|
// 这几个属于画刷相关参数,不需要立即调用 SetProperty
|
|
break;
|
|
|
|
default:
|
|
meshEditor.SetProperty(
|
|
editorParameter.ContourSpace,
|
|
editorParameter.MarkStep,
|
|
editorParameter.ContourMinValue,
|
|
editorParameter.ContourMaxValue,
|
|
editorParameter.ZMin,
|
|
editorParameter.ZMax);
|
|
break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 图层选中变化事件
|
|
/// </summary>
|
|
/// <param name="sender">图层树</param>
|
|
/// <param name="e">事件参数</param>
|
|
private void trvLayer_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
|
|
{
|
|
string strText = e.Node.GetDisplayText(0);
|
|
bool bShow = e.Node.Checked;
|
|
switch (strText)
|
|
{
|
|
case "网格":
|
|
meshEditor.ShowMesh(bShow);
|
|
//Trace.WriteLine(bShow.ToString());
|
|
break;
|
|
case "等值线":
|
|
meshEditor.ShowIsopleth(bShow);
|
|
break;
|
|
case "断层":
|
|
meshEditor.ShowFault(bShow);
|
|
break;
|
|
case "控制点":
|
|
meshEditor.ShowControlPoint(bShow);
|
|
break;
|
|
case "边界":
|
|
meshEditor.ShowBound(bShow);
|
|
break;
|
|
case "附加线":
|
|
meshEditor.ShowOtherLines(bShow);
|
|
break;
|
|
case "网格点":
|
|
meshEditor.ShowMeshVertex(bShow);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ppgs the parameter_ custom property descriptors.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void ppgParameter_CustomPropertyDescriptors(object sender, DevExpress.XtraVerticalGrid.Events.CustomPropertyDescriptorsEventArgs e)
|
|
{
|
|
if (e.Context.PropertyDescriptor == null)
|
|
{
|
|
e.Properties = e.Properties.Sort(new string[] {
|
|
"OperatorRadius"
|
|
,"Strength"
|
|
,"ComputeType"
|
|
,"ContourSpace"
|
|
, "MarkStep"
|
|
, "ContourMinValue"
|
|
, "ContourMaxValue"
|
|
,"ZMin"
|
|
,"ZMax"});
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 窗体关闭事件
|
|
/// </summary>
|
|
/// <param name="sender">窗体</param>
|
|
/// <param name="e">事件参数</param>
|
|
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (meshEditor.IsSaved == false
|
|
&& meshEditor?.CanUndo() == true)
|
|
{
|
|
DialogResult result = MessageBox.Show(this, "文件已经修改,是否保存?"
|
|
, "退出", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
WriteBack();
|
|
PushDataClick?.Invoke(sender, e);
|
|
}
|
|
else if (result == DialogResult.Cancel)
|
|
{
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void meshEditor_Load(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
private void bbtnOffsetFault_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor?.OffsetFault();
|
|
}
|
|
#region 二期功能
|
|
/// <summary>
|
|
/// 井点匹配点击事件.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnPointAdapt_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
var points = meshEditor.GetPointList();
|
|
var validPoints = points
|
|
.Where(p => !double.IsNaN(p.Z) && p.Z > -1e100)
|
|
.ToArray();
|
|
|
|
if (validPoints.Length <= 1)
|
|
{
|
|
XtraMessageBox.Show(this, "合法数据点必须大于1个", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
List<double> dataForX = validPoints.Select(p => p.X).ToList();
|
|
List<double> dataForY = validPoints.Select(p => p.Y).ToList();
|
|
List<double> dataForZ = validPoints.Select(p => p.Z).ToList();
|
|
List<double> dataForTZ = validPoints.Select(p => p.TZ).ToList();
|
|
List<string> nameList = validPoints.Select(p => p.Name).ToList();
|
|
|
|
FormWellAdjustSetting formWellAdjustSetting = new FormWellAdjustSetting(100, 10, 0);
|
|
formWellAdjustSetting.LoadData(dataForX, dataForY, dataForZ, dataForTZ, nameList);
|
|
if (formWellAdjustSetting.ShowDialog() == DialogResult.OK)
|
|
{
|
|
string selected = formWellAdjustSetting.SelectedMode;
|
|
string method = "井点校正";
|
|
int methodType = 1;
|
|
|
|
//传入控制点
|
|
if (formWellAdjustSetting.SelectedWellPoints.Count > 1)
|
|
{
|
|
meshEditor.SetWellPointList(
|
|
formWellAdjustSetting.SelectedWellPoints.ToArray(),
|
|
formWellAdjustSetting.SelectedWellPoints.Count
|
|
);
|
|
}
|
|
else
|
|
{
|
|
XtraMessageBox.Show(this, "参与运算的控制点过少,至少大于两个!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
int gridNum = formWellAdjustSetting.FeatherWidth;
|
|
int correctionType = formWellAdjustSetting.SmoothRegionIndex;
|
|
|
|
switch (selected)
|
|
{
|
|
case "默认":
|
|
{
|
|
meshEditor.WellAdaptiveAdjust(
|
|
correctionType,
|
|
gridNum,
|
|
(float)formWellAdjustSetting.WellRadius
|
|
, (float)formWellAdjustSetting.ValueRange
|
|
, (float)formWellAdjustSetting.DecreasingFactor);
|
|
|
|
UpdateVolumeDate();
|
|
}
|
|
return;
|
|
//case "克里金": method = "克里金井点校正"; methodType = 1; break;
|
|
case "RBF": method = "RBF井点校正"; methodType = 2; break;
|
|
case "IDW": method = "IDW井点校正"; methodType = 3; break;
|
|
}
|
|
|
|
double valueRange = formWellAdjustSetting.ValueRange;
|
|
double lastValidFactor = formWellAdjustSetting.DilutionFactor;
|
|
bool state = meshEditor.RectificationMeshWellCompute(valueRange, correctionType, gridNum, methodType, lastValidFactor);
|
|
if (!state)
|
|
{
|
|
return;
|
|
}
|
|
|
|
using (var dlg = new FrmRectificationProgress(() => meshEditor.GetWellRectificationProgress(),
|
|
() => meshEditor.MeshWellThreadStop(),
|
|
method))
|
|
{
|
|
var result = dlg.ShowDialog(this);
|
|
if (result != DialogResult.Cancel)
|
|
{
|
|
meshEditor.OSGUpdateObjectView();
|
|
ppgParameter.Refresh();
|
|
UpdateVolumeDate();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 过滤等值线点击事件.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnFilterMesh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
FormFilterMeshSetting formFilterMeshSetting = new FormFilterMeshSetting(30);
|
|
if (formFilterMeshSetting.ShowDialog() == DialogResult.OK)
|
|
{
|
|
meshEditor.FilterMesh((float)formFilterMeshSetting.FilterValue);
|
|
}
|
|
}
|
|
|
|
private float optimizeMeshRadius = 50;
|
|
/// <summary>
|
|
/// bbtns the optimize mesh_ item click.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnOptimizeMesh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
optimizeMeshRadius = Convert.ToSingle(btxtOptimize.EditValue);
|
|
meshEditor.StartOptimizeMesh(optimizeMeshRadius);
|
|
}
|
|
|
|
/// <summary>
|
|
/// btxts the optimize_ edit value changed.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void btxtOptimize_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
optimizeMeshRadius = Convert.ToSingle(btxtOptimize.EditValue);
|
|
meshEditor.OptimizeMeshRadius = optimizeMeshRadius;
|
|
}
|
|
/// <summary>
|
|
/// 区域控制.
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The e.</param>
|
|
private void bbtnPolygonOperator_DownChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
meshEditor?.EnableDrawPolygon(bbtnPolygonOperator.Down);
|
|
}
|
|
private void bbtnDragUpPolygon_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
bool isChecked = Convert.ToBoolean(barEditItem1.EditValue);
|
|
meshEditor?.StretchUpPolygon(isChecked);
|
|
}
|
|
|
|
private void bbtnDragDownPolygon_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
bool isChecked = Convert.ToBoolean(barEditItem1.EditValue);
|
|
meshEditor?.PushDownPolygon(isChecked);
|
|
}
|
|
|
|
private void bbtnSmoothPolygon_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
bool isChecked = Convert.ToBoolean(barEditItem1.EditValue);
|
|
meshEditor?.SmoothPolygon(isChecked);
|
|
}
|
|
#endregion
|
|
|
|
private int influenceRadius = 30; //初始影响半径
|
|
private int strengthPercentage = 10; //初始力度百分比
|
|
private bool isAltPressed = false; //是否按下 ALT 键
|
|
|
|
/// <summary>
|
|
/// 设置控件节点value
|
|
/// </summary>
|
|
/// <param name="targetName">控件名</param>
|
|
/// <param name="value">值</param>
|
|
private void SetEditorValue(string targetName, int value)
|
|
{
|
|
foreach (BaseRow row in ppgParameter.Rows)
|
|
{
|
|
if (row is CategoryRow categoryRow)
|
|
{
|
|
foreach (BaseRow childRow in categoryRow.ChildRows)
|
|
{
|
|
if (childRow.Properties.Caption == targetName)
|
|
{
|
|
childRow.Properties.Value = value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnRadiusUp()
|
|
{
|
|
influenceRadius += 5;
|
|
if (influenceRadius > 300)
|
|
{
|
|
influenceRadius = 300;
|
|
}
|
|
|
|
SetEditorValue("影响半径", influenceRadius);
|
|
meshEditor?.SetDrawCircle();
|
|
}
|
|
|
|
private void OnRadiusDown()
|
|
{
|
|
influenceRadius -= 5;
|
|
if (influenceRadius < 1)
|
|
{
|
|
influenceRadius = 1;
|
|
}
|
|
SetEditorValue("影响半径", influenceRadius);
|
|
meshEditor?.SetDrawCircle();
|
|
}
|
|
|
|
private void OnPressureUp()
|
|
{
|
|
strengthPercentage += 5;
|
|
if (strengthPercentage > 100)
|
|
{
|
|
strengthPercentage = 100;
|
|
}
|
|
SetEditorValue("力度", strengthPercentage);
|
|
}
|
|
|
|
private void OnPressureDown()
|
|
{
|
|
strengthPercentage -= 5;
|
|
if (strengthPercentage < 1)
|
|
{
|
|
strengthPercentage = 0;
|
|
}
|
|
SetEditorValue("力度", strengthPercentage);
|
|
}
|
|
|
|
private void UpdateStatus(bool state)
|
|
{
|
|
if (state)
|
|
{
|
|
this.bbtnDragDown.Down = true;
|
|
isAltPressed = true;
|
|
meshEditor?.StartDragDown();
|
|
}
|
|
else
|
|
{
|
|
this.bbtnDragUp.Down = true;
|
|
isAltPressed = false;
|
|
meshEditor?.StartDragUp();
|
|
}
|
|
meshEditor?.SetDrawCircle();
|
|
}
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
{
|
|
base.OnKeyDown(e);
|
|
|
|
// 按下“]”键放大影响半径
|
|
if (e.KeyCode == Keys.OemCloseBrackets)
|
|
{
|
|
OnRadiusUp();
|
|
}
|
|
|
|
// 按下“[”键缩小影响半径
|
|
if (e.KeyCode == Keys.OemOpenBrackets)
|
|
{
|
|
OnRadiusDown();
|
|
}
|
|
|
|
if (e.Shift)
|
|
{
|
|
// 按下“>”增加力度百分比
|
|
if (e.KeyCode == Keys.OemPeriod)
|
|
{
|
|
OnPressureUp();
|
|
}
|
|
|
|
// 按下“<”减少力度百分比
|
|
if (e.KeyCode == Keys.Oemcomma)
|
|
{
|
|
OnPressureDown();
|
|
}
|
|
}
|
|
|
|
if (e.KeyCode == Keys.Oemtilde)
|
|
{
|
|
this.bbtnCloneStamp.Down = true;
|
|
//开始抓取仿制图章标本
|
|
meshEditor.CloneStampCircle();
|
|
}
|
|
|
|
if (e.KeyCode == Keys.Menu)
|
|
{
|
|
if (!isAltPressed)
|
|
{
|
|
UpdateStatus(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnKeyUp(KeyEventArgs e)
|
|
{
|
|
base.OnKeyUp(e);
|
|
|
|
if (e.KeyCode == Keys.Menu)
|
|
{
|
|
if (isAltPressed)
|
|
{
|
|
UpdateStatus(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void bbtnCalculateZ_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
if (calculateZDialog == null)
|
|
{
|
|
calculateZDialog = new CalculateZDialog()
|
|
{
|
|
StartPosition = FormStartPosition.CenterScreen,
|
|
};
|
|
}
|
|
if (calculateZDialog.ShowDialog(this) == DialogResult.OK)
|
|
{
|
|
//运算 传入z值表达式
|
|
string zExpression = calculateZDialog.GetZExpression().ToLower();
|
|
|
|
bool state = meshEditor.CompileExpressionZ(zExpression);
|
|
if (!state)
|
|
{
|
|
MessageBox.Show(this, "公式输入不正确,请检查语法、变量名和括号匹配。", "公式错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
state = meshEditor.CalculateZByExpression(zExpression);
|
|
|
|
if (state)
|
|
{
|
|
ppgParameter.Refresh();
|
|
UpdateVolumeDate();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void barEditItem1_ItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void bbtnFaultControl_CheckedChanged(object sender, ItemClickEventArgs e)
|
|
{
|
|
var item = sender as BarCheckItem;
|
|
if (item.Checked)
|
|
{
|
|
// 处理按下(选中)状态
|
|
meshEditor?.SetFaultControlState(true);
|
|
}
|
|
else
|
|
{
|
|
// 处理释放(未选中)状态
|
|
meshEditor?.SetFaultControlState(false);
|
|
}
|
|
}
|
|
|
|
private void bbtnCloneStamp_ItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
meshEditor.CloneStampCircle();
|
|
}
|
|
|
|
private void bttonFitting_ItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
var points = meshEditor.GetPointList();
|
|
if (points == null || points.Length <= 1)
|
|
{
|
|
XtraMessageBox.Show(this, "数据点必须大于1个", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
var validPoints = points
|
|
.Where(p => !double.IsNaN(p.Z) && p.Z > -1e100)
|
|
.ToArray();
|
|
|
|
if (validPoints.Length <= 1)
|
|
{
|
|
XtraMessageBox.Show(this, "合法数据点必须大于1个", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
|
|
FormFittingTool fittingForm = new FormFittingTool();
|
|
List<double> dataForY = validPoints.Select(p => p.TZ).ToList();
|
|
List<double> dataForZ = validPoints.Select(p => p.Z).ToList();
|
|
List<string> nameList = validPoints.Select(p => p.Name).ToList();
|
|
fittingForm.LoadData(dataForY, dataForZ, nameList, meshEditor.GetZMin(), meshEditor.GetZMax());
|
|
|
|
// 获取校正后的公式
|
|
fittingForm.OnCalibrationComplete += (k, b, formulaStr) =>
|
|
{
|
|
bool state = meshEditor.FittingCorrectionOperation(formulaStr);
|
|
if (state)
|
|
{
|
|
ppgParameter.Refresh();
|
|
UpdateVolumeDate();
|
|
}
|
|
};
|
|
|
|
fittingForm.OnRestore += (s, args) =>
|
|
{
|
|
meshEditor.Undo();
|
|
};
|
|
|
|
fittingForm.Show(this);
|
|
}
|
|
|
|
private void bttonEntireSmooth_ItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
FormSmoothSetting formSmoothSetting = new FormSmoothSetting();
|
|
|
|
if (formSmoothSetting.ShowDialog(this) == DialogResult.OK)
|
|
{
|
|
if (formSmoothSetting.SelectedAlgorithmIndex == 0)
|
|
{
|
|
int smoothType = formSmoothSetting.SmoothRegionIndex;
|
|
double sigma = formSmoothSetting.GaussianRadius;
|
|
int iter = formSmoothSetting.IterationCount;
|
|
int gridNum = formSmoothSetting.FeatherWidth;
|
|
meshEditor.FullSmoothGridGaussian(smoothType, sigma, iter, gridNum);
|
|
}
|
|
else
|
|
{
|
|
int smoothType = formSmoothSetting.SmoothRegionIndex;
|
|
double smooth = formSmoothSetting.SmoothCoefficient;
|
|
int smoothCount = formSmoothSetting.SmoothTimes;
|
|
int gridNum = formSmoothSetting.FeatherWidth;
|
|
meshEditor.FullSmoothIDWMesh(smoothType, smooth, smoothCount, gridNum);
|
|
}
|
|
}
|
|
|
|
UpdateVolumeDate();
|
|
}
|
|
|
|
private void RefreshVolumeData()
|
|
{
|
|
if (volumeStatsForm == null || volumeStatsForm.IsDisposed) return;
|
|
|
|
int method = volumeStatsForm.GetCurrentMethod(); // 0:容积法, 1:等值线法
|
|
int mode = volumeStatsForm.GetCurrentMode(); // 0:构造图, 1:等厚图
|
|
|
|
LineVolumnData[] dataList = null;
|
|
|
|
// 根据方式获取数据
|
|
if (method == 0)
|
|
{
|
|
// --- 容积法 ---
|
|
dataList = meshEditor.GetStatisVolumn(mode);
|
|
}
|
|
else
|
|
{
|
|
// --- 等值线法 ---
|
|
dataList = meshEditor.GetContourStatisVolumn();
|
|
}
|
|
|
|
volumeStatsForm.SetDataSource(dataList);
|
|
}
|
|
|
|
private void bttonVolume_ItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
if (volumeStatsForm == null || volumeStatsForm.IsDisposed)
|
|
{
|
|
volumeStatsForm = new FormVolumeStats();
|
|
volumeStatsForm.StartPosition = FormStartPosition.CenterScreen;
|
|
|
|
// 绑定事件
|
|
volumeStatsForm.ModeChanged += (s, idx) => RefreshVolumeData();
|
|
volumeStatsForm.MethodChanged += (s, idx) => RefreshVolumeData();
|
|
|
|
// 初始加载数据
|
|
RefreshVolumeData();
|
|
volumeStatsForm.Show(this);
|
|
}
|
|
else
|
|
{
|
|
volumeStatsForm.Activate();
|
|
volumeStatsForm.Visible = true;
|
|
RefreshVolumeData();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新面积权衡实时查看器 数据
|
|
/// </summary>
|
|
private void UpdateVolumeDate()
|
|
{
|
|
if (volumeStatsForm != null && volumeStatsForm.Visible && !volumeStatsForm.IsDisposed)
|
|
{
|
|
RefreshVolumeData();
|
|
}
|
|
}
|
|
|
|
private void UpdateVolumeChanged(object sender, EventArgs e)
|
|
{
|
|
if (volumeStatsForm != null && volumeStatsForm.Visible && !volumeStatsForm.IsDisposed)
|
|
{
|
|
RefreshVolumeData();
|
|
}
|
|
}
|
|
|
|
private void bttonDragShape_ItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
meshEditor.DragShape();
|
|
}
|
|
|
|
private void UpdateTrendPtChanged(object sender, EventArgs e)
|
|
{
|
|
if (trendForm != null && !trendForm.IsDisposed)
|
|
{
|
|
trendForm.ReleasePickButton();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void bttnTrend_ItemClick(object sender, ItemClickEventArgs e)
|
|
{
|
|
if (trendForm != null && !trendForm.IsDisposed)
|
|
{
|
|
trendForm.Activate(); // 如果已打开,直接置顶显示
|
|
return;
|
|
}
|
|
|
|
trendForm = new FormTrend();
|
|
trendForm.Owner = this;
|
|
trendForm.StartPosition = FormStartPosition.CenterParent;
|
|
|
|
// 这里的 ipx, ipy 建议在事件内部实时获取,否则窗口缩放后中心点就变了
|
|
trendForm.TrendDataChanged += (s, args) =>
|
|
{
|
|
// 实时获取当前中心点
|
|
int currentIpx = this.meshEditor.Width / 2;
|
|
int currentIpy = this.meshEditor.Height / 2;
|
|
|
|
switch (args.OperateType)
|
|
{
|
|
case TrendOperateType.Update:
|
|
if (args.ActiveTrend != null)
|
|
{
|
|
// 只有当主界面处于“拾取模式”且确实点了一下时,才覆盖模型坐标
|
|
if (this.meshEditor.CommandStatus == OperaCommandType.PickTrendLocation &&
|
|
(this.meshEditor.mouseTrendPt.X > 0 || this.meshEditor.mouseTrendPt.Y > 0))
|
|
{
|
|
args.ActiveTrend.Cx = this.meshEditor.mouseTrendPt.X;
|
|
args.ActiveTrend.Cy = this.meshEditor.mouseTrendPt.Y;
|
|
|
|
// 拾取存入模型后,立刻清空临时点,防止后续其他项 Update 时误用
|
|
this.meshEditor.mouseTrendPt.X = 0;
|
|
this.meshEditor.mouseTrendPt.Y = 0;
|
|
}
|
|
|
|
int tx = args.ActiveTrend.Cx > 0 ? (int)args.ActiveTrend.Cx : currentIpx;
|
|
int ty = args.ActiveTrend.Cy > 0 ? (int)args.ActiveTrend.Cy : currentIpy;
|
|
|
|
meshEditor.DrawTrendArrowOnWindow(args.ActiveTrend.Name, tx, ty,
|
|
(float)args.ActiveTrend.Angle, (float)args.ActiveTrend.Ratio);
|
|
}
|
|
break;
|
|
|
|
case TrendOperateType.Delete:
|
|
meshEditor.ClearTrendArrow(args.DeletedName);
|
|
break;
|
|
|
|
case TrendOperateType.Close:
|
|
meshEditor.ClearAllTrendArrows();
|
|
// 窗口关闭时,主界面状态也应重置
|
|
this.meshEditor.CommandStatus = OperaCommandType.Unknown;
|
|
this.meshEditor.mouseTrendPt.X = 0;
|
|
this.meshEditor.mouseTrendPt.Y = 0;
|
|
break;
|
|
|
|
case TrendOperateType.PickLocation:
|
|
meshEditor.StartTrendPt();
|
|
break;
|
|
}
|
|
};
|
|
|
|
trendForm.Show();
|
|
}
|
|
}
|
|
}
|