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