You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1020 lines
36 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GeoSigma.UCDraw;
using System.Diagnostics;
using UCDraw;
using Unplugged.Segy;
using System.Text.RegularExpressions;
using SigmaDrawerElement;
using GeoSigma.SigmaDrawerStyle;
using GeoSigmaDrawLib;
namespace GeoSigma.PcgDrawSection
{
public delegate void ShowSectionEventHandler(int sectionType, int sectionNum);
public partial class UCSectionViewer : UserControl
{
public ShowSectionEventHandler ShowSectionEvent = null;
/// <summary>
/// 剖面类型1-Inline;2-Xline.
/// </summary>
public int SectionType { get; set; }
public int SectionNum { get; set; }
public ISegyFile Segy { get; set; }
public ISegyOptions SegyOptions { get; set; }
private int startInline = 0;
private int startXline = 0;
public MainView ViewController { get; set; }
public DrawViewer Viewer { get; set; }
long sectionPtr = 0;
int inlineMin = 0, inlineMax = 0, crosslineMin = 0, crosslineMax = 0;
bool bEnableDraw = true;
/// <summary>
/// 打开按钮是否显示
/// </summary>
public bool ShowToolButtonOpen
{
get
{
return tbtnOpenFile.Visible;
}
set
{
tbtnOpenFile.Visible = value;
}
}
/// <summary>
/// 格式分析按钮是否可见
/// </summary>
public bool ShowToolParse
{
get
{
return tbtnParseHeader.Visible;
}
set
{
tbtnParseHeader.Visible = value;
}
}
private PanelProperty propertyControl;
public PanelProperty PropertyControl
{
get
{
return propertyControl;
}
private set
{
propertyControl = value;
}
}
public UCSectionViewer()
{
InitializeComponent();
ttxtInlineNum.TextBox.Validating += ttxtInlineNum_Validating;
ttxtCrosslineNum.TextBox.Validating += ttxtCrosslineNum_Validating;
SegyOptions = new SegyOptions();
InitSectionViewer();
}
/// <summary>
/// 添加线
/// </summary>
/// <param name="layerName">图层</param>
/// <param name="name">线名</param>
/// <param name="pts">坐标点</param>
public void AddDrawCurve(string layerName, string name, List<PointD> pts)
{
Viewer.AddDrawCurve(layerName, name, pts);
}
/// <summary>
/// 添加剖面上的线
/// </summary>
/// <param name="layerName"></param>
/// <param name="name"></param>
/// <param name="pts"></param>
public void AddSectionCurve(string layerName, string name, List<PointD> pts)
{
Viewer.DeleteElement(layerName, name);
List<PointD> lstPt = new List<PointD>();
if (this.SectionType == 1)
{
for(int i= 0; i < pts.Count; i++)
{
if(pts[i].X>= crosslineMin && pts[i].X<= crosslineMax)
{
lstPt.Add(new PointD((pts[i].X - crosslineMin) * 10, pts[i].Y));
}
}
}
else
{
for (int i = 0; i < pts.Count; i++)
{
if (pts[i].X >= inlineMin && pts[i].X <= inlineMax)
{
lstPt.Add(new PointD((pts[i].X - inlineMin) * 10, pts[i].Y));
}
}
}
this.AddDrawCurve(layerName, name, lstPt);
}
public int DeleteSectionCurve(string layerName, string name)
{
return Viewer.DeleteElement(layerName, name);
}
public void Redraw()
{
this.Viewer.Redraw();
}
private void btnTest_Click(object sender, EventArgs e)
{
string strCurveName = "P1";
string strLayerName = "层位";
// 测试添加解释成果
List<PointD> pts = new List<PointD>();
pts.Add(new PointD(0, -967.0000));
pts.Add(new PointD(100, -966.6250));
pts.Add(new PointD(200, -966.2500));
pts.Add(new PointD(300, -965.8750));
pts.Add(new PointD(400, -965.5000));
pts.Add(new PointD(500, -965.1250));
this.AddDrawCurve(strLayerName, strCurveName, pts);
// 测试样式设置 ResetCurveStyle
CurveProperty curveProperty = new CurveProperty();
curveProperty.CurveType = (int)LineType.PLINE_TRANSPARENT;
curveProperty.Width = 3;
curveProperty.LineColor = Color.Green;
int nCount = Viewer.ResetCurveStyle(strCurveName, strLayerName, curveProperty);
Viewer.Redraw();
}
/// <summary>
/// 启动播放Inline
/// </summary>
/// <param name="lineNo"></param>
public void PlayInline(int lineNo)
{
this.Viewer.DeleteSectionAll();
sectionPtr = 0;
bool isTraceShow = true;
for (int i = 0; i < this.bdnavInline.Items.Count; i++)
{
this.bdnavInline.Items[i].Enabled = isTraceShow;
}
this.tsbtnCrossline.Checked = false;
this.tsbtnInline.Checked = true;
this.tsbtnInline.Visible = false;
this.bdnavInline.Visible = true;
this.bdnavCrossline.Visible = false;
ShowInline(lineNo);
// 设置导航位置
ttxtInlineNum.Text = lineNo.ToString();
int[] values = (int[])this.bdSourceInline.DataSource;
if (values == null)
{
return;
}
int nPos = Array.IndexOf(values, lineNo);
if (nPos >= 0)
{
bEnableDraw = false;
this.bdSourceInline.Position = nPos;
bEnableDraw = true;
}
//ShowInline(lineNo);
}
/// <summary>
/// 启动播放Crossline
/// </summary>
/// <param name="lineNo"></param>
public void PlayCrossline(int lineNo)
{
this.Viewer.DeleteSectionAll();
sectionPtr = 0;
bool isTraceShow = true;
for (int i = 0; i < this.bdnavCrossline.Items.Count; i++)
{
this.bdnavCrossline.Items[i].Enabled = isTraceShow;
}
this.tsbtnInline.Checked = false;
this.tsbtnCrossline.Checked = true;
this.tsbtnCrossline.Visible = false;
this.bdnavInline.Visible = false;
this.bdnavCrossline.Visible = true;
ShowCrossline(lineNo);
// 设置导航位置
ttxtCrosslineNum.Text = lineNo.ToString();
int[] values = (int[])this.bdSourceCrossline.DataSource;
if (values == null)
{
return;
}
int nPos = Array.IndexOf(values, lineNo);
if (nPos >= 0)
{
bEnableDraw = false;
this.bdSourceCrossline.Position = nPos;
bEnableDraw = true;
}
//ShowCrossline(lineNo);
}
private void UCSectionViewer_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;
}
/// <summary>
/// 创建剖面绘图区
/// </summary>
private void InitSectionViewer()
{
ViewController = new MainView();
ViewController.ToolMainVisible = false;
ViewController.DrawerGotFocus += (object drawer, EventArgs ea) =>
{
//Trace.WriteLine("openFile:" + ea.ToString());
};
if (ViewController.NewFile("Inline") == false)
{
return;
}
Viewer = ViewController.ViewControl;
propertyControl = ViewController.PropertyControl;
mainContainer.TopToolStripPanel.Controls.Add(ViewController.ToolstripElements);
this.tspMain.Location = new Point(0, 0);
ViewController.ToolstripElements.Location = new Point(0, this.tspMain.Height + 2);
//mainContainer.ContentPanel.Controls.Add(drawView);
this.splitContainer1.Panel1.Controls.Add(Viewer);
ViewController.ViewControl.Dock = DockStyle.Fill;
this.splitContainer1.Panel2Collapsed = true;
//this.splitContainer1.Panel2.Controls.Add(propertyControl);
//propertyControl.Dock = DockStyle.Fill;
}
/// <summary>
/// 保存文件
/// </summary>
/// <returns>是否成功</returns>
public bool SaveFile()
{
if (ViewController.IsNewDocument)
{
return SaveAs();
}
if (ViewController.SaveFile())
{
this.Text = ViewController.Text;
}
return true;
}
/// <summary>
/// 另存为
/// </summary>
/// <returns>是否成功</returns>
public bool SaveAs()
{
if (ViewController.SaveAs())
{
this.Text = ViewController.Text;
//NewFileSavedEvent?.Invoke(mainView.FileFullName);
return true;
}
return false;
}
public bool SaveTo(string fileNew)
{
return ViewController.SaveTo(fileNew);
}
/// <summary>
/// 是否需要取消操作,文件已经修改,阻止关闭
/// </summary>
/// <returns></returns>
public bool CancelClosing()
{
if (this.ViewController != null && this.ViewController.IsDocumentModified())
{
switch (MessageBox.Show("文件已修改,是否保存?", "保存",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question))
{
case DialogResult.Cancel:
return true;
case DialogResult.Yes:
if (SaveFile() == false)
{
return true;
}
else
{
return false;
}
case DialogResult.No:
return false;
}
}
return false;
}
/// <summary>
/// 打开文件
/// </summary>
/// <param name="strFile">文件路径</param>
/// <param name="setZColor">是否以方块方式显示散点数据</param>
public void OpenFile(string strFile)
{
try
{
this.SuspendLayout();
MainView mainView = new MainView();
mainView.ToolMainVisible = false;
if (mainView.OpenFile(strFile) == false)
{
return;
}
//mainView.DrawerGotFocus += (object drawer, EventArgs ea) =>
//{
// //Trace.WriteLine("openFile:" + ea.ToString());
//};
Viewer = mainView.ViewControl;
propertyControl = mainView.PropertyControl;
mainContainer.TopToolStripPanel.Controls.Remove(ViewController.ToolstripElements);
mainContainer.TopToolStripPanel.Controls.Add(mainView.ToolstripElements);
this.tspMain.Location = new Point(0, 0);
mainView.ToolstripElements.Location = new Point(0, this.tspMain.Height + 2);
this.splitContainer1.Panel1.Controls.Clear();
this.splitContainer1.Panel1.Controls.Add(Viewer);
mainView.ViewControl.Dock = DockStyle.Fill;
ViewController = mainView;
sectionPtr = 0;
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
finally
{
this.ResumeLayout();
}
}
/// <summary>
/// 保存文件
/// </summary>
/// <param name="sender">按钮</param>
/// <param name="e">事件参数</param>
private void tsbtnSave_Click(object sender, EventArgs e)
{
SaveFile();
}
/// <summary>
/// 打开文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbtnOpenFile_Click(object sender, EventArgs e)
{
if(CancelClosing() == true)
{
return;
}
string strFile = DocHelper.OpenDialog();
if (strFile == null)
{
return;
}
OpenFile(strFile);
}
private void tsbtnSetSegy_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;
}
Segy = OpenSegyFile(ofd.FileName);
ResetLineRange();
}
public ISegyFile OpenSegyFile(string segyFileName, IReadingProgress progress = null)
{
var reader = new SegyReader();
reader.Options = SegyOptions;
ISegyFile segyFile = reader.Read(segyFileName, progress);
// segy = reader.Read(strFile, new SegyReadingProgress(this.tpgbMain.ProgressBar));
// this.tpgbMain.Value = 0;
//ResetLineRange();
return segyFile;
}
/// <summary>
/// 打开文件头分析窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbtnParseHeader_Click(object sender, EventArgs e)
{
ShowParseDialog();
}
private void ShowParseDialog()
{
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();
}
};
}
/// <summary>
/// 切换到Inline浏览
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 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;
}
}
/// <summary>
/// 跳转到inline
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ttxtInlineNum_KeyPress(object sender, KeyPressEventArgs e)
{
postionEdit(sender, e, bdSourceInline);
}
/// <summary>
/// 跳转到crossline
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ttxtCrosslineNum_KeyPress(object sender, KeyPressEventArgs e)
{
postionEdit(sender, e, bdSourceCrossline);
}
private void postionEdit(object sender, KeyPressEventArgs e, BindingSource binding)
{
int[] values = (int[])binding.DataSource;
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)
{
binding.Position = nPos;
}
e.Handled = true;
}
else
{
if (e.KeyChar != '\b')//这是允许输入退格键
{
if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字
{
e.Handled = true;
}
}
}
}
/// <summary>
/// Inline导航事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bdSourceInline_PositionChanged(object sender, EventArgs e)
{
int nInlineNum = ((int[])bdSourceInline.DataSource)[bdSourceInline.Position];
this.ttxtInlineNum.Text = nInlineNum.ToString();
if (bEnableDraw)
{
ShowInline(nInlineNum);
}
}
/// <summary>
/// Crossline导航事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bdSourceCrossline_PositionChanged(object sender, EventArgs e)
{
int nlineNum = ((int[])bdSourceCrossline.DataSource)[bdSourceCrossline.Position];
this.ttxtCrosslineNum.Text = nlineNum.ToString();
if (bEnableDraw)
{
ShowCrossline(nlineNum);
}
}
public void SetRange(int inlineMin, int inlineMax, int xlineMin, int xlineMax)
{
this.inlineMin = inlineMin;
this.inlineMax = inlineMax;
this.crosslineMin = xlineMin;
this.crosslineMax = xlineMax;
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}";
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}";
bEnableDraw = true;
}
/// <summary>
/// 重置并绑定inline、crossline
/// </summary>
private void ResetLineRange()
{
int nDelay = 0;
// Inline、Crossline范围
Segy.GetLineRange(ref inlineMin, ref inlineMax, ref crosslineMin, ref crosslineMax, ref nDelay);
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 ShowCrossline(int lineNum)
{
SectionType = 2;
// 另一方向线的线号
List<int> lstInlineNum = new List<int>();
List<int> lstXlineNum = new List<int>();
int nOtherNum = -1;
int nCount = Segy.Traces.Count;
List<int> lstTraceIndex = new List<int>();
for (int i = 0; i < nCount; i++)
{
if (Segy.Traces[i].Header.CrosslineNumber == lineNum)
{
lstTraceIndex.Add(i);
if (nOtherNum != Segy.Traces[i].Header.InlineNumber)
{
nOtherNum = Segy.Traces[i].Header.InlineNumber;
lstInlineNum.Add(nOtherNum);
}
}
}
for (int i = 0; i < lstInlineNum.Count; i++)
{
lstXlineNum.Add(lineNum);
}
int nDelay = -Segy.Traces[lstTraceIndex[0]].Header.Delay;
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;
section.Coordinate.Y = nDelay;
this.DrawAxis(0, nDelay, lstInlineNum, lstXlineNum, (Segy.Header.SampleNumber-1) * Segy.Header.SampleInteral * 0.001);
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.Viewer.DeleteSeismicSection(sectionPtr);
sectionPtr = this.Viewer.AddSeismicSection(strProperty, btsValus);
btsValus = null;
// 添加其它数据
ShowSectionEvent?.Invoke(2, lineNum);
this.Viewer.Redraw();
}
else
{
//this.Viewer.ClearGeo();
sectionPtr = this.Viewer.AddSeismicSection(strProperty, btsValus);
btsValus = null;
// 添加其它数据
ShowSectionEvent?.Invoke(2, lineNum);
this.Viewer.ViewAll();
}
SectionNum = lineNum;
}
private void ShowInline(int inlineNum)
{
SectionType = 1;
// 另一方向线的线号
List<int> lstInlineNum = new List<int>();
List<int> lstXlineNum = new List<int>();
int nOtherNum = -1;
int nCount = Segy.Traces.Count;
List<int> lstTraceIndex = new List<int>();
for (int i = 0; i < nCount; i++)
{
if (Segy.Traces[i].Header.InlineNumber == inlineNum)
{
lstTraceIndex.Add(i);
if (nOtherNum != Segy.Traces[i].Header.CrosslineNumber)
{
nOtherNum = Segy.Traces[i].Header.CrosslineNumber;
lstXlineNum.Add(nOtherNum);
}
}
}
for(int i=0;i< lstXlineNum.Count; i++)
{
lstInlineNum.Add(inlineNum);
}
int nDelay = -Segy.Traces[lstTraceIndex[0]].Header.Delay;
this.startInline = Segy.Traces[lstTraceIndex[0]].Header.InlineNumber;
this.startXline = Segy.Traces[lstTraceIndex[0]].Header.CrosslineNumber;
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;
section.Coordinate.Y = nDelay;
// 绘制坐标信息
this.DrawAxis(0, nDelay, lstInlineNum, lstXlineNum, (Segy.Header.SampleNumber-1) * Segy.Header.SampleInteral * 0.001);
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++)
{
// 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];
}
}
if (sectionPtr > 0)
{
this.Viewer.DeleteSeismicSection(sectionPtr);
sectionPtr = this.Viewer.AddSeismicSection(strProperty, btsValus);
btsValus = null;
ShowSectionEvent?.Invoke(1, inlineNum);
this.Viewer.Redraw();
}
else
{
sectionPtr = this.Viewer.AddSeismicSection(strProperty, btsValus);
btsValus = null;
ShowSectionEvent?.Invoke(1, inlineNum);
this.Viewer.ViewAll();
}
SectionNum = inlineNum;
}
/// <summary>
/// 绘制坐标信息
/// </summary>
/// <param name="v1"></param>
/// <param name="nDelay"></param>
/// <param name="lstInlineNum"></param>
/// <param name="lstXlineNum"></param>
/// <param name="v2"></param>
private void DrawAxis(int offsetX, int offsetY, List<int> lstInlineNum, List<int> lstXlineNum, double deepth)
{
this.Viewer.DeleteLayer(new List<string> { "坐标" });
this.Viewer.DeleteLayer(new List<string> { "坐标\\Axis" });
this.Viewer.DeleteLayer(new List<string> { "坐标\\Scale" });
this.Viewer.DeleteLayer(new List<string> { "坐标\\ScaleX" });
this.Viewer.DeleteLayer(new List<string> { "坐标\\ScaleY" });
this.Viewer.DeleteLayer(new List<string> { "坐标\\Grid" });
string strLayerName = string.Empty;
string strCurveName = string.Empty;
double dYMin = offsetY - deepth;
double dXMax = offsetX + (lstInlineNum.Count-1) * 10;
List<PointD> pts = new List<PointD>();
// 横向网格线
pts.Clear();
strLayerName = "坐标\\Grid";
List<DrawerPoint> lstScaleY = new List<DrawerPoint>();
int nStepY = 100;
double dCooY = offsetY;
int nDeepth = (int)(Math.Floor(dCooY / nStepY));
while (nDeepth * nStepY > dYMin)
{
double dScaleY = nDeepth * nStepY;
// 横向网格线
pts.Add(new PointD(offsetX, dScaleY));
pts.Add(new PointD(dXMax, dScaleY));
this.AddDrawCurve(strLayerName, $"{dScaleY}", pts);
pts.Clear();
// 纵向刻度线
pts.Add(new PointD(offsetX - 5, dScaleY));
pts.Add(new PointD(offsetX, dScaleY));
this.AddDrawCurve("坐标\\Scale", $"{dScaleY}", pts);
pts.Clear();
// 纵向标注
DrawerPoint drawPt = new DrawerPoint();
drawPt.X = offsetX;
drawPt.Y = dScaleY;
drawPt.Name = $"{dScaleY}";
lstScaleY.Add(drawPt);
nDeepth -= 1;
}
// 横向网格线
pts.Clear();
pts.Add(new PointD(offsetX, dYMin));
pts.Add(new PointD(dXMax, dYMin));
this.AddDrawCurve(strLayerName, $"{nDeepth * nStepY}", pts);
// 纵向刻度线
pts.Clear();
pts.Add(new PointD(offsetX - 5, dYMin));
pts.Add(new PointD(offsetX, dYMin));
this.AddDrawCurve("坐标\\Scale", $"{nDeepth * nStepY}", pts);
// 纵向标注
DrawerPoint drawPtY = new DrawerPoint();
drawPtY.X = offsetX;
drawPtY.Y = nDeepth * nStepY;
drawPtY.Name = $"{nDeepth * nStepY}";
lstScaleY.Add(drawPtY);
strLayerName = "坐标\\ScaleY";
this.Viewer.AddDrawPoints(strLayerName, lstScaleY);
DrawerPointStyle styleScaleY = new DrawerPointStyle();
styleScaleY.SymbolSize = new SizeF(0, 0);
PointText ptTextY = new PointText();
ptTextY.Height = 12;
ptTextY.Width = ptTextY.Height * 0.4;
ptTextY.DeltY = 0;
ptTextY.DeltX = -6;
ptTextY.Style = (int)TextStyleFlags.alignLeft | (int)TextStyleFlags.alignCenterV;
styleScaleY.Text = ptTextY;
styleScaleY.ForeColor = Color.FromArgb(0, 0, 0);
Viewer.SetLayerHowtoViewPoint(strLayerName, styleScaleY.SerialXml(), true);
// 设置网格虚线样式
strLayerName = "坐标\\Grid";
CurveProperty curveProperty = new CurveProperty();
curveProperty.VirtureValues = "4 4";
curveProperty.LineColor = Color.FromArgb(127, 127, 127);
this.Viewer.CreateLayerCurveStyle(strLayerName, curveProperty.StyleType, curveProperty.SerialXml());
// 横向坐标轴和刻度线
strLayerName = "坐标\\Scale";
//this.Viewer.DeleteLayer(new List<string> { strLayerName });
List<DrawerPoint> lstScaleX = new List<DrawerPoint>();
DrawerPoint ptLableInline = new DrawerPoint();
ptLableInline.X = offsetX - 30;
ptLableInline.Y = offsetY;
ptLableInline.Name = "Xline";
lstScaleX.Add(ptLableInline);
DrawerPoint ptLableXline = new DrawerPoint();
ptLableXline.X = offsetX - 30;
ptLableXline.Y = offsetY + 8;
ptLableXline.Name = "Inline";
lstScaleX.Add(ptLableXline);
pts.Clear();
double dScaleX = 0;
for (int i = 0; i < lstInlineNum.Count; i++)
{
if (SectionType == 2)
{
dScaleX = offsetX + (lstInlineNum[i] - lstInlineNum[0]) * 10;
}
else
{
dScaleX = offsetX + (lstXlineNum[i] - lstXlineNum[0]) * 10;
}
pts.Add(new PointD(dScaleX, offsetY));
// 横向刻度线
if (i % 10 == 0 || i == lstInlineNum.Count - 1)
{
List<PointD> ptsScale = new List<PointD>();
ptsScale.Add(new PointD(dScaleX, offsetY + 5));
ptsScale.Add(new PointD(dScaleX, offsetY));
this.AddDrawCurve(strLayerName, $"X{i}", ptsScale);
DrawerPoint ptScaleXline = new DrawerPoint();
ptScaleXline.X = dScaleX;
ptScaleXline.Y = offsetY;
ptScaleXline.Name = lstXlineNum[i].ToString();
lstScaleX.Add(ptScaleXline);
DrawerPoint ptScaleInline = new DrawerPoint();
ptScaleInline.X = dScaleX;
ptScaleInline.Y = offsetY+8;
ptScaleInline.Name = lstInlineNum[i].ToString();
lstScaleX.Add(ptScaleInline);
}
}
strLayerName = "坐标\\Axis";
strCurveName = "AxisX";
this.AddDrawCurve(strLayerName, strCurveName, pts);
strLayerName = "坐标\\ScaleX";
this.Viewer.AddDrawPoints(strLayerName, lstScaleX);
DrawerPointStyle styleScale = new DrawerPointStyle();
styleScale.SymbolSize = new SizeF(0, 0);
PointText ptText = new PointText();
ptText.Height = 12;
ptText.Width = ptText.Height*0.4;
ptText.DeltY = 4;
ptText.Style = (int)TextStyleFlags.alignCenterH | (int)TextStyleFlags.alignTop;
styleScale.Text = ptText;
styleScale.ForeColor = Color.FromArgb(0, 0, 0);
Viewer.SetLayerHowtoViewPoint(strLayerName, styleScale.SerialXml(), true);
strLayerName = "坐标\\Axis";
// 纵向坐标
pts.Clear();
pts.Add(new PointD(offsetX, offsetY));
pts.Add(new PointD(offsetX, dYMin));
strCurveName = "AxisY";
this.AddDrawCurve(strLayerName, strCurveName, pts);
// 绘制刻度线
LayerStatus status = LayerStatus.VIEW_NOT_EDIT;
this.Viewer.SetLayerState( "坐标", status);
this.Viewer.SetLayerState("坐标\\Axis", status);
this.Viewer.SetLayerState("坐标\\Scale", status);
this.Viewer.SetLayerState("坐标\\ScaleX", status);
this.Viewer.SetLayerState("坐标\\ScaleY", status);
this.Viewer.SetLayerState("坐标\\Grid", status);
}
}
}