using GeoSigmaDrawLib; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace QuikGridCS { public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// /// 选择输入文件. /// /// The sender. /// The e. private void btnInputFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "*.xyz|*.xyz|*.*|*.*"; ofd.RestoreDirectory = true; if(ofd.ShowDialog() == DialogResult.OK) { this.txtInput.Text = ofd.FileName; this.LoadFile(this.txtInput.Text); } } /// /// 加载文件. /// /// The xyz file. private void LoadFile(string xyzFile) { if (Interface.QuikGridLoadFileXyz(this.txtInput.Text) == 0) { return; } loadGridInfo(); } /// /// 加载网格信息. /// private void loadGridInfo() { double xMin = 0; double xMax = 0; double yMin = 0; double yMax = 0; int countX = 0; int countY = 0; double zMin = 0; double zMax = 0; int nReturn = Interface.QuikGridGetView(ref xMin, ref xMax, ref yMin, ref yMax, ref countX, ref countY, ref zMin, ref zMax); if (nReturn == 0) { return; } this.txtXMin.Text = $"{xMin}"; this.txtXMax.Text = $"{xMax}"; this.txtYMin.Text = $"{yMin}"; this.txtYMax.Text = $"{yMax}"; this.txtZMin.Text = $"{zMin}"; this.txtZMax.Text = $"{zMax}"; this.txtXCount.Text = $"{countX}"; this.txtYCount.Text = $"{countY}"; } /// /// 输出文件选择事件. /// /// The sender. /// The e. private void btnOutputFile_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Surfer GRD|*.grd"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { this.txtOutput.Text = sfd.FileName; } } /// /// 选择Kev输出文件. /// /// The sender. /// The e. private void btnOutputFileKev_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "*.Kev|*.kev|*.dfd|*.dfd"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { this.txtOutputKev.Text = sfd.FileName; } } /// /// 执行输出. /// /// The sender. /// The e. private void btnOutput_Click(object sender, EventArgs e) { string strFileInput = this.txtInput.Text; string strFileKev = this.txtOutputKev.Text; int nXCount = 0; int nYCount = 0; if (int.TryParse(this.txtXCount.Text, out nXCount) == false || int.TryParse(this.txtYCount.Text, out nYCount) == false) { MessageBox.Show("网格数量不正确"); return; } double dContourSpace = double.Parse(txtContourSpace.Text); int dContourLable = int.Parse(txtContourLableSpace.Text); double dSmooth = double.Parse(this.txtSmoothFactor.Text); Interface.QuikGridCreate(strFileInput, strFileKev, nXCount, nYCount, dContourSpace, dContourLable, dSmooth); MessageBox.Show("网格化成功,结果已经保存到文件!"); return; //Interface.QuikGridGenerateGrid(); if (Interface.QuikGridFromFile(strFileInput, nXCount, nYCount)== true) { Interface.QuikGridGenerateGrid(); double xMin = 0; double xMax = 0; double yMin = 0; double yMax = 0; int countX = 0; int countY = 0; double zMin = 0; double zMax = 0; int nReturn = Interface.QuikGridGetView(ref xMin, ref xMax, ref yMin, ref yMax, ref countX, ref countY, ref zMin, ref zMax); if (nReturn == 0) { return; } double dStepX = (xMax - xMin) / (countX-1); double dStepY = (yMax - yMin) / (countY-1); string strFileOut = this.txtOutput.Text; if (!string.IsNullOrEmpty(strFileOut)) { Interface.QuikGridSaveFileGrd(strFileOut); } if (!string.IsNullOrEmpty(strFileKev)) { IntPtr ptrValues = Interface.QuikGridGridValue(); DrawerData drawer = new DrawerData(); long pos = drawer.CreateMesh("背景", ptrValues, xMin, yMin, countX, countY, dStepX, dStepY, zMin, zMax); //double dContourSpace = double.Parse(txtContourSpace.Text); //int dContourLable = int.Parse(txtContourLableSpace.Text); if(dContourSpace>0&& dContourLable > 0) { drawer.CreateContour(pos, dContourSpace, dContourLable); } drawer.SaveAs(strFileKev); drawer.Dispose(); // 释放数据指针 GeoSigmaLib.PointerArrayDelete(ptrValues); } loadGridInfo(); MessageBox.Show("网格化成功,结果已经保存到文件!"); } } } }