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.

490 lines
17 KiB
C#

using DevExpress.XtraBars;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using GeoSigmaDrawLib;
using MeshProcess;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace KedGridEditor
{
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 Dictionary<string, int> faciesMap;
private Color curFaciesColor = Color.FromArgb(0, 0, 0);
/// <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.ppgParameter.SelectedObject = meshEditor.KedEditorParameter;
this.faciesMap = new Dictionary<string, int>();
this.faciesMap.Clear();
// 颜色编辑器设置
RepositoryItemColorPickEdit riColorEdit = new RepositoryItemColorPickEdit();
riColorEdit.ShowCustomColors = true; // 显示自定义颜色列表
riColorEdit.ShowSystemColors = false; // 显示系统颜色
riColorEdit.ShowWebColors = false; // 显示系统颜色
riColorEdit.ShowAutomaticButton = true;
riColorEdit.ShowMoreColorsButton = true;
riColorEdit.ShowColorDialog = true;
// 注册为 PropertyGrid 的默认颜色编辑器
this.ppgParameter.RepositoryItems.Add(riColorEdit);
this.ppgParameter.DefaultEditors.Add(typeof(Color), riColorEdit);
// 布尔类型编辑器
RepositoryItemCheckEdit riCheckEdit = new RepositoryItemCheckEdit();
riCheckEdit.CheckStyle = CheckStyles.Standard;
this.ppgParameter.DefaultEditors.Add(typeof(Boolean), riCheckEdit);
}
/// <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
, Dictionary<string, int> map)
: this()
{
this.geo = geo;
this.pxy = this.geo.GetDrawerXy();
faciesMap = map;
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.KedEditorParameter;
}
/// <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, 1);
// 打开时启用 “断层填充” 和 “断层边缘优化”
meshEditor.EnableFillFault(true);
meshEditor.OffsetFault();
this.ppgParameter.SelectedObject = null;
this.ppgParameter.SelectedObject = meshEditor.KedEditorParameter;
}
meshEditor.SetMouseMoveEvent(EditorMouseMoveEvent);
Application.Idle += Application_Idle;
SetFaciesTypeMap();
}
/// <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.bbtnPolygonChange.Enabled = bbtnPolygonF.Down;
this.bbtnPolygonSmooth.Enabled = bbtnPolygonF.Down;
}
}
/// <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.Editor?.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>
/// 数据回传事件
/// </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 ppgParameterKed_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
{
KedGridEditorParameter editorParameter = this.ppgParameter.SelectedObject as KedGridEditorParameter;
if (editorParameter == null)
return;
switch (e.Row.Properties.FieldName)
{
case nameof(KedGridEditorParameter.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(KedGridEditorParameter.WellPointColor):
meshEditor.SetWellColor(editorParameter.WellPointColor);
break;
case nameof(KedGridEditorParameter.FontSize):
meshEditor.SetWellTxtSize((float)editorParameter.FontSize);
break;
case nameof(KedGridEditorParameter.EnablePickMeshZ):
meshEditor.EnablePickMeshZ(editorParameter.EnablePickMeshZ);
break;
case nameof(KedGridEditorParameter.FaciesType):
{
if (faciesMap.TryGetValue(editorParameter.FaciesType, out int faciesId))
{
// 同步到 meshEditor
if (meshEditor.FaciesValueType != faciesId)
meshEditor.FaciesValueType = faciesId;
//切换处理项颜色
int r = 0, g = 0, b = 0;
meshEditor.GetColorByZ(faciesId, ref r, ref g, ref b);
editorParameter.FaciesColor = Color.FromArgb(r, g, b);
curFaciesColor = editorParameter.FaciesColor;
}
break;
}
case nameof(KedGridEditorParameter.FaciesColor):
{
if (curFaciesColor == editorParameter.FaciesColor)
return;
//修改相颜色
int r = editorParameter.FaciesColor.R;
int g = editorParameter.FaciesColor.G;
int b = editorParameter.FaciesColor.B;
meshEditor.SetColorByZ(meshEditor.FaciesValueType, r, g, b);
curFaciesColor = editorParameter.FaciesColor;
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.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 ppgParameterKed_CustomPropertyDescriptors(object sender, DevExpress.XtraVerticalGrid.Events.CustomPropertyDescriptorsEventArgs e)
{
if (e.Context.PropertyDescriptor == null)
{
e.Properties = e.Properties.Sort(new string[] {
"FaciesType"
,"FaciesColor"
,"OperatorRadius"
,"Strength"});
}
}
/// <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)
{
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
}
#region 沉积相
//设置沉积相z值
public void SetFaciesTypeMap()
{
if (faciesMap == null)
faciesMap = new Dictionary<string, int>();
if (faciesMap.Count == 0)
{
int count = 0;
IntPtr ptr = meshEditor.GetFaciesList(ref count);
if (count == 0 || ptr == IntPtr.Zero)
return;
int[] faciesList = new int[count];
Marshal.Copy(ptr, faciesList, 0, count);
Marshal.FreeCoTaskMem(ptr);
faciesMap.Clear();
foreach (int id in faciesList)
{
string key = id.ToString(); // 暂用 ID 作为 key
faciesMap[key] = id;
}
}
meshEditor.KedEditorParameter.FaciesOptions.Clear();
foreach (var kv in faciesMap)
{
meshEditor.KedEditorParameter.FaciesOptions.Add(kv.Key);
}
// 设置默认选中项
if (meshEditor.KedEditorParameter.FaciesOptions.Count > 0)
{
meshEditor.KedEditorParameter.FaciesType = meshEditor.KedEditorParameter.FaciesOptions[0];
meshEditor.FaciesValueType = faciesMap[meshEditor.KedEditorParameter.FaciesType];
int r = 0, g = 0, b = 0;
meshEditor.GetColorByZ(meshEditor.FaciesValueType, ref r, ref g, ref b);
meshEditor.KedEditorParameter.FaciesColor = Color.FromArgb(r, g, b);
curFaciesColor = Color.FromArgb(r, g, b);
}
ppgParameter.Refresh();
}
private void bttonBrushColor_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor.EnableDrawPolygon(false);
meshEditor.BrushSetCircleZ(this.bttonBrushColor.Down);
}
private void bttonFeatherBrush_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor.EnableDrawPolygon(false);
meshEditor.FeatherBrush(this.bttonFeatherBrush.Down);
}
private void bttonBrushSmooth_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor.EnableDrawPolygon(false);
meshEditor.BrushSmoothCircle(bttonBrushSmooth.Down);
}
private void bttonErase_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor.EnableDrawPolygon(false);
meshEditor.BrushEraseCircle(this.bttonErase.Down);
}
private void bttonMagic_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor.EnableDrawPolygon(false);
meshEditor.FaciesMagicWand(this.bttonMagic.Down);
}
private void bbtnPolygonF_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor?.FaciesEnableDrawPolygon(bbtnPolygonF.Down);
}
private void bbtnPolygonChange_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor?.FaciesPolygonLassoZ();
}
private void bbtnPolygonSmooth_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor?.FaciesPolygonLassoSmooth();
}
private void bttonFullImageSmooth_ItemClick(object sender, ItemClickEventArgs e)
{
meshEditor?.FaciesFullImageSmooth();
}
#endregion
}
}