DuanMian.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using SuperMap.Data;
  2. using SuperMap.Mapping;
  3. using System;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using WWPipeLine.MapBasic;
  8. using WWPipeLine.MapBasic.Conditions;
  9. namespace WWPipeLine.MapTools.Conditions.AnalystToolBar
  10. {
  11. public class DuanMian : BasicToolBar
  12. {
  13. private GeoLine m_TheLine;
  14. private Recordset m_Guanxian;
  15. public DuanMian() : base()
  16. {
  17. this.ConditionPanelName = "断面分析";
  18. InitializeComponent();
  19. toolStripLB.Text = "";
  20. var analystToolStripButton = new ToolStripButton()
  21. {
  22. DisplayStyle = ToolStripItemDisplayStyle.ImageAndText,
  23. Text = "开始分析",
  24. Name = "Analyst",
  25. AutoToolTip = false
  26. };
  27. base.ToolStrip.Items.Add(analystToolStripButton);
  28. analystToolStripButton.Click += AnalystToolStripButton_Click;
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. MapControl.Action = SuperMap.UI.Action.CreateLine;
  33. MapControl.Tracked += MapControl_Tracked;
  34. }
  35. private void AnalystToolStripButton_Click(object sender, EventArgs e)
  36. {
  37. if (m_TheLine is null || m_TheLine.PartCount != 1) { Sunny.UI.UIMessageTip.ShowError("构建查询结果失败,请重新绘制断面"); return; }
  38. DataTable dt = new DataTable { TableName = "DuanMianAnalystResult" };
  39. DataColumn dataColumn;
  40. dataColumn = new DataColumn { ColumnName = "dmgc", Caption = "地面高程(M)", DataType = Type.GetType("System.Double") }; dt.Columns.Add(dataColumn);
  41. dataColumn = new DataColumn { ColumnName = "gxgc", Caption = "管线高程(M)", DataType = Type.GetType("System.Double") }; dt.Columns.Add(dataColumn);
  42. dataColumn = new DataColumn { ColumnName = "gxms", Caption = "管线埋深(M)", DataType = Type.GetType("System.Double") }; dt.Columns.Add(dataColumn);
  43. dataColumn = new DataColumn { ColumnName = "gxgj", Caption = "管线管径(MM)", DataType = Type.GetType("System.Int32") }; dt.Columns.Add(dataColumn);
  44. dataColumn = new DataColumn { ColumnName = "gxSMID", Caption = "管线ID", /*DataType = Type.GetType("System.Int32")*/ }; dt.Columns.Add(dataColumn);
  45. dataColumn = new DataColumn { ColumnName = "jl", Caption = "距离(M)", DataType = Type.GetType("System.Double") }; dt.Columns.Add(dataColumn);
  46. Point2D m_TheLine_start = new Point2D(m_TheLine[0][0].X, m_TheLine[0][0].Y);
  47. Point2D m_TheLine_end = new Point2D(m_TheLine[0][1].X, m_TheLine[0][1].Y);
  48. Point2D m_Guanxian_start;
  49. Point2D m_Guanxian_end;
  50. Point2D m_JiaoDian;
  51. Point2D m_JiaoDian_temp = new Point2D(0, 0);
  52. double m_JiaoDian_jl = 0.0D;
  53. double m_Guanxian_start_ms = 0.0D;
  54. double m_Guanxian_end_ms = 0.0D;
  55. double m_JiaoDian_ms = 0.0D;
  56. double m_Guanxian_start_gc = 0.0D;
  57. double m_Guanxian_end_gc = 0.0D;
  58. double m_JiaoDian_gc = 0.0D;
  59. m_Guanxian.MoveFirst();
  60. DataRow dr;
  61. DataTable dsJSJDPT2Count;
  62. dt.Rows.Clear();
  63. while (!m_Guanxian.IsEOF)
  64. {
  65. dr = dt.NewRow();
  66. string sqlWhere = string.Format(" bsm ='{0}' OR bsm='{1}' ", m_Guanxian.GetFieldValue("qsdh"), m_Guanxian.GetFieldValue("zddh"));
  67. dsJSJDPT2Count = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, sqlWhere);
  68. if (dsJSJDPT2Count.Rows.Count == 2)//理论上只会查询到2条记录,分别是管线的起点物探号和终点物探号
  69. {
  70. //获得管线的 起点坐标 起始埋深 终点坐标 终点埋深 来自管点JSJDPT数据
  71. m_Guanxian_start = getPoint2D(dsJSJDPT2Count.Rows[0]["x"], dsJSJDPT2Count.Rows[0]["y"]);
  72. m_Guanxian_end = getPoint2D(dsJSJDPT2Count.Rows[1]["x"], dsJSJDPT2Count.Rows[1]["y"]);
  73. m_JiaoDian = Geometrist.IntersectLine(m_TheLine_start, m_TheLine_end, m_Guanxian_start, m_Guanxian_end, false);
  74. //开始计算交点的埋深数据
  75. Double.TryParse(dsJSJDPT2Count.Rows[0]["ms"].ToString(), out m_Guanxian_start_ms);
  76. Double.TryParse(dsJSJDPT2Count.Rows[1]["ms"].ToString(), out m_Guanxian_end_ms);
  77. m_JiaoDian_ms = ComsStatic.getPointHeight(m_Guanxian_start, m_Guanxian_start_ms, m_Guanxian_end, m_Guanxian_end_ms, m_JiaoDian);
  78. //开始计算交点的地面高程
  79. Double.TryParse(dsJSJDPT2Count.Rows[0]["dmgc"].ToString(), out m_Guanxian_start_gc);
  80. Double.TryParse(dsJSJDPT2Count.Rows[1]["dmgc"].ToString(), out m_Guanxian_end_gc);
  81. m_JiaoDian_gc = ComsStatic.getPointHeight(m_Guanxian_start, m_Guanxian_start_gc, m_Guanxian_end, m_Guanxian_end_gc, m_JiaoDian);
  82. //开始计算交点 之间的距离 第一个交点距离为0
  83. if (m_JiaoDian_temp.X != 0 && m_JiaoDian_temp.Y != 0)
  84. {
  85. GeoLine geoline = new GeoLine(new Point2Ds { m_JiaoDian, m_JiaoDian_temp });
  86. m_JiaoDian_jl = Math.Round(geoline.Length, 2);
  87. }
  88. m_JiaoDian_temp = m_JiaoDian;
  89. dr["dmgc"] = m_JiaoDian_gc;
  90. dr["gxgc"] = m_JiaoDian_gc - m_JiaoDian_ms;
  91. dr["gxms"] = m_JiaoDian_ms;
  92. dr["gxgj"] = m_Guanxian.GetFieldValue("gj");
  93. dr["jl"] = m_JiaoDian_jl;//m_JiaoDian_jl== 0 ? "" : m_JiaoDian_jl.ToString();
  94. dr["gxSMID"] = m_Guanxian.GetFieldValue("smid");
  95. dt.Rows.Add(dr);
  96. }
  97. m_Guanxian.MoveNext();
  98. }
  99. if (dt.Rows.Count == m_Guanxian.RecordCount && dt.Rows.Count > 0)
  100. {
  101. DuanMianAnalystResult duanMianAnalystResult = new DuanMianAnalystResult(dt);
  102. duanMianAnalystResult.ShowDialog();
  103. CloseToolBar();
  104. }
  105. //else if (dt.Rows.Count < m_Guanxian.RecordCount)
  106. //{
  107. // Sunny.UI.UIMessageTip.ShowWarning(string.Format("应生成{0}个横切面,共生成{1}个横切面,请首先检查管线的起始点号和终点点号数据!", m_Guanxian.RecordCount, dt.Rows.Count), 5000);
  108. // DuanMianAnalystResult duanMianAnalystResult = new DuanMianAnalystResult(dt);
  109. // duanMianAnalystResult.ShowDialog();
  110. // this.CloseToolBar();
  111. //}
  112. else
  113. {
  114. Sunny.UI.UIMessageTip.ShowError("构建查询结果失败,请重新绘制断面");
  115. }
  116. }
  117. private static Point2D getPoint2D(object x, object y)
  118. {
  119. return new Point2D(ComsStatic.StringToDouble(x), ComsStatic.StringToDouble(y));
  120. }
  121. private void MapControl_Tracked(object sender, SuperMap.UI.TrackedEventArgs e)
  122. {
  123. m_TheLine = e.Geometry.Clone() as GeoLine;
  124. if (m_TheLine is null) return;
  125. m_TheLine.Style = new GeoStyle { LineColor = Color.Red, LineWidth = 1 };
  126. MapControl.Map.TrackingLayer.Clear();
  127. MapControl.Map.TrackingLayer.Add(m_TheLine, "StartDraw");
  128. MapControl.Map.Refresh();
  129. m_Guanxian = ComsStatic.dvJSLK.Query(m_TheLine, 0, " qsdh is not null and zddh is not null ", CursorType.Static);
  130. if (m_Guanxian.RecordCount < 1)
  131. {
  132. Sunny.UI.UIMessageTip.ShowError("当前断面没有管线信息,请重新绘制断面!");
  133. }
  134. else
  135. {
  136. Sunny.UI.UIMessageTip.ShowOk("当前断面需要生成" + m_Guanxian.RecordCount + "个管线横切面");
  137. }
  138. }
  139. public override void AfterClose()
  140. {
  141. ComsStatic.RecordsetDispose(m_Guanxian);
  142. MapControl.Tracked -= MapControl_Tracked;
  143. base.AfterClose();
  144. }
  145. private void InitializeComponent()
  146. {
  147. this.SuspendLayout();
  148. //
  149. // DuanMian
  150. //
  151. this.Name = "DuanMian";
  152. this.ResumeLayout(false);
  153. this.PerformLayout();
  154. }
  155. }
  156. }