// // Copyright (c) PlaceholderCompany. All rights reserved. // using Detria; using DevExpress.XtraCharts; using DevExpress.XtraRichEdit.Model; using Fasterflect; using GeoSigma.SigmaDrawerElement; using GeoSigma.UCDraw.WellAndSection; using GeoSigmaDrawLib; using InterfaceWorkAreaData; //using DQ.Construction.NewLook.Utility; using InterfaceWorkAreaData.LoadCurveData; using NetTopologySuite; using NetTopologySuite.Algorithm; using NetTopologySuite.Geometries; using NetTopologySuite.Operation.Distance; using NetTopologySuite.Operation.Overlay; using NetTopologySuite.Operation.OverlayNG; using NetTopologySuite.Precision; using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; using WorkData; using WorkData.Entity; using Math = System.Math; namespace UCDraw { //public delegate void StatusColumnInfo(string msg); //public delegate void EmptyNameCurveLoadHandler(string itemString); //public delegate void ViewerTipMessageHandler(string tipMessage); //public delegate void DrawerViewChangeLayerEvent(string eventKind); //public delegate void MainViewInfoHandler(string info); public partial class WellSectionDrawViewer : WellBaseDrawView { private double smallScollFactor = 0.02; private double largeScrollFactor = 0.9; private int scrollPositionYLast = 0; private bool needHScrollToEnd = false; private bool needHScrollToBegin = false; private bool needVScrollToTop = false; private bool needVScrollToBottom = false; #region 打印 private PrinterStatus printerStatus = null; private PrinterDrawer printerDrawer; private PrintPreviewControl printPreview; private ViewFactor viewFactor; //进入打印预览后,可能会改变视图。待退出打印预览后,恢复原来的视图。 #endregion public WellSectionDrawViewer(GeoSigmaXY.eViewType vType = GeoSigmaXY.eViewType.plane) { mViewType = vType; System.Security.Cryptography.RNGCryptoServiceProvider csp = new System.Security.Cryptography.RNGCryptoServiceProvider(); byte[] byteCsp = new byte[10]; csp.GetBytes(byteCsp); ID = BitConverter.ToInt32(byteCsp, 0); InitializeComponent(); InitDrawer(); this.Drawer.mViewType = vType; this.BorderStyle = BorderStyle.None; //.Dock = DockStyle.Fill; //pnlMain.Controls.Add(draw1); //HRuler.Size = new Size(HRuler.Size.Width, 20); pnlMain.Refresh(); //hRuler1.InitTransform(drawer1.GetRangeGetter()); //vRuler1.InitTransform(drawer1.GetRangeGetter()); //drawer1.MouseMove += hRuler1.ProcessMouseMove; //drawer1.DrawerZoomIn += hRuler1.Zoom; //drawer1.DrawerZoomOut += hRuler1.Zoom; //drawer1.DrawerViewAll += hRuler1.Zoom; //drawer1.DrawerViewPan += hRuler1.ReDraw; //drawer1.DrawerOnPaint += hRuler1.ReDraw; //drawer1.MouseMove += vRuler1.ProcessMouseMove; //drawer1.DrawerZoomIn += vRuler1.Zoom; //drawer1.DrawerZoomOut += vRuler1.Zoom; //drawer1.DrawerViewAll += vRuler1.Zoom; //drawer1.DrawerViewPan += vRuler1.ReDraw; //drawer1.DrawerOnPaint += vRuler1.ReDraw; //drawer1.DrawerPrintPreview += PreviewPrint; //drawer1.DrawerChangedViewBySynchronizeEvent += (drawer, e) => //{ // vRuler1.Invalidate(); // hRuler1.Invalidate(); //}; //this.MouseWheel+=Viewer_MouseWheel; //this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); //this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.drawer1.SetScrollBar += SetScrollBar; this.drawer1.DrawerScroll += ScrollScreenAndBar; this.drawer1.DrawerWheel += ScrollByWheel; // drawer1.DrawerGotFocus += drawer1_DrawerGotFocus; drawer1.ENCurveLoadHandler += HandleEmptyNameCurve; #region 打印 //NewMethod(); #endregion // drawer1.DrawerCommandStart += OnCommandStart; // drawer1.DrawerCommandFinish += OnCommandFinish; //drawer1.TipMessageHandler += ShowTipMessage; drawer1.ChangeLayerEvent += OnChangeLayer; drawer1.GetLengthAngleEvent += GetLengthAngle; drawer1.m_GetWellPoleDocContextMenu = new Drawer.DeletateGetWellPoleDocContextMenu(this.getWellSectionDocContextMenu);// WellPoleDrawViewer.getWellPoleDocContextMenu); } //public void SetDrawerMouseLocation(double dx, double dy) //{ // drawer1?.SetMouseLocation(dx, dy); //} /// /// 导出到图片 /// /// 文件路径 /// 是否成功 //public bool Export2Image(string fileFullPath) //{ // return this.Drawer.Export2Image(fileFullPath); //} //public void GetLengthAngle(string info) //{ // GetLengthAngleEvent?.Invoke(info); //} ///// ///// 曲线加密 ///// //public void CurveExcuteDensity() //{ // this.Drawer?.CurveExcuteDensity(); //} ///// ///// 多边形连接. ///// ///// An int. //public int CurveConnect(bool deleteOrignalCurves = false) //{ // if (this.Drawer == null) // { // return 0; // } // return this.Drawer.CurveConnect(deleteOrignalCurves); //} ///// ///// 曲线冗余处理 ///// //public void CurveRedundancy() //{ // this.Drawer?.CurveRedundancy(); //} ///// ///// 添加线 ///// ///// 图层 ///// 线名 ///// 坐标点 //public void AddDrawCurve(string layerName, string name, List pts) //{ // if (this.Drawer == null) // { // return; // } // this.Drawer.AddCurve(layerName, name, pts); //} ///// ///// 添加地震剖面 ///// ///// 属性数据 ///// 图元索引 //public long AddSeismicSection(string sectionData, float[] values) //{ // return this.Drawer.AddSeismicSection(sectionData, values); //} //public void DeleteSectionAll() //{ // this.Drawer.DeleteSeismicSection(); //} ///// ///// 删除剖面 ///// ///// 图元 ///// 是否成功 //public bool DeleteSeismicSection(long pos) //{ // return this.Drawer.DeleteSeismicSection(pos); //} ///// ///// 删除图元 ///// ///// 图层名称 ///// 图元名称 ///// 删除的数量 //public int DeleteElement(string layerName, string eleName) //{ // return this.Drawer.DeleteElement(layerName, eleName); //} ///// ///// 删除点图元 ///// ///// 层名 ///// 点名称 ///// 删除个数 //public int DeletePoint(string layerName, string eleName) //{ // return this.Drawer.DeletePoint(layerName, eleName); //} ///// ///// 删除点数据 ///// ///// 图层名称 ///// 点数据名称列表 //public void DeletePoints(string layerName, List eleNames) //{ // foreach (string name in eleNames) // { // this.Drawer.DeletePoint(layerName, name); // } //} //public void DeletePoints(string layerName, List pts) //{ // this.Drawer.DeletePoints(layerName, pts); //} private void InitPrint() { if (printerStatus != null) return; viewFactor = new ViewFactor(); viewFactor.zoomFactor = 1; printerStatus = new PrinterStatus(); printPreview = new PrintPreviewControl(); printerDrawer = new PrinterDrawer(printerStatus, printPreview); pnlMain.Controls.Add(printPreview); } //public void CutX()//fbw //{ // drawer1?.Cutx(); //} //public void Copy()//fbw //{ // drawer1?.Copy(); //} //public void Paste()//fbw //{ // drawer1?.Paste(); //} ///// ///// 截取窗口图形. ///// //public void ImageCutWindow() //{ // drawer1?.ImageCutWindow(); // drawer1?.ShowClipboardSketch(); //} //public void ImageCutAll() //{ // drawer1?.ImageCutAll(); // drawer1?.ShowClipboardSketch(); //} //public void SwitchGrid() //{ // bShowGrid = !bShowGrid; // geoSigma.SigmaView_ShowBKGrid(bShowGrid ? 1 : 0); // drawer1.ReDraw(); //} //public void DisplayBackgroundGrid(bool show) //{ // geoSigma.SigmaView_ShowBKGrid(show ? 1 : 0); // drawer1.ReDraw(); //} //public void EnableHeighLight(bool enable) //{ // drawer1?.EnableHeighLight(enable); //} //public void Redraw() //{ // drawer1?.ReDraw(); //TODO:drawer1重命名 //} ////通过DrawView调用Undo/Redo功能 因为有的Undo/Redo需要用到HDC //public int Undo() //{ // return (drawer1?.Undo()).Value; //} //public int Redo() //{ // return (drawer1?.Redo()).Value; //} //public GeoSigmaXY GetGeoSigma() //{ // return geoSigma; //} //public GeoSigmaXY GeoSigma //{ // get // { // return geoSigma; // } //} //public void SelectAll() //{ // drawer1?.SelectAll(); //} //public void SelectAllPoint() //{ // drawer1?.SelectAllPoint(); //} //public void SelectAllCurve() //{ // drawer1?.SelectAllCurve(); //} //public void ToolRestore() //{ // drawer1?.RestoreTool(); //} //public void RestoreToolDefault() //{ // drawer1?.RestoreToolDefault(); //} ////private DrawToolType activeTool; // active drawing tool ////private DrawTool[] tools; // array of tools ///// ///// Active drawing tool. ///// //public DrawToolType ActiveTool //{ // get // { // return drawer1.ActiveTool; // } // set // { // drawer1.ActiveTool = value; // } //} //private bool enableMeshPack = true; //public bool EnableMeshPack //{ // get // { // return enableMeshPack; // } // set // { // enableMeshPack = value; // } //} //public ViewOperationKind GetViewOperationKind() //{ // return drawer1.ViewOpKind; //} //public void SetViewOperationKind(ViewOperationKind kind) //{ // drawer1.SetViewOperationKind(kind); //} //private void SetStateOfControls() //{ // if (needHScrollToEnd) // { // scrollH.Value = scrollH.Maximum - scrollH.LargeChange + 1; // needHScrollToEnd = false; // } // if (needHScrollToBegin) // { // scrollH.Value = scrollH.Minimum; // needHScrollToBegin = false; // } // if (needVScrollToBottom) // { // int nCurValue = scrollV.Maximum - scrollV.LargeChange + 1; // if (nCurValue > scrollV.Maximum) // { // nCurValue = scrollV.Maximum; // } // scrollV.Value = nCurValue; // needVScrollToBottom = false; // } // if (needVScrollToTop) // { // scrollV.Value = scrollV.Minimum; // needVScrollToTop = false; // } //} protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); //Application.Idle += Application_Idle; } protected override void OnHandleDestroyed(EventArgs e) { base.OnHandleDestroyed(e); //Application.Idle -= Application_Idle; } //private void Application_Idle(object sender, EventArgs e) //{ // SetStateOfControls(); //} //public bool ReloadFile() //{ // try // { // geoSigma = drawer1.ReloadFile(); // // hRuler1.InitGeo(geoSigma); // // vRuler1.InitGeo(geoSigma); // } // catch (Exception ex) // { // Console.WriteLine(ex.Message); // return false; // } // if (geoSigma == null) // { // return false; // } // // Geo.EnableMeshPackage(EnableMeshPack); // Redraw(); // return true; //} //public override bool OpenFile(string filePath, GeoSigmaXY.eViewType vType = GeoSigmaXY.eViewType.plane) //{ // try // { // geoSigma = drawer1.OpenFile(filePath,vType); // if (geoSigma == null) // { // return false; // } // // geoSigma.EnableMeshPackage(this.enableMeshPack); // } // catch (Exception ex) // { // Console.WriteLine(ex.Message); // return false; // } // // SetScrollBar(); // if (geoSigma == null) // { // return false; // } // return true; //} //public void ClearGeo() //{ // drawer1.ClearGeo(); //} //public bool OpenXy(IntPtr pxy) //{ // try // { // geoSigma = drawer1.OpenXy(pxy); // // geoSigma.EnableMeshPackage(this.enableMeshPack); // // hRuler1.InitGeo(geoSigma); // // vRuler1.InitGeo(geoSigma); // } // catch (Exception ex) // { // Console.WriteLine(ex.Message); // return false; // } // // SetScrollBar(); // if (geoSigma == null) // { // return false; // } // return true; //} //public void SetBackColor(int r, int g, int b) //{ // if (geoSigma == null) // { // return; // } // drawer1.ViewBackColor = Color.FromArgb(r, g, b); // //geoSigma.SetViewBackcolor(r, g, b); //} //public void SetSymbolView(bool isSymbolView) //{ // if (geoSigma == null) // { // return; // } // geoSigma.SetSymbolView(isSymbolView); //} //public bool SaveFile(string fileName) //{ // if (geoSigma == null) return false; // return geoSigma.SaveDocument(fileName); //} //public bool SaveFile(string fileName, double leftMargin, double rightMargin, // double topMargin, double bottomMargin, int paperSizeType, int pdfAHType, int pdfPapertDirectionType) //{ // if (geoSigma == null) return false; // return geoSigma.SavePdfDocument(fileName, leftMargin, rightMargin, // topMargin, bottomMargin, paperSizeType, pdfAHType, pdfPapertDirectionType); //} public override bool NewFile(string fileName, GeoSigmaXY.eViewType vType = GeoSigmaXY.eViewType.wellsection) { try { if (drawer1 == null) { MessageBox.Show("drawer1 == null"); } geoSigma = drawer1.NewFile(fileName, this.mNewWellInfo, vType); if (vType != GeoSigmaXY.eViewType.wellsection) return true; if (workAreaDb.Instance.workData.isConn() == false) return true; // readWorkAreaDataForWell(this.mNewWellInfo.wellName); } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } if (geoSigma == null) { return false; } return true; } /// /// 将全部内容当前分辨率保存到指定输出文件. /// /// The output file. /// /// /// /// //public void Draw2Image(string outputFile, double left = 0, double top = 0, double right = 0, double bottom = 0) //{ // drawer1?.Geo?.Draw2Image(outputFile, left, top, right, bottom); //} //public bool SetPointZColor() //{ // return drawer1.SetPointZColor(); //} //public string GetLayers(bool withStatus = false) //{ // return geoSigma != null ? geoSigma.GetLayers(withStatus) : string.Empty; //} #region 打印 public override void PreviewPrint() { InitPrint(); // vRuler1.Hide(); // hRuler1.Hide(); pnlScrollV.Hide(); pnlScrollH.Hide(); drawer1.Hide(); printerStatus.Init(drawer1.Geo); printerDrawer.Init(drawer1.Geo); // drawer1.MouseMove -= hRuler1.ProcessMouseMove; // drawer1.MouseMove -= vRuler1.ProcessMouseMove; drawer1.Anchor = AnchorStyles.None; drawer1.Geo.GetViewFactors(ref viewFactor); LayoutPreviewPrintCtrl(); } public void OnClosePreviewWindow(object sender, EventArgs e) { // vRuler1.Show(); // hRuler1.Show(); pnlScrollV.Show(); pnlScrollH.Show(); //previewPrintBar.Hide(); printPreview.Visible = false; // drawer1.MouseMove += hRuler1.ProcessMouseMove; // drawer1.MouseMove += vRuler1.ProcessMouseMove; drawer1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; drawer1.RecoverView(viewFactor); drawer1.Show(); } protected void LayoutPreviewPrintCtrl() { //int previewHeight = Height - previewPrintBar.Height; //int previewWidth = PrintTool.GetWidthOfPreviewPrintCanvas(printerStatus.PaperName, printerStatus.Orientation, previewHeight); // int previewX = (Width - previewWidth) / 2; //printPreview.Location = new Point(previewX, previewPrintBar.Height); //printPreview.Width = previewWidth; //printPreview.Height = Height; //previewHeight; //printPreview.Visible = true; printerDrawer.Redraw(); } protected override void OnResize(EventArgs e) { base.OnResize(e); if (printPreview == null || printPreview.Visible == false) return; LayoutPreviewPrintCtrl(); } #endregion //public int SelectByNames(string nameData) //{ // return Drawer.SelectByNames(nameData); //} /// /// 根据名称查找并激活图元 /// /// 图元名称 /// 全字匹配 /// 匹配大小写 /// 图元类型 /// 是否只查找可编辑图元 /// 查找结果 //public int FindElementByName(string content, bool matchAll = false, bool matchCase = false, int elementType = 0, bool editableOnly = true) //{ // return Drawer.FindElementByName(content, matchAll, matchCase, elementType, editableOnly); //} //public string GetCurrentLayer() //{ // if (geoSigma == null) // { // return string.Empty; // } // return geoSigma.GetCurrentLayer(); //} //public void SetCurrentLayer(string layerName) //{ // geoSigma?.SetCurrentLayer(layerName); //} //public bool RemoveCurveStyle(string layerName, int index) //{ // if (geoSigma.RemoveCurveStyle(layerName, index)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SetLayerHowtoViewPoint(string layerName, string data, bool replace) //{ // if (geoSigma.SetLayerHowtoViewPoint(layerName, data, replace)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SetLayerStyle(CurveView curveStyle, string layerName, int propertyIndex) //{ // string strCurveStyle = ((CurveView)curveStyle).SerialXml(); // strCurveStyle = strCurveStyle.Replace("true", "1"); // strCurveStyle = strCurveStyle.Replace("false", "0"); // return this.SetLayerHowtoViewCurve(layerName, strCurveStyle, propertyIndex - 1); //} //public bool SetLayerHowtoViewCurve(string layerName, string data, int index) //{ // if (geoSigma.SetLayerHowtoViewCurve(layerName, data, index)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SetLayerMoveUpCurveStyle(string layerName, int index) //{ // if (geoSigma.SetLayerMoveUpCurveStyle(layerName, index)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SetLayerMoveDownCurveStyle(string layerName, int index) //{ // if (geoSigma.SetLayerMoveDownCurveStyle(layerName, index)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool CreateLayerCurveStyle(string layerName, CurveStyleType type, string data) //{ // if (geoSigma.CreateLayerCurveStyle(layerName, type, data)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool AddLayerCurveStyle(string layerName, CurveStyleType type, string data) //{ // if (geoSigma.AddLayerCurveStyle(layerName, type, data)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool CreateLayerPointStyle(string layerName, string data) //{ // if (geoSigma.CreateLayerPointStyle(layerName, data)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public void InvokeSelectedChanged(string elementData, long position) //{ // this.SelectedElementPosition=position; // if (SelectedElementChanged!=null) // { // SelectedElementChanged(this, new ElementArgs(elementData, position)); // } //} ///// ///// 添加点数据 ///// ///// 图层名称 ///// 点数据 //public void AddDrawPoint(string layerName, DrawerPoint drawPoint) //{ // Drawer?.AddPoint(layerName, drawPoint); //} //public bool RemovePointStyle(string layerName) //{ // if (geoSigma.RemovePointStyle(layerName)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} /// /// Sets the state of the layer. /// /// Name of the layer. /// The status. //public void SetLayerState(string layerName, LayerStatus status) //{ // geoSigma.SetLayerState(layerName, status); // geoSigma.EnableRedraw(true); //} ///// ///// 按图层名称获取层数据 ///// ///// ///// ///// ///// ///// //public IntPtr GetLayerData(string name, string holes, string boundarys, string wells) //{ // IntPtr ret = IntPtr.Zero; // // 使用 Split 方法按分号分割字符串,并存储到数组中 // string[] holeArr = holes.Split(';'); // string[] boundaryArr = boundarys.Split(';'); // string[] wellArr = wells.Split(';'); // bool bHole = false; // bool bBoundary = false; // bool bWell = false; // // 打印每个分割后的字符串 // foreach (string hole in holeArr) // { // if (hole == name) // { // bHole = true; // break; // } // } // // 打印每个分割后的字符串 // foreach (string boundary in boundaryArr) // { // if (boundary == name) // { // bBoundary = true; // break; // } // } // foreach (string well in wellArr) // { // if (well == name) // { // bWell = true; // break; // } // } // ret = geoSigma.GetLayerData(name, bHole, bBoundary, bWell); // return ret; //} ///// ///// Processes the mesh fault area. ///// ///// The p root. ///// The p main mesh. //public void ProcessMeshFaultArea(IntPtr pRoot, IntPtr pMainMesh) //{ // geoSigma.ProcessMeshFaultArea(pRoot, pMainMesh); //} ///// ///// 按边界处理网格 ///// ///// ///// //public void ProcessMeshBoundary(IntPtr pRoot, IntPtr pMainMesh) //{ // geoSigma.ProcessMeshBoundary(pRoot, pMainMesh); //} ///// ///// Sets the VTK data node checked. ///// ///// The p node data. ///// if set to true [is checked]. //public void SetVtkDataNodeChecked(IntPtr pNodeData, bool isChecked) //{ // geoSigma.SetVtkDataNodeChecked(pNodeData, isChecked); //} ///// ///// Sets the VTK data node hide. ///// ///// The p node data. ///// if set to true [is hide]. //public void SetVtkDataNodeHide(IntPtr pNodeData, bool isHide) //{ // geoSigma.SetVtkDataNodeChecked(pNodeData, isHide); //} ///// ///// ///// ///// ///// //public void AddVtkDataNodeChild(IntPtr pParent, IntPtr pChild) //{ // geoSigma.AddVtkDataNodeChild(pParent, pChild); //} ///// ///// Adds the data as symble. ///// ///// The data. ///// The symbol name. ///// If true, overwrite. ///// An int. //public int AddDataAsSymble(string data, string symbolName, bool overwrite = false) //{ // return Drawer.Geo.AddDataAsSymble(data, symbolName, overwrite); //} ///// ///// Autos the join curves. ///// ///// An int. //public int AutoJoinCurves() //{ // FrmJoinCurves frmJoin = new FrmJoinCurves(); // if (frmJoin.ShowDialog(this) != DialogResult.OK) // { // return 0; // } // double dMaxError = frmJoin.MaxError; // bool bOnlySameName = frmJoin.OnlySameName; // return Drawer.Geo.Curve_AutoJoin(dMaxError, bOnlySameName); //} //private void Viewer_MouseWheel(object sender, MouseEventArgs e) //{ // if (geoSigma==null) return; // // 屏幕坐标偏移量 // int nOffsetScreen = this.VerticalScroll.Value -this.scrollPositionYLast; // int nScreenAllVert = this.VerticalScroll.Maximum-this.VerticalScroll.Minimum; // // 实际坐标偏移量 // double dOffsetReal = ((double)nOffsetScreen/nScreenAllVert)* this.mapRange.Height; // geoSigma.Scroll((int)ScrollOrientation.VerticalScroll, dOffsetReal); // scrollPositionYLast=this.VerticalScroll.Value; // geoSigma.EnableRedraw(true); //} private void SetScrollBar(object sender, EventArgs e) { if (mViewType == GeoSigmaXY.eViewType.wellpole) { SetScrollBarForWellPole(sender, e); return; } if (geoSigma == null) { return; } //System.Drawing.Point pt1 = this.pnlScrollH.Location; //System.Drawing.Size size1 = this.pnlScrollH.Size; ScrollArgs args = e as ScrollArgs; int hMax = 0, vMax = 0, hPage = 0, vPage = 0, hPos = 0, vPos = 0; geoSigma.SetScrollBar(ref hMax, ref vMax, ref hPage, ref vPage, ref hPos, ref vPos); if (hMax < 100) { hMax = 100; } if (vMax < 100) { vMax = 100; } if (hPos == 0) { //scrollH.Visible = false; } else { scrollH.Visible = true; } if (vPos == 0) { //scrollV.Visible = false; } else { scrollV.Visible = true; } if (hMax < args.ScreenRect.Width) { hMax = args.ScreenRect.Width; hPage = hMax; hPos = 0; } if (vMax < args.ScreenRect.Height) { vMax = args.ScreenRect.Height; vPage = vMax; vPos = 0; } // nMin、nPage、nPos与控件Min,LargeChange、value类似 // 但nMax相当于Max+LargeChange-1 int nMaxValueH = hMax; // hMax-hPage+1; int nMaxValueV = vMax; this.scrollH.Minimum = 0; this.scrollH.Maximum = nMaxValueH; this.scrollH.LargeChange = (int)((hPage * largeScrollFactor) + 0.5); this.scrollH.SmallChange = (int)((hPage * 0.2) + 0.5); if (hPos >= this.scrollH.Minimum && hPos <= this.scrollH.Maximum) { this.scrollH.Value = hPos; } this.scrollV.Minimum = 0; this.scrollV.Maximum = nMaxValueV; this.scrollV.LargeChange = vPage; this.scrollV.SmallChange = (int)((vPage * 0.2) + 0.5); if (vPos >= this.scrollV.Minimum && vPos <= this.scrollV.Maximum) { this.scrollV.Value = vPos; } this.drawer1.ScreenLocationChanged?.Invoke(); ////////////////////////////////////////////////////////////////////// } ///// ///// 添加并激活新图层 ///// ///// ///// 是否激活 //public void FindAddLayer(string strLayerName, bool doActive = true) //{ // geoSigma.FindAddLayer(strLayerName, doActive); //} //public void LayerRename(string oldName, string newName) //{ // geoSigma.LayerRename(oldName, newName); //} //public void DeleteLayer(List layers, bool withSubLayer = false) //{ // geoSigma.DeleteLayer(layers.ToArray(), withSubLayer); //} //public bool DeleteLayerEmpty() //{ // return geoSigma.DeleteLayerEmpty(); //} //public bool GetLayerStyleData(string layerName, ref string curveStyle, ref string pointStyle) //{ // return geoSigma.GetLayerStyleData(layerName, ref curveStyle, ref pointStyle); //} /// /// 滚动条事件 /// /// /// private void Viewer_Scroll(object sender, ScrollEventArgs e) { if (e.Type == ScrollEventType.EndScroll) { //Scroll2(800); return; } if (geoSigma == null) return; if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll) { if (Viewer_ScrollHori(sender, e) == true) { drawer1.IsViewStatusChanged = true; } } else if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) { if (Viewer_ScrollVert(sender, e)) { drawer1.IsViewStatusChanged = true; } } scrollPositionYLast = this.VerticalScroll.Value; // 通知相关控件 drawer1.ScreenLocationChanged?.Invoke(); } /// /// 水平滚动条 /// /// sender /// 参数 private bool Viewer_ScrollHori(object sender, ScrollEventArgs e) { if (this.mViewType == GeoSigmaXY.eViewType.wellpole) return ScrollHoriForWellPole((int)(e.ScrollOrientation), (int)e.Type, e.NewValue - e.OldValue); else return ScrollHori((int)(e.ScrollOrientation), (int)e.Type, e.NewValue - e.OldValue); } /// 纵向、横向 /// ScrollEventType /// 滚动条变化量 private bool ScrollHori(int nOrientation, int nType, int nValue) { //geoSigma.HScroll(nType, e.NewValue, scrollH.Maximum-scrollH.LargeChange+1); // 屏幕总宽度 int nScreenAllHor = this.scrollH.Maximum - this.scrollH.Minimum; // 屏幕宽度 Ws int nWs = drawer1.Width; // 屏幕实际距离 Wr double dWtest = geoSigma.GetRealWidth(nValue); double dWs = geoSigma.GetRealWidth(nWs); // dOffset = Wr*nValue/Ws; double dOffset = 0; if (Math.Abs(nValue) < 0.01) { // TODO:需要进一步修改屏幕滚动范围 if (nType == (int)ScrollEventType.SmallIncrement) { nValue = this.scrollH.SmallChange; scrollH.Maximum = scrollH.Maximum + nValue; double dF = (double)nValue / nWs; dOffset = dWs * dF; //drawer1.enlargeRight(dOffset); needHScrollToEnd = true; } else if (nType == (int)ScrollEventType.SmallDecrement) { nValue = -this.scrollH.SmallChange; scrollH.Minimum = scrollH.Minimum + nValue; double dF = (double)nValue / nWs; dOffset = dWs * dF; //drawer1.enlargeLeft(Math.Abs(dOffset)); needHScrollToBegin = true; } else { return false; } } else { // 计算实际坐标变化量 // 变化比例 //double dF = (double)nValue/(nScreenAllHor-this.scrollH.LargeChange+1); //dOffset=dF*drawer1.MapRange.Width; double dF = (double)nValue / nWs; dOffset = dWs * dF; } //Console.WriteLine(string.Format("offset {0}", dOffset)); geoSigma.Scroll(nOrientation, dOffset); drawer1.EnableRedraw = true; drawer1.Invalidate(); return true; } public void Scroll2(int scrollValue) { scrollH.Value = scrollValue; } /// /// 垂直滚动条 /// /// /// private bool Viewer_ScrollVert(object sender, ScrollEventArgs e) { if (this.mViewType == GeoSigmaXY.eViewType.wellpole) return ScrollVertForWellPole((int)e.ScrollOrientation, (int)e.Type, e.NewValue - e.OldValue); else return ScrollVert((int)e.ScrollOrientation, (int)e.Type, e.NewValue - e.OldValue); } /// /// 竖向滚动. /// /// The n orientation. /// The n type. /// The n value. /// A bool. private bool ScrollVert(int nOrientation, int nType, int nValue) { int nScreenAllVert = this.scrollV.Maximum - this.scrollV.Minimum; // 屏幕高度 Ws int nHs = drawer1.Height; // 屏幕实际距离 Wr double dHs = geoSigma.GetRealHeight(nHs); double dOffset = 0; if (Math.Abs(nValue) < 0.01) { if (nType == (int)ScrollEventType.SmallIncrement) { nValue = this.scrollV.SmallChange; scrollV.Maximum = scrollV.Maximum + nValue; double dF = (double)nValue / nHs; dOffset = dHs * dF; //dOffset=((double)nValue/nScreenAllVert)*drawer1.MapRange.Height; //drawer1.enlargeBottom(dOffset); needVScrollToBottom = true; } else if (nType == (int)ScrollEventType.SmallDecrement) { nValue = -this.scrollV.SmallChange; scrollV.Minimum = scrollV.Minimum + nValue; double dF = (double)nValue / nHs; dOffset = dHs * dF; //dOffset=((double)nValue/nScreenAllVert)*drawer1.MapRange.Height; //drawer1.enlargeTop(dOffset); needVScrollToTop = true; } else { return false; } } else { //double dF = (double)nValue/(nScreenAllVert-this.scrollV.LargeChange+1); //dOffset=dF* drawer1.MapRange.Height; double dF = (double)nValue / nHs; dOffset = dHs * dF; } geoSigma.Scroll(nOrientation, -dOffset); drawer1.EnableRedraw = true; drawer1.Invalidate(); return true; } /// /// 更新属性界面 /// public void RefreshProperty() { drawer1?.RefreshProperty(); } /// /// //通过滑轮滚动图形 /// /// true向上滚动图形 false向下滚动图形 private void ScrollByWheel(bool bUp) { if (mViewType == GeoSigmaXY.eViewType.wellpole) { ScrollByWheelForWellPole(bUp); return; } if (geoSigma == null) { return; } int nValue = this.scrollV.SmallChange; if (bUp == false) { int v = scrollV.Value + nValue; if (v > scrollV.Maximum) { scrollV.Maximum = v; } scrollV.Value = v; } else { int v = scrollV.Value - nValue; if (v < scrollV.Minimum) { scrollV.Minimum = v; } scrollV.Value = v; } int nHs = drawer1.Height; // 屏幕高度 double dHs = geoSigma.GetRealHeight(nHs); // 屏幕实际距离 double dF = (double)nValue / nHs; double dOffset = dHs * dF; if (bUp) { //1--ScrollOrientation.VerticalScroll geoSigma.Scroll(1, dOffset); } else { geoSigma.Scroll(1, -dOffset); } drawer1.EnableRedraw = true; drawer1.Invalidate(); // 通知相关控件 drawer1.ScreenLocationChanged?.Invoke(); } //public void GridGenerateContour() //{ // drawer1?.GridGenerateContour(); //} //public void GridSmooth() //{ // drawer1?.GridSmooth(); //} //public void GridStatics() //{ // drawer1.GridStatics(); //} ///// ///// Creates the mesh by data async. ///// ///// A System.Threading.Tasks.Task. //public async System.Threading.Tasks.Task CreateMeshByDataAsync() //{ // await drawer1.CreateMeshByDataAsync(); //} ///// ///// Creates the mesh by Image async. ///// ///// A System.Threading.Tasks.Task. //public async System.Threading.Tasks.Task CreateMeshByImageAsync() //{ // await drawer1.CreateMeshByImageAsync(); //} //public void ZoomIn() //{ // drawer1.ZoomIn(); //} //public void ZoomOut() //{ // drawer1.ZoomOut(); //} //public void ViewAll() //{ // drawer1.ViewAll(); //} //public void Extend(RectangleF rect) //{ // drawer1.Extend(rect); //} //public void InitlizePaint(RectangleF rect) //{ // drawer1.InitlizePaint(rect); //} private void Viewer_Resize(object sender, EventArgs e) { //drawer1.ReDraw(); } //public void ReDrawWindow() //{ // drawer1.ReDrawWindow(); //} //private void ShowTipMessage(string tipMessage) //{ // TipMessageHandler?.Invoke(tipMessage); //} private void drawer1_DrawerGotFocus(object sender, EventArgs e) { if (DrawerGotFocus != null) { DrawerGotFocus(sender, e); } } ///// ///// 创建泰森图. ///// ///// 块数 //public int CreateVoronoi() //{ // return geoSigma.CreateVoronoi(); //} //public int CreateVoronoi2() //{ // return 0; //} private bool ptInRange(IEnumerable coors, Coordinate coor, GeometryFactory gf) { Coordinate coorStart = coors.First();//[0]; Coordinate coorEnd = coors.Last();//[coors.Count - 1]; double dDist = DistanceOp.Distance(gf.CreatePoint(coorStart), gf.CreatePoint(coorEnd)); LineString line = new LineString(coors.ToArray()); double dLength = line.Length; // 不是闭合多边形 if (dDist > dLength * 0.1) { return false; } Polygon poly = null; if (coorStart.X != coorEnd.X || coorStart.X != coorEnd.Y) { Coordinate[] caCoor = new Coordinate[coors.Count() + 1]; coors.ToArray().CopyTo(caCoor, 0); caCoor[caCoor.Length - 1] = caCoor[0]; poly = gf.CreatePolygon(caCoor); } else { poly = gf.CreatePolygon(coors.ToArray()); } return poly.Covers(gf.CreatePoint(coor)); } ///// ///// 创建三角网 ///// ///// 块数 //public int CreateDelaunay() //{ // return 0; //} ///// ///// 创建三角网 ///// ///// 块数 //public int CreateDelaunayConstraint() //{ // return 0; //} private List safeUnion(List polygons) { if (polygons == null || polygons.Count == 0) { return new List(); } if (polygons.Count == 1) { return new List() { (Polygon)polygons[0] }; } var unionResult = new List(); var current = polygons[0]; for (int i = 1; i < polygons.Count; i++) { try { current = current.Union(polygons[i]); } catch (TopologyException ex) { // 分步失败时尝试修复后合并 var cleaned2 = polygons[i].Buffer(0); var pm = new PrecisionModel(1000); // 1e3 = 3位小数 var geom2Prec = GeometryPrecisionReducer.Reduce(cleaned2, pm); current = OverlayNG.Overlay(current, geom2Prec, SpatialFunction.Union); //double eps = 1e-6; //var bufA = current.Buffer(eps); //var bufB = polygons[i].Buffer(eps); //var tmp = bufA.Union(bufB); //current = tmp.Buffer(-eps); Trace.WriteLine($"断层合并出错:{ex.Message}"); } } if (current is MultiPolygon muit) { return muit.Geometries.Cast().ToList(); } else { unionResult.Add(current as Polygon); } return unionResult; } /// /// 将两个仅在单一顶点相连的多边形合并为一个连通 Polygon /// public static Polygon MergeAtSharedVertex(Polygon poly1, Polygon poly2) { // 1. 提取外环坐标并检测/修正方向 var coords1 = poly1.ExteriorRing.Coordinates; var coords2 = poly2.ExteriorRing.Coordinates; if (!NetTopologySuite.Algorithm.Orientation.IsCCWArea(coords1)) { Array.Reverse(coords1); } if (!NetTopologySuite.Algorithm.Orientation.IsCCWArea(coords2)) { Array.Reverse(coords2); } // 2. 定位唯一共享顶点 var shared = coords1.FirstOrDefault(c1 => coords2.Any(c2 => c1.Equals2D(c2))); if (shared == null) { throw new InvalidOperationException("两多边形无共享顶点。"); } int idx1 = Array.FindIndex(coords1, c => c.Equals2D(shared)); int idx2 = Array.FindIndex(coords2, c => c.Equals2D(shared)); // 3. 滚动坐标序列,使共享点为起点 CoordinateArrays.Scroll(coords1, idx1); CoordinateArrays.Scroll(coords2, idx2); // 4. 拼接两段序列并去重 var mergedCoords = coords1 .Concat(coords2.Skip(1)) .ToArray(); mergedCoords = CoordinateArrays.RemoveRepeatedPoints(mergedCoords); // 5. 闭合环:首尾坐标必须相同 if (!mergedCoords[0].Equals2D(mergedCoords[mergedCoords.Length - 1])) { mergedCoords = mergedCoords .Concat(new[] { mergedCoords[0] }) .ToArray(); } // 6. 构造 LinearRing 并修复几何 var factory = NtsGeometryServices.Instance.CreateGeometryFactory(); var ring = factory.CreateLinearRing(mergedCoords); var rawPoly = factory.CreatePolygon(ring); return rawPoly; } /// /// 判断两个 Polygon 是否共享至少一个顶点 /// private static bool PolygonsShareVertex(Polygon a, Polygon b) { return a.ExteriorRing.Coordinates .Any(c1 => b.ExteriorRing.Coordinates .Any(c2 => c1.Equals2D(c2))); // :contentReference[oaicite:8]{index=8} } /// /// 对多个仅在顶点相连的 Polygon 进行合并,返回合并后的连通面列表 /// public static List MergeMultipleAtSharedVertex(IEnumerable polygons) { var list = polygons.ToList(); var visited = new bool[list.Count]; var result = new List(); for (int i = 0; i < list.Count; i++) { if (visited[i]) continue; // 广度优先搜索构建连通分量 var queue = new Queue(); queue.Enqueue(i); visited[i] = true; Polygon merged = list[i] as Polygon; while (queue.Any()) { int idx = queue.Dequeue(); for (int j = 0; j < list.Count; j++) { if (visited[j]) continue; // 若与当前 merged 多边形或其成分共享顶点,则合并 if (PolygonsShareVertex(merged, list[j] as Polygon)) { merged = MergeAtSharedVertex(merged, list[j] as Polygon); visited[j] = true; queue.Enqueue(j); } } } result.Add(merged); } return result; } /// /// 辅助方法:在交叉点处分割线段 /// /// 线 /// 分割点 /// 分割后线 private static LineString splitLineAtPoint(LineString line, Coordinate splitPoint) { List coords = line.Coordinates.ToList(); int index = coords.FindIndex(c => c.Equals2D(splitPoint, 1e-6)); // 如果交叉点已是顶点,无需拆分 if (index != -1) { return line; } PrecisionModel pm = new PrecisionModel(1e6); // 保留6位小数 Coordinate scaledSplitPoint = new Coordinate(pm.MakePrecise(splitPoint.X), pm.MakePrecise(splitPoint.Y)); // 插入新顶点并拆分 List newCoords = new List(); for (int i = 0; i < coords.Count - 1; i++) { newCoords.Add(coords[i]); Coordinate coorA = new Coordinate(pm.MakePrecise(coords[i].X), pm.MakePrecise(coords[i].Y)); Coordinate coorB = new Coordinate(pm.MakePrecise(coords[i + 1].X), pm.MakePrecise(coords[i + 1].Y)); bool inRange2 = splitPoint.X > Math.Min(coorA.X, coorB.X) && splitPoint.X < Math.Max(coorA.X, coorB.X) && splitPoint.Y > Math.Min(coorA.Y, coorB.Y) && splitPoint.Y < Math.Max(coorA.Y, coorB.Y); if (inRange2 == false) { continue; } double dx1 = coorB.X - coorA.X, dy1 = coorB.Y - coorA.Y; double dx2 = splitPoint.X - coorA.X, dy2 = splitPoint.Y - coorA.Y; double det = (dx1 * dy2) - (dy1 * dx2); // 自定义阈值 double EPS = 1e-3; OrientationIndex orient; if (Math.Abs(det) <= EPS) { orient = OrientationIndex.Straight; } else { orient = det > 0 ? OrientationIndex.CounterClockwise : OrientationIndex.Clockwise; } //OrientationIndex orient = NetTopologySuite.Algorithm.Orientation.Index(coorA, coorB, splitPoint); if (orient == OrientationIndex.Straight) { newCoords.Add(splitPoint); } } newCoords.Add(coords[coords.Count - 1]); // 生成拆分后的线段 return new LineString(newCoords.ToArray()); } /// /// creates the index line. /// /// The geo source. /// The pts dest. /// A list of int. private List createIndexLine(Geometry geoSource, List ptsDest) { List lstLine = new List(); foreach (Coordinate coor in geoSource.Coordinates) { int nIndexFind = ptsDest.FindIndex((it) => { return it.x == coor.X && it.y == coor.Y; }); if (nIndexFind < 0) { ptsDest.Add(new Vec2(coor.X, coor.Y)); lstLine.Add(ptsDest.Count - 1); } else { lstLine.Add(nIndexFind); } } return lstLine; } /// /// 判断线是否闭合. /// /// The line. /// A bool. private bool isLineRing(LineString line) { double dDistance = line[0].Distance(line[line.Count - 1]); double dLength = line.Length; if (dDistance < dLength * 0.075) { return true; } return false; } private void HandleEmptyNameCurve(string xmlOfEmptyNameCurves) { ENCurveLoadHandler?.Invoke(xmlOfEmptyNameCurves); } ///// ///// 选择图元事件 ///// ///// 发送者 ///// 事件参数 //private void drawer1_SelectedElementChanged(object sender, ElementArgs e) //{ // if (e == null) // { // this.SelectedElementPosition = -1; // SelectedElementChanged?.Invoke(sender, null); // return; // } // this.SelectedElementPosition = e.Position; // SelectedElementChanged?.Invoke(sender, e); //} //public bool SetElementProperty(string elementData) //{ // if (geoSigma.SelectSetElement(elementData, SelectedElementPosition)) // , data, index // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} ///// ///// 将选中图元保存为模版. ///// ///// The output file. ///// 是否成功 //public bool SelectWriteTemplate(string outputFile) //{ // if (geoSigma == null) // { // return false; // } // return geoSigma.SelectWriteTemplate(outputFile); //} //public bool SelectRemoveCurveStyle(int index) //{ // if (geoSigma.SelectRemoveCurveStyle(SelectedElementPosition, index)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SelectRemovePointStyle() //{ // if (geoSigma.SelectRemovePointStyle(SelectedElementPosition)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SelectMoveUpCurveStyle(int index) //{ // if (geoSigma.SelectMoveUpCurveStyle(SelectedElementPosition, index)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SelectMoveDownCurveStyle(int index) //{ // if (geoSigma.SelectMoveDownCurveStyle(SelectedElementPosition, index)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SelectCreateCurveStyle(CurveStyleType type, string data) //{ // if (geoSigma.SelectCreateCurveStyle(SelectedElementPosition, type, data)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} ///// ///// 重命名图元 ///// ///// 旧名称 ///// 新名称 ///// 图层 ///// 替换的数量 //public int RenameElement(string oldName, string newName, string layerName) //{ // return geoSigma.RenameElement(oldName, newName, layerName); //} /// /// 设置线的属性 /// /// 名称 /// 图层 /// 属性 /// 应用数量 //public int ResetCurveStyle(string curveName, string layerName, CurveView curveStyle) //{ // string strStyleData = curveStyle.SerialXml(); // int nCount = geoSigma.ResetCurveStyle(curveName, layerName, (int)curveStyle.StyleType, strStyleData); // if (nCount > 0) // { // Drawer.UpdateElementSelected(); // } // return 0; //} ///// ///// 获得选中点的样式 ///// ///// 数据 ///// 是否成功 //public bool SelectCreatePointStyle(string data) //{ // if (geoSigma.SelectCreatePointStyle(SelectedElementPosition, data)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public bool SelectGetLayerName(out string layer) //{ // if (SelectedElementPosition <= 0) // { // layer = string.Empty; // return false; // } // return geoSigma.SelectGetLayerName(SelectedElementPosition, out layer); //} //public bool SelectSetLayerByName(string layer) //{ // if (geoSigma.SelectSetLayerByName(SelectedElementPosition, layer)) // { // geoSigma.EnableRedraw(true); // return true; // } // return false; //} //public void EnableCrossLine(bool enable) //{ // drawer1.EnableCrossLine = enable; //} // 窗口尺寸变化 private void DrawViewer_SizeChanged(object sender, EventArgs e) { ReDrawWindow(); } private void ScrollScreenAndBar(ScrollKind kind) { int offset = 30; if (kind == ScrollKind.Left) { if (scrollH.Minimum == scrollH.Value) //说明上一次按向右的箭头 return; int v = scrollH.Value - offset; //直接减的话 scrollH.Value可能为负数 如果为负数 程序就崩溃了 所以做了一个判断 if (v < scrollH.Minimum) //第一次到达最左侧 滚动一次。不然 总是看不到最顶部的图形 { v = scrollH.Minimum; return; } scrollH.Value = v; ScrollHori((int)ScrollOrientation.HorizontalScroll, (int)ScrollEventType.LargeDecrement, -offset); } else if (kind == ScrollKind.Right) { int v = scrollH.Value + offset; if (v > scrollH.Maximum) { scrollH.Value = scrollH.Maximum; return; } scrollH.Value = v; ScrollHori((int)ScrollOrientation.HorizontalScroll, (int)ScrollEventType.LargeDecrement, offset); } else if (kind == ScrollKind.Up) { if (scrollV.Minimum == scrollV.Value) return; int v = scrollV.Value - offset; if (v < scrollV.Minimum) { v = scrollV.Minimum; } scrollV.Value = v; ScrollVert((int)ScrollOrientation.VerticalScroll, (int)ScrollEventType.LargeDecrement, -offset); } else if (kind == ScrollKind.Down) { int v = scrollV.Value + offset; if (v > scrollV.Maximum) { scrollV.Value = scrollV.Maximum; return; } scrollV.Value = v; ScrollVert((int)ScrollOrientation.VerticalScroll, (int)ScrollEventType.LargeDecrement, offset); } else if (kind == ScrollKind.PageDown) { if (scrollV.Value == scrollV.Maximum) return; double offsetW; int offsetS; CalculateVOffset(out offsetW, out offsetS); int v = scrollV.Value + offsetS; if (v > scrollV.Maximum) { v = scrollV.Maximum; } scrollV.Value = v; ScrollVert((int)ScrollOrientation.VerticalScroll, (int)ScrollEventType.LargeDecrement, offsetS); } else if (kind == ScrollKind.PageUp) { if (scrollV.Value == scrollV.Minimum) return; double offsetW; int offsetS; CalculateVOffset(out offsetW, out offsetS); int v = scrollV.Value - offsetS; if (v < scrollV.Minimum) { v = scrollV.Minimum; } scrollV.Value = v; ScrollVert((int)ScrollOrientation.VerticalScroll, (int)ScrollEventType.LargeDecrement, -offsetS); } } private void CalculateVOffset(out double offsetW, out int offsetS) { offsetW = 0; offsetS = 0; // 屏幕高度 Ws double totalHWolrd = Math.Abs(geoSigma.GetRealHeight(scrollV.Maximum)); //图纸的总高度 if (totalHWolrd < 1) return; double hWorld = Math.Abs(geoSigma.GetRealHeight(drawer1.Height)); //屏幕高度对应的图纸中的高度 double offsetScroll = scrollV.Maximum * hWorld / totalHWolrd; offsetS = (int)offsetScroll; // (int)(drawer1.Height * offsetScroll / (double)scrollV.Maximum); offsetW = hWorld; } private void OnChangeLayer(string eventKind) { ChangeLayerEvent?.Invoke(eventKind); } //private void drawer1_MouseMove(object sender, MouseEventArgs e) //{ // if (!string.IsNullOrWhiteSpace(drawer1.MouseMoveInfo)) // { // MouseMoveEvent?.Invoke(drawer1.MouseMoveInfo); // } // else // { // string mouseXY = string.Empty; // if (geoSigma != null) // { // geoSigma.GetMouseMoveXY(e.X, e.Y, ref mouseXY); // MouseMoveEvent?.Invoke(mouseXY); // } // } //} ///// ///// 为常用菜单添加命令. ///// ///// The text. ///// The handler. ///// if set to true [need element]. //public void InsertCommonCommand(string text, EventHandler handler, bool needElement = true // , DrawElementType elementType = DrawElementType.ELEMENT_UNKNOWN) //{ // drawer1?.InsertCommonCommand(text, handler, needElement // , elementType); //} /// /// 获得图层的数据 /// /// 图层名称 /// 数据列表 //public List GetDataByLayer(string layerName) //{ // return drawer1?.GetDataByLayer(layerName); //} //public List GetLayerCurve(string layerName) //{ // return drawer1?.GetLayerCurve(layerName); //} ///// ///// 获得选中的所有图元 ///// ///// 选中图元的列表 //public List GetSelectedElements() //{ // return drawer1?.GetSelectedElements(); //} ///// ///// ///// ///// ///// //private static Image Bitmap2Image(System.Drawing.Bitmap Bi) //{ // MemoryStream ms = new MemoryStream(); // Bi.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // BitmapImage bImage = new BitmapImage(); // bImage.BeginInit(); // bImage.StreamSource=new MemoryStream(ms.ToArray()); // bImage.EndInit(); // ms.Dispose(); // Bi.Dispose(); // Image i = new Image(); // i.Source=bImage; // return i; //} private void SetScrollBarForWellPole(object sender, EventArgs e) { if (geoSigma == null) { return; } ScrollArgs args = e as ScrollArgs; int hMax = 0, vMax = 0, hPage = 0, vPage = 0, hPos = 0, vPos = 0; geoSigma.SetScrollBar(ref hMax, ref vMax, ref hPage, ref vPage, ref hPos, ref vPos); if (hMax < 100) { hMax = 100; } if (vMax < 100) { vMax = 100; } if (hPos == 0) { //scrollH.Visible = false; } else { scrollH.Visible = true; } if (vPos == 0) { //scrollV.Visible = false; } else { scrollV.Visible = true; } Console.WriteLine($"set scroll bar vmax= {vMax}, vmin = {hMax}, vpos = {vPos}"); if (hMax < args.ScreenRect.Width) { hMax = hMax + 20;// args.ScreenRect.Width; hPage = hMax; hPos = 0; } if (vMax < args.ScreenRect.Height) { vMax = args.ScreenRect.Height; vPage = vMax; vPos = 0; } // nMin、nPage、nPos与控件Min,LargeChange、value类似 // 但nMax相当于Max+LargeChange-1 int nMaxValueH = hMax; // hMax-hPage+1; int nMaxValueV = vMax; this.scrollH.Minimum = 0; this.scrollH.Maximum = nMaxValueH; this.scrollH.LargeChange = (int)((hPage * largeScrollFactor) + 0.5); this.scrollH.SmallChange = (int)((hPage * 0.2) + 0.5); if (hPos >= this.scrollH.Minimum && hPos <= this.scrollH.Maximum) { this.scrollH.Value = hPos; } GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; if (GeoSigmaWellPoleXY.IsLockWellHead()) { int maxV, pageV, posV; maxV = pageV = posV = 0; GeoSigmaWellPoleXY.SetScrollBarVRangeForLockWellHead(ref maxV, ref pageV, ref posV); this.scrollV.Minimum = 0; this.scrollV.Maximum = maxV; this.scrollV.LargeChange = pageV; this.scrollV.SmallChange = (int)((pageV * 0.2) + 0.5); if (posV >= this.scrollV.Minimum && posV <= this.scrollV.Maximum) { this.scrollV.Value = posV; } } else { this.scrollV.Minimum = 0; this.scrollV.Maximum = nMaxValueV; this.scrollV.LargeChange = vPage; this.scrollV.SmallChange = (int)((vPage * 0.2) + 0.5); if (vPos >= this.scrollV.Minimum && vPos <= this.scrollV.Maximum) { this.scrollV.Value = vPos; } } this.drawer1.ScreenLocationChanged?.Invoke(); ////////////////////////////////////////////////////////////////////// } public override void SetLockWellHead() { drawer1.SetLockWellHead(); drawer1.ResetScrollbar(); } //public void AddTrack() //{//test code // GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; // int[] typeIdArr = new int[0]; // string[] typeStrArr = new string[0]; // GeoSigmaWellPoleXY.GetWellTrackTypeInfo(ref typeIdArr, ref typeStrArr); // int[] addTypes = new int[3]; // addTypes[0] = (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Text); // addTypes[1] = (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Curve); // addTypes[2] = (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Symbol); // bool b = GeoSigmaWellPoleXY.AddTrackAfterSelectedWellObject(addTypes, 3); //} //public void DeleteSelectedWellObject() //{ // GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; // bool b = GeoSigmaWellPoleXY.DeleteSelectedWellObject(); //} public void CombineLeftTrack() { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; bool b = GeoSigmaWellPoleXY.SelectedTrackCombineLeftTrack(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void CombineRightTrack() { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; bool b = GeoSigmaWellPoleXY.SelectedTrackCombineRightTrack(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public override void AddPictureToWellTrack() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "选择图片文件"; openFileDialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; openFileDialog.Multiselect = false; // 是否允许多选 if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; int type, ttype; type = ttype = -1; UInt64 thandle = 0; GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; if (GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref thandle)) { if (type == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACKINDATA) && ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_IMAGE)) { GeoSigmaWellPoleXY.SetPictureInWellTrack(thandle, filePath); drawer1.EnableRedraw = true; drawer1.Invalidate(); } } } } //public GeoSigmaWellPoleXY.NewWellInfo mNewWellInfo = new GeoSigmaWellPoleXY.NewWellInfo(); public void testGetWellObjectProperties() { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; UInt64 wellHandle = 0; GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle); string[] stratificationClass; GeoSigmaWellPoleXY.GetWellStratificationClasses(wellHandle, out stratificationClass); string[] resultSymbols; GeoSigmaWellPoleXY.GetSymbolNamesForResult(out resultSymbols); Bitmap bmp = new Bitmap(50, 50); Graphics gBmp = Graphics.FromImage(bmp); IntPtr pBmpDC = gBmp.GetHdc(); GeoSigmaWellPoleXY.GetDrawSymbolForResult(resultSymbols[0], pBmpDC, 50, 50); string[] lithSymbols; GeoSigmaWellPoleXY.GetSymbolNamesForLithology(out lithSymbols); Bitmap lithbmp = new Bitmap(50, 50); Graphics lithgBmp = Graphics.FromImage(lithbmp); IntPtr plithBmpDC = lithgBmp.GetHdc(); GeoSigmaWellPoleXY.GetDrawSymbolForLithology(lithSymbols[0], plithBmpDC, 50, 50); string[] lithConSymbols; GeoSigmaWellPoleXY.GetSymbolNamesForLithConstitution(out lithConSymbols); Bitmap lithconbmp = new Bitmap(50, 50); Graphics lithcongBmp = Graphics.FromImage(lithconbmp); IntPtr plithconBmpDC = lithcongBmp.GetHdc(); GeoSigmaWellPoleXY.GetDrawSymbolForLithConstitution(lithConSymbols[0], plithconBmpDC, 50, 50); string[] framesLine; GeoSigmaWellPoleXY.GetWellFrameLineNames(out framesLine); Bitmap wellLinebmp = new Bitmap(100, 30); Graphics wellLinegBmp = Graphics.FromImage(wellLinebmp); IntPtr wellLineBmpDC = wellLinegBmp.GetHdc(); GeoSigmaWellPoleXY.GetDrawWellFrameLine(framesLine[2], wellLineBmpDC, 100, 30); string[] normalSymbs; GeoSigmaWellPoleXY.GetNormalSymbolNames(out normalSymbs); Bitmap norsybbmp = new Bitmap(100, 30); Graphics gnorsybbmp = Graphics.FromImage(norsybbmp); IntPtr gnorsybbmpDC = gnorsybbmp.GetHdc(); GeoSigmaWellPoleXY.GetDrawNormalSymbol(normalSymbs[2], gnorsybbmpDC, 100, 30); string[] CurvePointSymbolNames; GeoSigmaWellPoleXY.GetCurvePointSymbolNames(out CurvePointSymbolNames); Bitmap wellptbmp = new Bitmap(100, 30); Graphics wellptgbmp = Graphics.FromImage(wellptbmp); IntPtr pwellptbmp = wellptgbmp.GetHdc(); GeoSigmaWellPoleXY.GetDrawCurvePointSymbol(CurvePointSymbolNames[2], pwellptbmp, 100, 30); string[] stratumLithSymbolNames; GeoSigmaWellPoleXY.GetStratumLithNames(out stratumLithSymbolNames); Bitmap slithbmp = new Bitmap(100, 30); Graphics swellptgbmp = Graphics.FromImage(slithbmp); IntPtr pswellptbmp = swellptgbmp.GetHdc(); GeoSigmaWellPoleXY.GetDrawStratumLith(stratumLithSymbolNames[2], pswellptbmp, 100, 30); string[] curveLine; GeoSigmaWellPoleXY.GetWellCurveLineNames(out curveLine); List listPerforations = workAreaDb.Instance.workData.getWellPerforations("DD7-3"); List listInnerLayers = workAreaDb.Instance.workData.getInnerLayers("D6-1"); List lstLongCycles = workAreaDb.Instance.workData.getWellCycles("D6-1", 1); List lstMediumCycles = workAreaDb.Instance.workData.getWellCycles("D6-1", 2); List lstShorCycles = workAreaDb.Instance.workData.getWellCycles("D6-1", 3); string strInnerLayer = ""; WellDataConvert.getInnerLayersJson(ref strInnerLayer, listInnerLayers); List lstLiths = workAreaDb.Instance.workData.getWellLithologys("DD7-3"); string strLithJson = ""; WellDataConvert.getWellLithologysJson(ref strLithJson, lstLiths); List lstOilTest = workAreaDb.Instance.workData.getWellOilTests("DD7-3"); string strOilTestJson = ""; WellDataConvert.getWellOilTestJson(ref strLithJson, lstOilTest); int type, ttype; type = ttype = -1; ulong objHandle = 0; bool b = GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref objHandle); if (b) { string[] curveNames; GeoSigmaWellPoleXY.GetWellAllCurveNames(objHandle, out curveNames); string[] discreteNames; GeoSigmaWellPoleXY.GetWellAllDiscreteNames(objHandle, out discreteNames); string strXml = ""; b = GeoSigmaWellPoleXY.GetWellObjectAttributesXml(objHandle, type, ttype, ref strXml); if (b) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.LoadXml(strXml); b = GeoSigmaWellPoleXY.SetWellObjectAttributesXml(objHandle, type, ttype, strXml); } catch (XmlException xmle) { Console.WriteLine(xmle.Message); } } //b = GeoSigmaWellPoleXY.GetWellObjectAttributesJson(objHandle, type, ttype, ref strJson); //if (b) //{ // JObject json = JObject.Parse(strJson); // //JObject propJson = (JObject)json["properties"]; // //JObject inDataJson = (JObject)propJson["道内对象设置"]; // //inDataJson["控制岩性宽度"] = false; // //string strJsonData = JsonConvert.SerializeObject(json); // byte[] databytes = Encoding.UTF8.GetBytes(strJson); // string jsonUtf8 = Encoding.ASCII.GetString(databytes);// // GeoSigmaWellPoleXY.SetWellObjectAttributesJson(objHandle, type, ttype, databytes, databytes.Length); //} } } //public void ViewExtendCenter() //{ // drawer1.ViewExtendCenter(); //} //public void ViewExtendWidth() //{ // drawer1.ViewExtendWidth(); //} private bool ScrollVertForWellPole(int nOrientation, int nType, int nValue) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)drawer1.Geo; if (GeoSigmaWellPoleXY.IsLockWellHead()) { GeoSigmaWellPoleXY.ScrollVForLockWellHead(nType, scrollV.Value, scrollV.LargeChange, scrollV.SmallChange, scrollV.Minimum, scrollV.Maximum); return true; } int nHs = drawer1.Height; // 屏幕实际距离 Wr double dHs = geoSigma.GetRealHeight(nHs); double dOffset = 0; int sliderBlockLen = scrollV.Value + scrollV.LargeChange; if (nType == (int)ScrollEventType.SmallIncrement) { nValue = this.scrollV.SmallChange; int deltaV = nValue; if ((sliderBlockLen + nValue) > scrollV.Maximum) { deltaV = scrollV.Maximum - sliderBlockLen; } if (deltaV < 0) deltaV = 0; scrollV.Value += deltaV; double dF = (double)deltaV / nHs; dOffset = dHs * dF; needVScrollToBottom = true; } else if (nType == (int)ScrollEventType.SmallDecrement) { nValue = -this.scrollV.SmallChange; int deltaV = nValue; if ((scrollV.Value + nValue) < scrollV.Minimum) { deltaV = scrollV.Minimum - scrollV.Value; } if (deltaV > 0) deltaV = 0; scrollV.Value += deltaV; double dF = (double)deltaV / nHs; dOffset = dHs * dF; } else { double dF = (double)nValue / nHs; dOffset = dHs * dF; } geoSigma.Scroll(nOrientation, -dOffset); drawer1.EnableRedraw = true; drawer1.Invalidate(); return true; } private bool ScrollHoriForWellPole(int nOrientation, int nType, int nValue) { //geoSigma.HScroll(nType, e.NewValue, scrollH.Maximum-scrollH.LargeChange+1); // 屏幕总宽度 //int nScreenAllHor = this.scrollH.Maximum - this.scrollH.Minimum; // 屏幕宽度 Ws int nWs = drawer1.Width; // 屏幕实际距离 Wr double dWtest = geoSigma.GetRealWidth(nValue); double dWs = geoSigma.GetRealWidth(nWs); // dOffset = Wr*nValue/Ws; double dOffset = 0; int sliderBlockLen = scrollH.Value + scrollH.LargeChange; if (nType == (int)ScrollEventType.SmallIncrement) { nValue = this.scrollH.SmallChange; // scrollH.Maximum = scrollH.Maximum + nValue; int deltaV = nValue; if ((sliderBlockLen + nValue) > scrollH.Maximum) { deltaV = scrollH.Maximum - sliderBlockLen; } if (deltaV < 0) deltaV = 0; scrollH.Value += deltaV; double dF = (double)deltaV / nWs; dOffset = dWs * dF; //drawer1.enlargeRight(dOffset); } else if (nType == (int)ScrollEventType.SmallDecrement) { nValue = -this.scrollH.SmallChange; int deltaV = nValue; if ((scrollH.Value + nValue) < scrollH.Minimum) { deltaV = scrollH.Minimum - scrollH.Value; } if (deltaV > 0) deltaV = 0; scrollH.Value += deltaV; double dF = (double)deltaV / nWs; dOffset = dWs * dF; //drawer1.enlargeLeft(Math.Abs(dOffset)); } else { double dF = (double)nValue / nWs; dOffset = dWs * dF; } geoSigma.Scroll(nOrientation, dOffset); drawer1.EnableRedraw = true; drawer1.Invalidate(); return true; } private void ScrollByWheelForWellPole(bool bUp) { if (geoSigma == null) { return; } GeoSigmaWellPoleXY geoWell = (GeoSigmaWellPoleXY)geoSigma; if (geoWell.IsLockWellHead()) { int zdelta = this.scrollV.SmallChange; if (!bUp) zdelta = -this.scrollV.SmallChange; geoWell.MouseWheelForLockWellHead(0, zdelta, 0, 0); int delta = this.scrollV.SmallChange; if (bUp == false) { int v = scrollV.Value + scrollV.LargeChange + this.scrollV.SmallChange; if (v > scrollV.Maximum) { delta = scrollV.Maximum - (scrollV.Value + scrollV.LargeChange); } if (delta < 0) delta = 0; scrollV.Value += delta; } else { delta = -this.scrollV.SmallChange; int v = scrollV.Value - this.scrollV.SmallChange; if (v < scrollV.Minimum) { delta = scrollV.Minimum - scrollV.Value; if (delta > 0) delta = 0; } scrollV.Value += delta; } return; } double dLeft = 0.0, dTop = 0.0, dRight = 0.0, dBottom = 0.0; Geo.GetMapRange(ref dLeft, ref dTop, ref dRight, ref dBottom); Rectangle rect = drawer1.ClientRectangle; double scLeft = 0.0, scRight = 0.0, scTop = 0.0, scBottom = 0.0; Geo.GetScreenReal(rect.Left, rect.Top, rect.Right, rect.Bottom, ref scLeft, ref scTop, ref scRight, ref scBottom); bool bMapLessScreen = false; if ((dTop - dBottom) < (scTop - scBottom)) bMapLessScreen = true; int nValue = this.scrollV.SmallChange; int deltaV = nValue; if (bMapLessScreen == false) { if (bUp == false) { int v = scrollV.Value + scrollV.LargeChange + nValue; if (v > scrollV.Maximum) { deltaV = scrollV.Maximum - (scrollV.Value + scrollV.LargeChange); } if (deltaV < 0) deltaV = 0; scrollV.Value += deltaV; } else { deltaV = -nValue; int v = scrollV.Value - nValue; if (v < scrollV.Minimum) { deltaV = scrollV.Minimum - scrollV.Value; if (deltaV > 0) deltaV = 0; } scrollV.Value += deltaV; } int nHs = drawer1.Height; // 屏幕高度 double dHs = geoSigma.GetRealHeight(nHs); // 屏幕实际距离 double dF = (double)deltaV / nHs; double dOffset = dHs * dF; geoSigma.Scroll(1, -dOffset); } else { if (bUp == true) {//滚轮向下,图向下移动, 图的顶部不高于屏幕的顶部 double OneLine = Geo.GetRealHeight(scrollV.SmallChange); if ((dBottom + OneLine) < scBottom) OneLine = scBottom - dBottom; if (OneLine > 0) OneLine = 0; geoSigma.Scroll(1, OneLine); } else {////滚轮向上, 图向上移动 ,图的底部不低于屏幕的底部 double OneLine = -Geo.GetRealHeight(scrollV.SmallChange); if ((dTop + OneLine) > scTop) OneLine = scTop - dTop; if (OneLine < 0) OneLine = 0; geoSigma.Scroll(1, OneLine); } } //int nHs = drawer1.Height; // 屏幕高度 //double dHs = geoSigma.GetRealHeight(nHs); // 屏幕实际距离 //double dF = (double)deltaV / nHs; //double dOffset = dHs * dF; //geoSigma.Scroll(1, -dOffset); drawer1.EnableRedraw = true; drawer1.Invalidate(); // 通知相关控件 drawer1.ScreenLocationChanged?.Invoke(); } private void ToolStripMenuItemAddWellTrack_Click(object sender, EventArgs e) { AddTrack(); } private void ToolStripMenuItemWellTrackDel_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; GeoSigmaWellPoleXY.DeleteSelectedWellObject(); } private void ToolStripMenuItemWellTrackAdd_Click(object sender, EventArgs e) { AddTrack(); } void getWellSectionDocContextMenu(ref ContextMenuStrip ctmenu, GeoSigmaWellPoleXY geoSigmaWellPoleXY) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigmaWellPoleXY; ctmenu = null; int stype = -1; int ttype = -1; UInt64 thandle = 0; // GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; if (geoSectionXY.GetSelectWellObject(ref stype, ref ttype, ref thandle)) { if (stype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_WELL)) { ctmenu = ctmWellPole; foreach (var item in ctmenu.Items) { if (item is ToolStripSeparator separator) continue; else if (item is ToolStripMenuItem menuItem) { if (menuItem.Name == "toolMenuItemRefreshWellPole") { if (workAreaDb.Instance.workData.isConn() == false) { menuItem.Enabled = false; } else { menuItem.Enabled = true; } break; } } } } else if (stype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK)) { if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Group)) { ctmenu = ctmWellGroupTrack; } else { if (ttype != (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Picture)) { ctmenu = ctmWellTrack; foreach (var item in ctmenu.Items) { if (item is ToolStripSeparator separator) continue; else if (item is ToolStripMenuItem menuItem) { if (menuItem.Name == "ToolStripMenuItemEditTrackData" || menuItem.Name == "toolStripMenuItemTrackRefreshData") { if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Depth) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Stratum)) { menuItem.Enabled = false; menuItem.Visible = false; } else { menuItem.Enabled = true; menuItem.Visible = true; } } if (menuItem.Name == "toolStripMenuItemSaveData") { if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Lith) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_InnerLayer) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Shot) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_SandLayer) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Sandstone) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Result) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Facies) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Cycle)) { if (workAreaDb.Instance.workData.isConn()) menuItem.Enabled = true; else menuItem.Enabled = false; menuItem.Visible = true; } else { menuItem.Enabled = false; menuItem.Visible = false; } } if (menuItem.Name == "toolStripMenuItemFaultInDB") { if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_SandLayer)) { if (workAreaDb.Instance.workData.isConn()) menuItem.Enabled = true; else menuItem.Enabled = false; menuItem.Visible = true; } else { menuItem.Enabled = false; menuItem.Visible = false; } } if (menuItem.Name == "toolStripMenuItemEditFault") { if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_SandLayer)) { menuItem.Visible = true; } else { /*menuItem.Enabled = false; */ menuItem.Visible = false; } } } } } } } else if (stype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACKINDATA)) { if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_IMAGE)) { ctmenu = contextMenuStripPictureInTrack; } else if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_RESULT) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_LAYERGROUP)) ctmenu = ctmWellObjInTrackLayer; else ctmenu = ctmWellObjInTrack; } else if (stype == (int)GeoSigmaWellPoleXY.eWellExtType.KEP_SECTIONBEND || stype == (int)GeoSigmaWellPoleXY.eWellExtType.KEP_SECTIONFAULT) { ctmenu = ctmWellObjInTrack; } else if (stype == (int)GeoSigmaWellPoleXY.eWellExtType.KEP_WELLSECTION) { ctmenu = ctmWellSection; } } } private void ToolStripMenuItemMergerLeftTrack_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; bool b = GeoSigmaWellPoleXY.SelectedTrackCombineLeftTrack(); } private void ToolStripMenuItemMergeRightTrack_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; bool b = GeoSigmaWellPoleXY.SelectedTrackCombineRightTrack(); } private void ToolStripMenuItemEditTrackData_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; // geoSigma; int type, ttype; type = ttype = -1; UInt64 thandle = 0; GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref thandle); if (type != (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK)) return; if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Group) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Depth)) return; if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_Sample) { var dataDlg = new FrmRockSampleDataEdit() { StartPosition = FormStartPosition.CenterScreen }; try { string strJson = ""; if (GeoSigmaWellPoleXY.GetWellTrackDataJson(thandle, ref strJson) == true) { dataDlg.SetRockSampleData(strJson); if (dataDlg.ShowDialog(this) == DialogResult.OK) { byte[] databytes = Encoding.UTF8.GetBytes(dataDlg.mStrDataJson); // string jsonUtf8 = Encoding.ASCII.GetString(databytes);// Encoding.UTF8.GetString(databytes); GeoSigmaWellPoleXY.SetWellTrackDataJson(thandle, databytes, databytes.Length); drawer1.EnableRedraw = true; drawer1.Invalidate(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { var dataDlg = new FrmWellDataEdit() { StartPosition = FormStartPosition.CenterScreen }; try { string dataType = string.Empty; string[] colsName = new string[0]; string[,] datas = new string[0, 0]; GeoSigmaWellPoleXY.GetWellTrackData(thandle, ref dataType, ref colsName, ref datas); string[] colsNameCH = new string[0]; GeoSigmaWellPoleXY.mWellTableInfos.GetTableColumnCHNames(dataType, colsName, ref colsNameCH); dataDlg.SetData(colsName, colsNameCH, datas); if (dataDlg.ShowDialog(this) == DialogResult.OK) { // byte[] databytes = Encoding.UTF8.GetBytes(dataDlg.strJsonData); if (dataDlg.m_IsModified == true) { if (GeoSigmaWellPoleXY.TrackIsWellTableDataSource(thandle) == true) {//井内管理数据就直接读去井内数据。 ulong wellHandle = 0; if (GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle) == true) { if (dataType == "ReservesLayer") { GeoSigmaWellPoleXY.SetWellReservesLayersJson(wellHandle, dataDlg.strJsonData, true); //GeoSigmaWellPoleXY.TrackReadWellTableData(thandle); } if (dataType == "SandSet") { GeoSigmaWellPoleXY.SetWellSandSetsJson(wellHandle, dataDlg.strJsonData, true); //GeoSigmaWellPoleXY.TrackReadWellTableData(thandle); } if (dataType == "FaultPoint") { //GeoSigmaWellPoleXY.SetWellFaultDatasJson(wellHandle, dataDlg.strJsonData); } } } else { GeoSigmaWellPoleXY.SetWellTrackDataJson(thandle, dataDlg.strJsonData); } this.drawer1.Invalidate(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void ToolStripMenuItemDelWellObjInTrack_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY GeoSigmaWellPoleXY = (GeoSigmaWellSectionXY)this.Geo; GeoSigmaWellPoleXY.DeleteSelectedWellObject(); } private void ToolStripMenuItemDelPictureInTrack_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY GeoSigmaWellPoleXY = (GeoSigmaWellSectionXY)this.Geo; GeoSigmaWellPoleXY.DeleteSelectedWellObject(); } private void ToolStripMenuItemImportPicutreInTrack_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "选择图片文件"; openFileDialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp;*.gif|所有文件|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; openFileDialog.Multiselect = false; // 是否允许多选 if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; int type, ttype; type = ttype = -1; UInt64 thandle = 0; GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)Geo; if (GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref thandle)) { if (type == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACKINDATA) && ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_IMAGE)) { GeoSigmaWellPoleXY.SetPictureInWellTrack(thandle, filePath); Invalidate(); } } } } private void toolStripMenuItemGroupTrackDel_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY GeoSigmaWellPoleXY = (GeoSigmaWellSectionXY)this.Geo; GeoSigmaWellPoleXY.DeleteSelectedWellObject(); } private void toolStripMenuItemGroupTrackAdd_Click(object sender, EventArgs e) { AddTrack(); } private void toolStripMenuItemGroupTrackMergeLeft_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY GeoSigmaWellPoleXY = (GeoSigmaWellSectionXY)this.Geo; bool b = GeoSigmaWellPoleXY.SelectedTrackCombineLeftTrack(); } private void toolStripMenuItemGroupTrackMergeRight_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY GeoSigmaWellPoleXY = (GeoSigmaWellSectionXY)this.Geo; bool b = GeoSigmaWellPoleXY.SelectedTrackCombineRightTrack(); } public void AddTrack() { var dlg = new FrmAddWellTrack() { StartPosition = FormStartPosition.CenterScreen }; GeoSigmaWellSectionXY GeoSigmaWellPoleXY = (GeoSigmaWellSectionXY)this.Geo; string[] typeNames = new string[0]; int[] typeIds = new int[0]; GeoSigmaWellSectionXY.GetWellTrackTypeInfo(ref typeIds, ref typeNames); dlg.setTypeInfo(typeNames, typeIds); if (dlg.ShowDialog(this) == DialogResult.OK) { if (dlg.mSelectTypeIds.Count > 0) { UInt64 wellHandle = 0; GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle); GeoSigmaWellPoleXY.GetWellBaseInfo(wellHandle, out GeoSigmaWellPoleXY.WellBaseInfo wellinfo); int[] newTypeIds = dlg.mSelectTypeIds.ToArray(); bool b = GeoSigmaWellPoleXY.AddTrackAfterSelectedWellObject(newTypeIds, newTypeIds.Length, out UInt64[] newTrackHandle, out int[] newTType); if (newTrackHandle.Length > 0) { for (int i = 0; i < newTrackHandle.Length; i++) { readTrackWorkAreaData(newTrackHandle[i], newTType[i], wellinfo.wellName, false); } this.Invalidate(); } //viewer.Redraw(); } // viewer.AddTrack(); } } bool getTempateFilePath(ref string templatePath) { bool b = false; templatePath = AppDomain.CurrentDomain.BaseDirectory + "Templates\\WellsSection\\"; if (Directory.Exists(templatePath) == false) { try { Directory.CreateDirectory(templatePath); } catch (UnauthorizedAccessException) { MessageBox.Show("没有创建模板目录的权限"); return b; } catch (PathTooLongException) { MessageBox.Show("路径太长"); return b; } catch (IOException ex) { MessageBox.Show($"IO错误: {ex.Message}"); return b; } catch (Exception ex) { MessageBox.Show($"发生错误: {ex.Message}"); return b; } } return true; } private void menuSaveWellTemplates_Click(object sender, EventArgs e) { string templatePath = ""; if (getTempateFilePath(ref templatePath) == false) return; SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "模板文件(*.pcg)|*.pcg"; dlg.Title = "保存模板文件"; string fileName = Path.GetFileName(this.drawer1.DrawFileName); dlg.InitialDirectory = templatePath; dlg.FileName = "template_" + fileName; if (dlg.ShowDialog() == DialogResult.OK) { GeoSigmaWellPoleXY geoWell = (GeoSigmaWellPoleXY)this.geoSigma; geoWell.SaveWellPoleTemplateFile(dlg.FileName); } } private void menuApplyingTemplates_Click(object sender, EventArgs e) { string templatePath = ""; if (getTempateFilePath(ref templatePath) == false) return; OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "选择模板文件"; dlg.Filter = "模板文件(*.pcg)|*.pcg"; dlg.RestoreDirectory = true; dlg.Multiselect = false; // 是否允许多选 dlg.InitialDirectory = templatePath; if (dlg.ShowDialog() == DialogResult.OK) { string filePath = dlg.FileName; GeoSigmaWellSectionXY sectionXY = (GeoSigmaWellSectionXY)this.Geo; ulong wellHandle = 0; sectionXY.GetSelectedWell(ref wellHandle); if (wellHandle != 0) { if (sectionXY.WellSectionApplyingTemplateFileForWell(filePath, wellHandle)) { this.drawer1.EnableRedraw = true; drawer1.Invalidate(); } } } } private void menuItemWellTrajectory_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; UInt64 wellHandle = 0; if (GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle) == true) { var dataDlg = new FrmWellDataEdit() { StartPosition = FormStartPosition.CenterScreen }; try { string dataType = "trajectory"; string[] colsName = new string[0]; string[,] datas = new string[0, 0]; GeoSigmaWellPoleXY.GetWellTrajectoryDatasJson(wellHandle, ref colsName, ref datas); string[] colsNameCH = new string[0]; GeoSigmaWellPoleXY.mWellTableInfos.GetTableColumnCHNames(dataType, colsName, ref colsNameCH); dataDlg.SetData(colsName, colsNameCH, datas); if (dataDlg.ShowDialog(this) == DialogResult.OK) { byte[] databytes = Encoding.UTF8.GetBytes(dataDlg.strJsonData); string jsonUtf8 = Encoding.ASCII.GetString(databytes);// Encoding.UTF8.GetString(databytes); //GeoSigmaWellPoleXY.SetWellTrackDataJson(thandle, databytes, databytes.Length); Invalidate(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void toolMenuItemRefreshWellPole_Click(object sender, EventArgs e) { try { //GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; //GeoSigmaWellPoleXY.SetWellUndoRedoAction(); //UInt64 wellHandle = 0; //GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle); //GeoSigmaWellPoleXY.GetWellBaseInfo(wellHandle, out GeoSigmaWellPoleXY.WellBaseInfo wellinfo); //readWorkAreaDataForWell(wellinfo.wellName); //drawer1.EnableRedraw = true; //drawer1.Invalidate(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //void readTrackWorkAreaData(ulong trackHandle, int ttype, string wellName, bool breadWellTable = true) //{ // GeoSigmaWellPoleXY geoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; // if ((GeoSigmaWellPoleXY.eWellExtType)(ttype) == GeoSigmaWellPoleXY.eWellExtType.Track_Lith) // { // List lstLiths = workAreaDb.Instance.workData.getWellLithologys(wellName); // string jsonStr = ""; // WellDataConvert.getWellLithologysJson(ref jsonStr, lstLiths); // geoSigmaWellPoleXY.SetWellTrackDataJson(trackHandle, jsonStr); // } // else if ((GeoSigmaWellPoleXY.eWellExtType)(ttype) == GeoSigmaWellPoleXY.eWellExtType.Track_Shot) // { // List listPerforations = workAreaDb.Instance.workData.getWellPerforations(wellName); // string jsonStr = ""; // WellDataConvert.getWellPerforationsJson(ref jsonStr, listPerforations); // geoSigmaWellPoleXY.SetWellTrackDataJson(trackHandle, jsonStr); // } // else if ((GeoSigmaWellPoleXY.eWellExtType)(ttype) == GeoSigmaWellPoleXY.eWellExtType.Track_Cycle) // { // string strSource, strCol; // strSource = strCol = ""; // geoSigmaWellPoleXY.TrackGetDataSourceID(trackHandle, ref strSource, ref strCol); // WellDataConvert.setWellCycleDataToTrack(geoSigmaWellPoleXY, wellName, trackHandle, strSource); // } // else if ((GeoSigmaWellPoleXY.eWellExtType)(ttype) == GeoSigmaWellPoleXY.eWellExtType.Track_InnerLayer) // { // List lstInnerLayers = workAreaDb.Instance.workData.getInnerLayers(wellName); // string jsonStr = ""; // WellDataConvert.getInnerLayersJson(ref jsonStr, lstInnerLayers); // geoSigmaWellPoleXY.SetWellTrackDataJson(trackHandle, jsonStr); // } // else // { // if (geoSigmaWellPoleXY.TrackIsWellTableDataSource(trackHandle) == true) // {//井内管理数据就直接读取井内数据。 // if (breadWellTable) // { // UInt64 wellHandle = 0; // if (geoSigmaWellPoleXY.GetSelectedWell(ref wellHandle)) // { // string tableId = ""; // string colId = ""; // geoSigmaWellPoleXY.TrackGetDataSourceID(trackHandle, ref tableId, ref colId); // readOneWellTableFromWorkArea(wellHandle, wellName, tableId); // if (tableId != "") // GeoSigmaWellPoleXY.RefreshAllInTrackObjsForOneWellTable(wellHandle, tableId); // } // } // else // geoSigmaWellPoleXY.TrackReadWellTableData(trackHandle); //读取井内管理的数据 // } // else // {//非井内管理数据,就先获得数据源,然后再设置 // string sourceId, strColId; // sourceId = strColId = ""; // bool b = geoSigmaWellPoleXY.TrackGetDataSourceID(trackHandle, ref sourceId, ref strColId); // if (b) // { // string jsonStr = ""; // WellDataConvert.getDataJson(wellName, sourceId, ref jsonStr); // geoSigmaWellPoleXY.SetWellTrackDataJson(trackHandle, jsonStr); // } // } // } //} //void readWorkAreaDataForWell(string wellName, UInt64 wellHandle) //{ // GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; // if (GeoSigmaWellPoleXY.GetWellTracks(wellHandle, out ulong[] trackHandles, out int[] ttypes, out string[] dataStrRef)) // { // int trackNum = trackHandles.Length; // readAllWellTableFromWorkArea(wellHandle, wellName);//读取井柱的所有井管理数据 // DataTable curvesTable = new DataTable(); // ResultDataInfo qCurveResult = new ResultDataInfo(); // for (int i = 0; i < trackNum; i++)//因为曲线数据是以文件的形式整体存储的,所以先将井的曲线数据都拿出来,然后去匹配。 // { // if ((GeoSigmaWellPoleXY.eWellExtType)(ttypes[i]) == GeoSigmaWellPoleXY.eWellExtType.Track_Curve) // { // qCurveResult = workAreaDb.Instance.workData.getCurvesData(wellName, ref curvesTable); // break; // } // } // for (int i = 0; i < trackNum; i++) // { // if ((GeoSigmaWellPoleXY.eWellExtType)(ttypes[i]) == GeoSigmaWellPoleXY.eWellExtType.Track_Curve) // { //曲线数据 // WellDataConvert.getWellCurveValueForNewWell(curvesTable, GeoSigmaWellPoleXY, wellHandle, trackHandles[i], dataStrRef[i]); // continue; // } // readTrackWorkAreaData(trackHandles[i], ttypes[i], wellName, false); // } // } //} //void readAllWellTableFromWorkArea(UInt64 wellHandle, string wellName) //{ // List wellTrajcectory = workAreaDb.Instance.workData.getWellTrajectory(wellName); // string trajStr = ""; // WellDataConvert.getWellTrajectoryJson(ref trajStr, wellTrajcectory); // if (trajStr != "")//读取井轨迹数据 // { // GeoSigmaWellPoleXY.SetWellTrajectoryDatasJson(wellHandle, trajStr); // } // readStratumDivisionFromWorkArea(wellHandle); // string strReservesLayers = ""; // List reservesLayers = workAreaDb.Instance.workData.getReservesLayers(wellName); //获取储层数据 // WellDataConvert.getReservesLayerJson(ref strReservesLayers, reservesLayers); // if (strReservesLayers != "") // { // GeoSigmaWellPoleXY.SetWellReservesLayersJson(wellHandle, strReservesLayers, false); // } // string strSandSet = ""; // List wellSandSets = workAreaDb.Instance.workData.getWellSandSets(wellName); //获取井分层数据 // WellDataConvert.getWellSandSetsJson(ref strSandSet, wellSandSets); // if (strSandSet != "") // { // GeoSigmaWellPoleXY.SetWellSandSetsJson(wellHandle, strSandSet, false); // } // string strFaultPoints = ""; // List wellFaults = workAreaDb.Instance.workData.getWellFaultPoints(wellName);//获取断点数据 // WellDataConvert.getWellFaultPointsJson(ref strFaultPoints, wellFaults); // if (strFaultPoints != "") // { // GeoSigmaWellPoleXY.SetWellFaultDatasJson(wellHandle, strFaultPoints, true); // } //} void SetSectionStratumDivisionFromWorkArea(IntPtr pSection) { string strStraifi = ""; List wellStratis = workAreaDb.Instance.workData.getWellStratification();//获取井分层级别数据。 WellDataConvert.getWellStratificationJson(ref strStraifi, wellStratis); if (strStraifi != "") {//设置井分层级别数据 GeoSigmaWellSectionXY.SetWellSectionStratificationJson(pSection, strStraifi); } string strStratums = ""; List stratums = workAreaDb.Instance.workData.getStratumDivisions(); //获取地质分层级别 WellDataConvert.getStratumDivisionJson(ref strStratums, stratums); if (strStratums != "") { GeoSigmaWellSectionXY.SetWellSectionStratumDivisionJson(pSection, strStratums); } } private void toolStripMenuItemTrackRefreshData_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; // geoSigma; int type, ttype; type = ttype = -1; UInt64 thandle = 0; GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref thandle); if (type != (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK)) return; if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Group) || ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Depth)) return; UInt64 wellHandle = 0; if (GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle) == false) return; GeoSigmaWellPoleXY.GetWellBaseInfo(wellHandle, out GeoSigmaWellPoleXY.WellBaseInfo wellinfo); if (workAreaDb.Instance.workData.isConn()) { if (ttype == (int)(GeoSigmaWellPoleXY.eWellExtType.Track_Curve)) { DataTable curvesTable = new DataTable(); ResultDataInfo qCurveResult = new ResultDataInfo(); string strXml = ""; if (GeoSigmaWellPoleXY.GetWellObjectAttributesXml(wellHandle, (int)GeoSigmaWellPoleXY.eWellExtType.KEP_WELL, 0, ref strXml) == true) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.LoadXml(strXml); XmlNode node = xmlDoc.SelectSingleNode("/Pcg/Head"); if (node != null) { string wellName = node.Attributes["WellName"].Value; qCurveResult = workAreaDb.Instance.workData.getCurvesData(wellName, ref curvesTable); string strCurve = ""; if (GeoSigmaWellPoleXY.GetWellObjectAttributesXml(thandle, (int)GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK, ttype, ref strCurve) == true) { xmlDoc.LoadXml(strCurve); node = xmlDoc.SelectSingleNode("/Pcg/WellTrack"); if (node != null) { string curveName = node.Attributes["Name"].Value; WellDataConvert.getWellCurveValueForNewWell(curvesTable, GeoSigmaWellPoleXY, wellHandle, thandle, curveName); } } } } catch (XmlException xmle) { Console.WriteLine(xmle.Message); } } } else { readTrackWorkAreaData(thandle, ttype, wellinfo.wellName); } drawer1.EnableRedraw = true; drawer1.Invalidate(); } } private void toolStripMenuItemSaveData_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; // geoSigma; int type, ttype; type = ttype = -1; UInt64 thandle = 0; GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref thandle); if (type != (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK)) return; UInt64 wellHandle = 0; GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle); GeoSigmaWellPoleXY.GetWellBaseInfo(wellHandle, out GeoSigmaWellPoleXY.WellBaseInfo wellinfo); string strJson = ""; if (MessageBox.Show("数据入库将删除原有数据,确定要保存数据吗?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel) return; if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_Lith) { GeoSigmaWellPoleXY.GetWellTrackDataJson(thandle, ref strJson); if (WellDataConvert.getWellLithologyFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.Well == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } else if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_InnerLayer) { GeoSigmaWellPoleXY.GetWellTrackDataJson(thandle, ref strJson); if (WellDataConvert.getWellInnerLayerFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.Well == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } else if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_Shot) { GeoSigmaWellPoleXY.GetWellTrackDataJson(thandle, ref strJson); if (WellDataConvert.getWellPerforationFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.JH == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } else if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_SandLayer) { GeoSigmaWellPoleXY.GetWellTrackDataJson(thandle, ref strJson); if (WellDataConvert.getWellInterpretDrillLayerFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.JH == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } else if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_Sandstone || ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_Result || ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_Facies) { GeoSigmaWellPoleXY.GetWellTableDatasJson(wellHandle, "ReservesLayer", ref strJson); if (WellDataConvert.getWellReserversLayerFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.Well == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } else if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_Cycle) { string strSource, strCol; strSource = strCol = ""; GeoSigmaWellPoleXY.TrackGetDataSourceID(thandle, ref strSource, ref strCol); GeoSigmaWellPoleXY.GetWellTrackDataJson(thandle, ref strJson); bool b = false; if (strSource == WellObjectBaseInfo.CycleTableTypes[(int)(WellObjectBaseInfo.eCycleDataType.CycleLongterm)]) //"CycleLongterm") { if (WellDataConvert.getWellLongCyClesJsonFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.Well == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } else if (strSource == WellObjectBaseInfo.CycleTableTypes[(int)(WellObjectBaseInfo.eCycleDataType.CycleShortterm)]) { if (WellDataConvert.getWellShortCyClesJsonFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.Well == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } else if (strSource == WellObjectBaseInfo.CycleTableTypes[(int)(WellObjectBaseInfo.eCycleDataType.CycleMediumterm)]) { if (WellDataConvert.getWellMediumCyClesJsonFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.Well == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } } } public override void SetAddFaultPoint() { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; GeoSigmaWellPoleXY.SetAddFaultPoint(); } public override bool IsAddFaultPoint() { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; return GeoSigmaWellPoleXY.IsAddFaultPoint(); } private void toolStripMenuItemEditFault_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; // geoSigma; int type, ttype; type = ttype = -1; UInt64 thandle = 0; GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref thandle); if (type != (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK)) return; if (ttype == (int)GeoSigmaWellPoleXY.eWellExtType.Track_SandLayer) { var dataDlg = new FrmWellDataEdit() { StartPosition = FormStartPosition.CenterScreen }; try { UInt64 wellHandle = 0; string strJson = ""; GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle); GeoSigmaWellPoleXY.GetWellTableDatasJson(wellHandle, "FaultPoint", ref strJson); string dataType = string.Empty; string[] colsName = new string[0]; string[,] datas = new string[0, 0]; WellDataConvert.getColNameAndDatasFromJson(strJson, ref dataType, ref colsName, ref datas); string[] colsNameCH = new string[0]; GeoSigmaWellPoleXY.mWellTableInfos.GetTableColumnCHNames(dataType, colsName, ref colsNameCH); dataDlg.SetData(colsName, colsNameCH, datas); if (dataDlg.ShowDialog(this) == DialogResult.OK) { // byte[] databytes = Encoding.UTF8.GetBytes(dataDlg.strJsonData); if (dataDlg.m_IsModified == true) { GeoSigmaWellPoleXY.SetWellFaultDatasJson(wellHandle, dataDlg.strJsonData, true); this.drawer1.Invalidate(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void toolStripMenuItemFaultInDB_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; // geoSigma; int type, ttype; type = ttype = -1; UInt64 thandle = 0; GeoSigmaWellPoleXY.GetSelectWellObject(ref type, ref ttype, ref thandle); if (type != (int)(GeoSigmaWellPoleXY.eWellExtType.KEP_TRACK)) return; UInt64 wellHandle = 0; GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle); GeoSigmaWellPoleXY.GetWellBaseInfo(wellHandle, out GeoSigmaWellPoleXY.WellBaseInfo wellinfo); string strJson = ""; GeoSigmaWellPoleXY.GetWellTableDatasJson(wellHandle, "FaultPoint", ref strJson); if (WellDataConvert.getWellFaultsFromJson(wellinfo.wellName, strJson, out List list)) { DBHelp.NewDb.Deleteable(r => r.JH == wellinfo.wellName).ExecuteCommand(); DBHelp.NewDb.BulkInsert(list); MessageBox.Show("写入完毕"); } } //public void InitStratumDivisionData() //{ // GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)geoSigma; // UInt64 wellHandle = 0; // if (GeoSigmaWellPoleXY.GetSelectedWell(ref wellHandle)) // { // readStratumDivisionFromWorkArea(wellHandle); // } //} public void SetBendsSmooth() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.SetBendsSmooth(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void SetWellSectionFlatternStyle(int style) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.SetWellSectionFlatternStyle(style); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void SetSectionWellShowStyle(int style) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.SetSectionWellShowStyle(style); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void ConnetAllLayers() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionConnectAllLayers(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void BreakAllBends() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionBreakAllBends(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void SetBendLinkStyle(int style) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.SetWellSectionBendLinkStyle(style); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void SetBendLeftExtendStyle(int style) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.SetWellSectionBendLeftExtendStyle(style); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void SetBendRightExtendStyle(int style) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.SetWellSectionBendRightExtendStyle(style); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void SetSectionDrawAddFaultItem() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.SetWellSectionDrawAddFaultItem(); } public void WellSectionAddDepthRuler() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionAddDepthRuler(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void WellSectionAddBendLayerPoint() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionAddBendLayerPoint(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void WellSectionDeleteBendLayerPoint() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionDeleteBendLayerPoint(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void WellSectionAddFaultPoint() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionAddFaultPoint(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } public void WellSectionDeleteFaultPoint() { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionDeleteFaultPoint(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } private void toolStripMenuItemBreakLeftLayer_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionBreakLeftBend(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } private void toolStripMenuItemBreakRightLayer_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionBreakRightBend(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } private void toolStripMenuItemConnectLeftLayer_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionConnectLeftLayer(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } private void toolStripMenuItemConnectRightLayer_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionConnectRightLayer(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } private void toolStripMenuItemConnectAllLayer_Click(object sender, EventArgs e) { GeoSigmaWellSectionXY geoSectionXY = (GeoSigmaWellSectionXY)geoSigma; geoSectionXY.WellSectionConnectLeftRightLayer(); drawer1.EnableRedraw = true; drawer1.Invalidate(); } private void toolStripMenuItemDelInTrack_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; GeoSigmaWellPoleXY.DeleteSelectedWellObject(); } private void menuDelSectionWell_Click(object sender, EventArgs e) { GeoSigmaWellPoleXY GeoSigmaWellPoleXY = (GeoSigmaWellPoleXY)this.Geo; GeoSigmaWellPoleXY.DeleteSelectedWellObject(); } public void createWellSection(List wells, string mTemplatefileNamePath, List linkTracks , ListselectLayersNames, double topExtent,double bottomExtent) { if (wells.Count == 0) return; GeoSigmaWellSectionXY geoSectionXy = (GeoSigmaWellSectionXY)this.Geo; string title = ""; for (int i = 0; i < wells.Count; i++) { title = title + wells[i].WellName + "+"; } title = title.TrimEnd('+'); IntPtr pSection = geoSectionXy.CreateWellSection(title, 1000, 1000, 2000); if (pSection == null) return; SetSectionStratumDivisionFromWorkArea(pSection); double prex = wells[0].x ?? 0; double prey = wells[0].y ?? 0; double len = 500; //如果没有x,y坐标就默认设置一个距离 List wellHandleList = new List(); for (int i = 0; i < wells.Count; i++) { UInt64 tHandle = 0; double x = wells[i].x ?? 0; double y = wells[i].y ?? 0; if (Math.Abs(x) < 0.0001)//如果没有x,y就拉开距离(这个不是特完善) x = prex + len; if (Math.Abs(y) < 0.0001) y = prey + len; double bushingLevel = wells[i].BushingLevel ?? 0; double top = 500; double bottom = 1000; if(selectLayersNames.Count > 0) { //选择了层位,就使用层位计算一下井深度 List tWellLayers = workAreaDb.Instance.workData.getWellSandSets(wells[i].WellName); double top1 = 999999; double bottom1 = -999999; if (tWellLayers.Count > 0) { bool bfind = false; for(int j = 0; j < tWellLayers.Count; j++) { if (selectLayersNames.Contains(tWellLayers[j].name)) { bfind = true; if (tWellLayers[j].top < top1) top1 = tWellLayers[j].top; if (tWellLayers[j].bottom > bottom1) bottom1 = tWellLayers[j].bottom; } } if(bfind) { top = top1 -2; bottom = bottom1 +2; } } } if (geoSectionXy.WellSectionAddNewWell(wells[i].WellName, 1000, top, bottom, x, y, bushingLevel, mTemplatefileNamePath, ref tHandle)) { wellHandleList.Add(tHandle); readWorkAreaDataForWell(wells[i].WellName, tHandle); } else { wellHandleList.Add(0); } prex = x; prey = y; } bool bDepth = true; if (selectLayersNames.Count > 0) bDepth = false; geoSectionXy.WellSectionReSetAllWellsPosition(bDepth,topExtent,bottomExtent); string trackTypeStr = ""; for (int i = 0; i < linkTracks.Count; i++) { trackTypeStr = trackTypeStr + linkTracks[i] + ";"; } trackTypeStr = trackTypeStr.TrimEnd(';'); geoSectionXy.WellSectionConnectLayers(trackTypeStr); } private void toolStripMenuItemUseWellTempForSection_Click(object sender, EventArgs e) { ulong wellHandle = 0; GeoSigmaWellSectionXY geoSectionXy = (GeoSigmaWellSectionXY)this.Geo; geoSectionXy.GetSelectedWell(ref wellHandle); if (wellHandle != 0) { if (geoSectionXy.WellSectionApplyingWellTemplateForSection(wellHandle) == true) { this.drawer1.EnableRedraw = true; drawer1.Invalidate(); } } } private void toolStripMenuSectionUseTempale_Click(object sender, EventArgs e) { string templatePath = ""; if (getTempateFilePath(ref templatePath) == false) return; OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "选择模板文件"; dlg.Filter = "模板文件(*.pcg)|*.pcg"; dlg.RestoreDirectory = true; dlg.Multiselect = false; // 是否允许多选 dlg.InitialDirectory = templatePath; if (dlg.ShowDialog() == DialogResult.OK) { string filePath = dlg.FileName; GeoSigmaWellSectionXY sectionXY = (GeoSigmaWellSectionXY)this.Geo; if(sectionXY.WellSectionApplyingTemplateFileForSection(filePath)) { this.drawer1.EnableRedraw = true; this.drawer1.Invalidate(); } } } } }