using System; using System.Collections.Generic; using System.Data; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; using Cyberpipe.PATM_Forms; using DevComponents.DotNetBar; using GeoScene.Data; using GeoScene.Globe; namespace Cyberpipe { public partial class FrmAllPipelineStatis : Office2007Form { static FrmAllPipelineStatis frm; private MainFrm.DataGridViewDelegate m_InitDataGridViewX1; private Dictionary<string, GSOFeatures> nameAndPipesMap; private Dictionary<string, double> nameAndLengthMap; private GSOGlobeControl globeControl1; private GSOGeoPolygon3D polygon; private List<string> pipeLayerNames; private static bool isSpaceQuery; public static void ShowForm(GSOGlobeControl ctl, GSOGeoPolygon3D polygon, MainFrm.DataGridViewDelegate InitDataGridViewX1,List<string> pipeLayerNames) { isSpaceQuery = true; if (frm == null) { frm = new FrmAllPipelineStatis(ctl,polygon, InitDataGridViewX1,pipeLayerNames); frm.Show(ctl.Parent); } else if (frm.WindowState == FormWindowState.Minimized) { frm.WindowState = FormWindowState.Normal; } } public FrmAllPipelineStatis(GSOGlobeControl ctl, GSOGeoPolygon3D polygon, MainFrm.DataGridViewDelegate InitDataGridViewX1, List<string> pipeLayerNames) { InitializeComponent(); Text = isSpaceQuery ? "空间查询" : "管线距离统计"; isSpaceQuery = false; globeControl1 = ctl; m_InitDataGridViewX1 = InitDataGridViewX1; this.polygon = polygon; this.pipeLayerNames = pipeLayerNames; } private void FrmAllPipelineStatis_Load(object sender, EventArgs e) { initPipesMap(polygon, out nameAndLengthMap, out nameAndPipesMap); drawChart(); } private void drawChart() { try { chartAllAreaPipeline.Series.Add("管线"); // Set axis title chartAllAreaPipeline.ChartAreas["ChartArea1"].AxisX.Title = "管线类型"; chartAllAreaPipeline.ChartAreas["ChartArea1"].AxisY.Title = "管线长度(米)"; chartAllAreaPipeline.ChartAreas["ChartArea1"].AxisX.Interval = 1; LabelStyle labeStyleAxisX = new LabelStyle(); labeStyleAxisX.Angle = -45; labeStyleAxisX.Enabled = true; chartAllAreaPipeline.ChartAreas["ChartArea1"].AxisX.LabelStyle = labeStyleAxisX; chartAllAreaPipeline.Series["管线"].ChartType = SeriesChartType.Column; chartAllAreaPipeline.Series["管线"]["DrawingStyle"] = "Cylinder"; chartAllAreaPipeline.Series["管线"].Points.DataBindXY(nameAndLengthMap.Keys, nameAndLengthMap.Values); for (int m = 0; m < nameAndLengthMap.Values.Count; m++) { if (chartAllAreaPipeline.Series["管线"].Points[m].YValues[0].ToString() != "0") { chartAllAreaPipeline.Series["管线"].Points[m].Label = chartAllAreaPipeline.Series[0].Points[m].YValues[0].ToString(); } string axisLabel = chartAllAreaPipeline.Series["管线"].Points[m].AxisLabel; chartAllAreaPipeline.Series["管线"].Points[m].AxisLabel = axisLabel.Substring(0, axisLabel.IndexOf("管线")); } } catch (Exception ex) { LogError.PublishError(ex); } } private void chartAllAreaPipeline_MouseClick(object sender, MouseEventArgs e) { HitTestResult result = chartAllAreaPipeline.HitTest(e.X, e.Y, true); int indexHit = result.PointIndex; if (indexHit < 0) return; //GSOFeatures fs = list[indexHit]; string pipetype = chartAllAreaPipeline.Series["管线"].Points[indexHit].AxisLabel+"管线"; GSOFeatures fs = nameAndPipesMap[pipetype]; string[] fields = ClassSearchAnalysis.getFields(pipetype, globeControl1); DataTable table = ClassSearchAnalysis.convertGSOFeatures2DataTable(fs, fields); if (table != null && table.Rows.Count > 0) { string strLable = "共有:" + Convert.ToString(table.Rows.Count) + "条记录" + " 管线里程:" + chartAllAreaPipeline.Series["管线"].Points[indexHit].YValues[0].ToString("0.00") + " 米"; m_InitDataGridViewX1(table, strLable, pipetype, true); } } private void chartAllAreaPipeline_MouseMove(object sender, MouseEventArgs e) { HitTestResult result = chartAllAreaPipeline.HitTest(e.X, e.Y, true); if (result.PointIndex >= 0) { Cursor = Cursors.Hand; } else { Cursor = Cursors.Default; } } private void FrmAllPipelineStatis_FormClosing(object sender, FormClosingEventArgs e) { frm = null; globeControl1.Globe.ClearAnalysis(); m_InitDataGridViewX1(null, "", "", false); } private void 导出统计专题图ToolStripMenuItem_Click(object sender, EventArgs e) { F_PATMTitle frm = new F_PATMTitle("S", chartAllAreaPipeline); frm.Show(); } /// <summary> /// 得到某图层区域内管线的map以及区域内管线长度的map /// </summary> /// <param name="polygon"></param> public void initPipesMap(GSOGeoPolygon3D polygon,out Dictionary<string,double> pipeAndLength,out Dictionary<string,GSOFeatures> nameAndPipeMap) { pipeAndLength = new Dictionary<string,double>(); nameAndPipeMap = new Dictionary<string, GSOFeatures>(); for (int i = 0; i < pipeLayerNames.Count; i++) { GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(pipeLayerNames[i]); double totalLength = 0.0; GSOFeatures fs = FeatureStatisticsService.GetLayerPipes(polygon, layer,out totalLength); if (fs == null) continue; nameAndPipeMap.Add(pipeLayerNames[i], fs); nameAndLengthMap.Add(pipeLayerNames[i],totalLength); } } } }