using GeoSigma.UCDraw; using SigmaDrawerElement; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using UCDraw; using Unplugged.Segy; namespace GeoSigma.PcgDrawSection { public partial class FormSegYParse : Form { //int inlineMin = 0, inlineMax = 0, crosslineMin = 0, crosslineMax = 0; //ISegyFile segy; //ISegyOptions segyOptions; //bool bEnableDraw = true; //DrawViewer drawView = null; //long sectionPtr = 0; public FormSegYParse() { InitializeComponent(); //ttxtInlineNum.TextBox.Validating += ttxtInlineNum_Validating; //ttxtCrosslineNum.TextBox.Validating += ttxtCrosslineNum_Validating; //segyOptions = new SegyOptions(); //InitSectionViewer(); } private void FormSegYParse_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = ucSectionViewer1.CancelClosing(); } //private void FormSegYParse_Load(object sender, EventArgs e) //{ // Application.Idle += Application_Idle; //} //private void Application_Idle(object sender, EventArgs e) //{ // bool isTraceShow = this.tsbtnInline.Checked; // for (int i = 0; i < this.bdnavInline.Items.Count; i++) // { // this.bdnavInline.Items[i].Enabled = isTraceShow; // } // for (int i = 0; i < this.bdnavCrossline.Items.Count; i++) // { // this.bdnavCrossline.Items[i].Enabled = !isTraceShow; // } // this.tsbtnInline.Enabled = true; // this.bindingNavigatorCountItem1.Enabled = true; // this.tsbtnCrossline.Enabled = true; // this.bindingNavigatorCountItem.Enabled = true; //} ///// ///// 创建剖面绘图区 ///// //private void InitSectionViewer() //{ // MainView viewer = new MainView(); // viewer.ToolMainVisible = false; // viewer.DrawerGotFocus += (object drawer, EventArgs ea) => // { // Trace.WriteLine("openFile:" + ea.ToString()); // }; // if (viewer.NewFile("Inline") == false) // { // return; // } // drawView = viewer.ViewControl; // mainContainer.TopToolStripPanel.Controls.Add(viewer.ToolstripElements); // this.tspMain.Location = new Point(0, 0); // viewer.ToolstripElements.Location = new Point(0, this.tspMain.Height+2); // mainContainer.ContentPanel.Controls.Add(drawView); // viewer.ViewControl.Dock = DockStyle.Fill; //} ///// ///// 打开文件 ///// ///// ///// //private void tbtnOpenFile_Click(object sender, EventArgs e) //{ // OpenFileDialog ofd = new OpenFileDialog(); // ofd.Filter = "Segy文件|*.segy;*.sgy|所有文件|*.*"; // ofd.RestoreDirectory = true; // ofd.Title = "打开Segy文件"; // if(ofd.ShowDialog(this)!= DialogResult.OK) // { // return; // } // string strFile = ofd.FileName; // var reader = new SegyReader(); // reader.Options = segyOptions; // segy = reader.Read(strFile, new SegyReadingProgress(this.tpgbMain.ProgressBar)); // this.tpgbMain.Value = 0; // ResetLineRange(); //} ///// ///// 重置并绑定inline、crossline ///// //private void ResetLineRange() //{ // // Inline、Crossline范围 // segy.GetLineRange(ref inlineMin, ref inlineMax, ref crosslineMin, ref crosslineMax); // int nProgress = 0; // bEnableDraw = false; // int[] arrCrossline = new int[crosslineMax - crosslineMin + 1]; // for (int i = crosslineMin; i <= crosslineMax; i++) // { // arrCrossline[nProgress] = crosslineMin + nProgress; // nProgress++; // } // this.bdSourceCrossline.DataSource = arrCrossline; // this.bdnavCrossline.BindingSource = this.bdSourceCrossline; // this.bindingNavigatorCountItem.Text = $"/{crosslineMax}"; // this.ttxtCrosslineNum.Text = $"{crosslineMin}"; // bEnableDraw = true; // int[] arrInline = new int[inlineMax - inlineMin + 1]; // nProgress = 0; // for (int i = inlineMin; i <= inlineMax; i++) // { // arrInline[nProgress] = inlineMin + nProgress; // nProgress++; // } // this.bdSourceInline.DataSource = arrInline; // this.bdnavInline.BindingSource = this.bdSourceInline; // this.bindingNavigatorCountItem1.Text = $"/{inlineMax}"; // this.ttxtInlineNum.Text = $"{inlineMin}"; // this.tsbtnInline.Checked = true; // this.tsbtnCrossline.Checked = false; //} ///// ///// 打开文件头分析窗口 ///// ///// ///// //private void tbtnParseHeader_Click(object sender, EventArgs e) //{ // FormParseHeader frmParse = new FormParseHeader(); // frmParse.Segy = this.segy; // frmParse.Options = this.segyOptions; // frmParse.Show(this); // frmParse.FormClosed += (object frm, FormClosedEventArgs close) => // { // if(frmParse.DialogResult == DialogResult.OK) // { // ResetLineRange(); // } // }; //} //private void bdnavInline_RefreshItems(object sender, EventArgs e) //{ //} ///// ///// 跳转到inline ///// ///// ///// //private void ttxtInlineNum_KeyPress(object sender, KeyPressEventArgs e) //{ // postionEdit(sender, e, (int[])bdSourceInline.DataSource); //} ///// ///// 跳转到crossline ///// ///// ///// //private void ttxtCrosslineNum_KeyPress(object sender, KeyPressEventArgs e) //{ // postionEdit(sender, e, (int[])bdSourceCrossline.DataSource); //} //private void postionEdit(object sender, KeyPressEventArgs e, int[] values) //{ // if(values == null) // { // return; // } // if (e.KeyChar == (char)Keys.Return) // { // string strValue = ((ToolStripTextBox)sender).Text; // if (string.IsNullOrEmpty(strValue)) // { // e.Handled = true; // return; // } // int nValue = Convert.ToInt32(strValue); // int nPos = Array.IndexOf(values,nValue); // if (nPos >= 0) // { // this.bdSourceInline.Position = nPos; // } // e.Handled = true; // } // else // { // if (e.KeyChar != '\b')//这是允许输入退格键 // { // if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 // { // e.Handled = true; // } // } // } //} ///// ///// Inline导航事件 ///// ///// ///// //private void bdSourceInline_PositionChanged(object sender, EventArgs e) //{ // int nInlineNum = ((int[])bdSourceInline.DataSource)[bdSourceInline.Position]; // this.ttxtInlineNum.Text = nInlineNum.ToString(); // if (bEnableDraw) // { // ShowInline(nInlineNum); // } //} ///// ///// Crossline导航事件 ///// ///// ///// //private void bdSourceCrossline_PositionChanged(object sender, EventArgs e) //{ // int nlineNum = ((int[])bdSourceCrossline.DataSource)[bdSourceCrossline.Position]; // this.ttxtCrosslineNum.Text = nlineNum.ToString(); // if (bEnableDraw) // { // ShowCrossline(nlineNum); // } //} ///// ///// 切换到Inline浏览 ///// ///// ///// //private void tsbtnInline_Click(object sender, EventArgs e) //{ // this.tsbtnInline.Checked = true; // this.tsbtnCrossline.Checked = false; //} //private void tsbtnCrossline_Click(object sender, EventArgs e) //{ // this.tsbtnInline.Checked = false; // this.tsbtnCrossline.Checked = true; //} //private void bdnavCrossline_RefreshItems(object sender, EventArgs e) //{ //} //private void ttxtInlineNum_Validating(object sender, CancelEventArgs e) //{ // bool bValid = Regex.IsMatch(ttxtInlineNum.Text, @"^\d+$"); // if (!bValid) // { // e.Cancel = true; // } //} //private void ttxtCrosslineNum_Validating(object sender, CancelEventArgs e) //{ // bool bValid = Regex.IsMatch(ttxtCrosslineNum.Text, @"^\d+$"); // if (!bValid) // { // e.Cancel = true; // } //} //private void ShowCrossline(int lineNum) //{ // int nCount = segy.Traces.Count; // List lstTraceIndex = new List(); // for (int i = 0; i < nCount; i++) // { // if (segy.Traces[i].Header.CrosslineNumber == lineNum) // { // lstTraceIndex.Add(i); // } // } // DrawerSeismicSection section = new DrawerSeismicSection(); // section.Base.TraceCount = lstTraceIndex.Count; // section.Base.SampleCount = segy.Header.SampleNumber; // section.Base.SampleStep = segy.Header.SampleInteral; // section.Base.FormatCode = (int)segy.Header.SampleFormat; // section.Base.IsPC = this.segyOptions.IsLittleEndian.Value ? 1 : 0; // DrawerElementProperty property = new DrawerElementProperty(); // property.Element = section; // string strProperty = DrawerElementHelp.Serialize(property); // float[] btsValus = new float[section.Base.SampleCount * section.Base.TraceCount]; // int nTraceCount = section.Base.TraceCount; // int nSampleCount = section.Base.SampleCount; // for (int i = 0; i < nTraceCount; i++) // { // for (int j = 0; j < nSampleCount; j++) // { // btsValus[i * nSampleCount + j] = segy.Traces[lstTraceIndex[i]].Values[j]; // } // } // if (sectionPtr > 0) // { // this.drawView.DeleteSeismicSection(sectionPtr); // sectionPtr = this.drawView.AddSeismicSection(strProperty, btsValus); // btsValus = null; // this.drawView.Redraw(); // } // else // { // sectionPtr = this.drawView.AddSeismicSection(strProperty, btsValus); // btsValus = null; // this.drawView.ViewAll(); // } //} //private void ShowInline(int inlineNum) //{ // int nCount = segy.Traces.Count; // List lstTraceIndex = new List(); // for (int i = 0; i < nCount; i++) // { // if(segy.Traces[i].Header.InlineNumber == inlineNum) // { // //if (segy.Traces[i].Header.CrosslineNumber > 1449 // // && segy.Traces[i].Header.CrosslineNumber < 1451) // { // lstTraceIndex.Add(i); // } // } // } // DrawerSeismicSection section = new DrawerSeismicSection(); // section.Base.TraceCount = lstTraceIndex.Count; // section.Base.SampleCount = segy.Header.SampleNumber; // section.Base.SampleStep = segy.Header.SampleInteral; // section.Base.FormatCode = (int)segy.Header.SampleFormat; // section.Base.IsPC = this.segyOptions.IsLittleEndian.Value ? 1 : 0; // DrawerElementProperty property = new DrawerElementProperty(); // property.Element = section; // string strProperty = DrawerElementHelp.Serialize(property); // float[] btsValus = new float[section.Base.SampleCount * section.Base.TraceCount]; // int nTraceCount = section.Base.TraceCount; // int nSampleCount = section.Base.SampleCount; // StringBuilder strbMsg = new StringBuilder(); // for (int i=0;i< nTraceCount; i++) // { // // Buffer.BlockCopy(segy.Traces[lstTraceIndex[i]].Values, 0, btsValus, 0, section.Base.SampleCount); // for(int j=0;j< nSampleCount; j++) // { // btsValus[i * nSampleCount + j] = segy.Traces[lstTraceIndex[i]].Values[j]; // //strbMsg.AppendLine($"{btsValus[i * nSampleCount + j]}"); // } // } // Trace.WriteLine(strbMsg.ToString()); // if (sectionPtr > 0) // { // this.drawView.DeleteSeismicSection(sectionPtr); // sectionPtr = this.drawView.AddSeismicSection(strProperty, btsValus); // btsValus = null; // this.drawView.Redraw(); // } // else // { // sectionPtr = this.drawView.AddSeismicSection(strProperty, btsValus); // btsValus = null; // this.drawView.ViewAll(); // } //} } public class SegyReadingProgress : IReadingProgress { public ProgressBar ProgressControl { get; set; } public bool CancellationPending { get; set; } = false; public SegyReadingProgress(ProgressBar progressControl) { this.ProgressControl = progressControl; } public void ReportProgress(int progressPercentage) { if (ProgressControl != null) { ProgressControl.Value = progressPercentage; } } } }