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); /// /// The form main. /// public partial class FormMain : DevExpress.XtraEditors.XtraForm { /// /// 鼠标移动事件 /// public EditorMouseMoveEventHandler EditorMouseMoveEvent; /// /// 模块进程名称 /// public static string ProcessName { get; set; } = "沉积相编辑系统"; public EventHandler PushDataClick; private GeoSigmaXY geo; private IntPtr pxy = IntPtr.Zero; private Dictionary faciesMap; private Color curFaciesColor = Color.FromArgb(0, 0, 0); /// /// Initializes a new instance of the class. /// public FormMain() { InitializeComponent(); this.KeyPreview = true; this.Text = ProcessName; this.trvLayer.ExpandAll(); this.ppgParameter.SelectedObject = meshEditor.KedEditorParameter; this.faciesMap = new Dictionary(); 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); } /// /// Initializes a new instance of the class. /// /// The p xy. public FormMain(GeoSigmaXY geo, string contourLayer, string faultLayer, string pointLayer, string otherLineLayer , Dictionary 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; } } /// /// 打开文件 /// /// /// private void bbtnOpenFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { meshEditor.OpenFile(); this.ppgParameter.SelectedObject = null; this.ppgParameter.SelectedObject = meshEditor.KedEditorParameter; } /// /// Form1_S the load. /// /// The sender. /// The e. 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(); } /// /// Application_S the idle. /// /// The sender. /// The e. 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; } } /// /// btns the view all_ item click. /// /// The sender. /// The e. private void btnViewAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { meshEditor.Editor?.ZoomView(); } /// /// bbtns the undo_ item click. /// /// The sender. /// The e. private void bbtnUndo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { meshEditor.Undo(); ppgParameter.Refresh(); } /// /// bbtns the redo_ item click. /// /// The sender. /// The e. private void bbtnRedo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { meshEditor.Redo(); ppgParameter.Refresh(); } /// /// 数据回传事件 /// /// 事件按钮 /// 事件参数 private void bbtnSendBackData_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { WriteBack(); PushDataClick?.Invoke(sender, e); } private void WriteBack() { List destroyPositions = new List(); List insertedPositions = new List(); meshEditor.PushbackData(meshEditor.ContourLayerName, destroyPositions, insertedPositions, meshEditor.LineLayerName, meshEditor.LineLayerNoName); geo.DestroyAndInsertElement(destroyPositions.ToArray(), insertedPositions.ToArray()); } /// /// 关闭按钮单击事件 /// /// /// private void bbtnClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.Close(); } /// /// 参数修改事件 /// /// 属性控件 /// 事件参数 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; } } } /// /// 图层选中变化事件 /// /// 图层树 /// 事件参数 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; } } /// /// ppgs the parameter_ custom property descriptors. /// /// The sender. /// The e. 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"}); } } /// /// 窗体关闭事件 /// /// 窗体 /// 事件参数 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(); 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 } }