Newer
Older
GHFX_REFACTOR / NewFunction / FrmCityServerLineAnalysis.cs
wxn on 9 Nov 2016 21 KB 冗余代码整理
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;

namespace Cyberpipe
{
    public partial class FrmCityServerLineAnalysis : Office2007Form
    {
        GSOGlobeControl globeControl1;

        List<string> m_pipelineNames = new List<string>();

        public FrmCityServerLineAnalysis(GSOGlobeControl globeControl, List<string> pipelineNames)
        {
            InitializeComponent();

            globeControl1 = globeControl;
            m_pipelineNames = pipelineNames;
        }

        private void FrmHorizontalDistanceAnalysis_Load(object sender, EventArgs e)
        {
            List<string> listCitySevenLine = new List<string>();
            listCitySevenLine.Add("城市红线");
            listCitySevenLine.Add("城市橙线");
            listCitySevenLine.Add("城市黄线");
            listCitySevenLine.Add("城市绿线");
            listCitySevenLine.Add("城市蓝线");
            listCitySevenLine.Add("城市紫线");
            listCitySevenLine.Add("城市黑线");

            listBoxCitySevenLine.DataSource = listCitySevenLine;

            if (globeControl1 != null)
            {
                for (int i = 0; i < m_pipelineNames.Count; i++)
                {
                    listBoxPolylineLayers.Items.Add(m_pipelineNames[i]);
                }
            }
        }
        //全区域管线审核
        private void buttonAllPolygon_Click(object sender, EventArgs e)
        {
            if (listBoxCitySevenLine.SelectedItems == null || listBoxCitySevenLine.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选中一个或者多个七线图层!", "提示");
                return;
            }
            if (listBoxPolylineLayers.SelectedItems == null || listBoxPolylineLayers.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选中一个或者多个管线图层!", "提示");
                return;
            }
            if (textBoxRedLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市红线的容限值!", "提示");
                return;
            }
            if (textBoxOrangeLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市橙线的容限值!", "提示");
                return;
            }
            if (textBoxYellowLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市黄线的容限值!", "提示");
                return;
            }
            if (textBoxGreenLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市绿线的容限值!", "提示");
                return;
            }
            if (textBoxBlueLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市蓝线的容限值!", "提示");
                return;
            }
            if (textBoxPurpleLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市紫线的容限值!", "提示");
                return;
            }
            if (textBoxBlackLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市黑线的容限值!", "提示");
                return;
            }
            double redAllowDistance = 0.0;
            double orangeAllowDistance = 0.0;
            double yellowAllowDistance = 0.0;
            double greenAllowDistance = 0.0;
            double blueAllowDistance = 0.0;
            double purpleAllowDistance = 0.0;
            double blackAllowDistance = 0.0;
            if (double.TryParse(textBoxRedLine.Text.Trim(), out redAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市红线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxOrangeLine.Text.Trim(), out orangeAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市橙线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxYellowLine.Text.Trim(), out yellowAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市黄线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxGreenLine.Text.Trim(), out greenAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市绿线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxBlueLine.Text.Trim(), out blueAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市蓝线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxPurpleLine.Text.Trim(), out purpleAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市紫线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxBlackLine.Text.Trim(), out blackAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市黑线的容限值!", "提示");
                return;
            }

            dataGridView1.Rows.Clear();

            for (int i = 0; i < listBoxPolylineLayers.SelectedItems.Count; i++)
            {
                GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(listBoxPolylineLayers.SelectedItems[i].ToString().Trim());
                if (layer != null)
                {
                    for (int j = 0; j < layer.GetAllFeatures().Length; j++)
                    {
                        GSOFeature feature = layer.GetAt(j);
                        if (feature != null && feature.Geometry != null && feature.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                        {
                            for (int m = 0; m < listBoxCitySevenLine.SelectedItems.Count; m++)
                            {
                                GSOLayer layerSevenLine = globeControl1.Globe.Layers.GetLayerByCaption(listBoxCitySevenLine.SelectedItems[m].ToString().Trim());
                                if (layerSevenLine.Bounds.Center.X == 0 && layerSevenLine.Bounds.Center.Y == 0)
                                {
                                    MessageBox.Show("请绘制并选择相应的城市七线", "提示");
                                    return;
                                }
                                if (layerSevenLine != null)
                                {
                                    double allowDistance = 0.0;
                                    switch (layerSevenLine.Caption)
                                    {
                                        case "城市红线":
                                            allowDistance = redAllowDistance;
                                            break;
                                        case "城市橙线":
                                            allowDistance = orangeAllowDistance;
                                            break;
                                        case "城市黄线":
                                            allowDistance = yellowAllowDistance;
                                            break;
                                        case "城市绿线":
                                            allowDistance = greenAllowDistance;
                                            break;
                                        case "城市蓝线":
                                            allowDistance = blueAllowDistance;
                                            break;
                                        case "城市紫线":
                                            allowDistance = purpleAllowDistance;
                                            break;
                                        case "城市黑线":
                                            allowDistance = blackAllowDistance;
                                            break;
                                    }
                                    GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D;


                                    GSOGeoPolygon3D polygon = line.CreateBuffer(allowDistance, true, 5, false, false);
                                    if (polygon != null)
                                    {
                                        GSOFeatures features = layerSevenLine.FindFeaturesInPolygon(polygon, false);
                                        if (features == null)
                                        {
                                            continue;
                                        }
                                        for (int n = 0; n < features.Length; n++)
                                        {
                                            GSOFeature featureSevenLine = features[n];
                                            if (featureSevenLine != null)
                                            {
                                                int rowIndex = dataGridView1.Rows.Add();
                                                dataGridView1.Rows[rowIndex].Tag = featureSevenLine;
                                                dataGridView1.Rows[rowIndex].Cells[0].Value = feature.Name;
                                                dataGridView1.Rows[rowIndex].Cells[1].Value = layer.Caption;
                                                dataGridView1.Rows[rowIndex].Cells[2].Value = featureSevenLine.Name;
                                                dataGridView1.Rows[rowIndex].Cells[3].Value = layerSevenLine.Caption;
                                            }
                                        }
                                    }


                                }
                            }
                        }
                    }
                }
            }
        }

        //绘制区域管线审核
        bool isDrawPolygonAnalysis;
        Dictionary<string, double> dicAllowDistance = new Dictionary<string, double>();
        private void buttonDrawPolygon_Click(object sender, EventArgs e)
        {
            if (listBoxCitySevenLine.SelectedItems == null || listBoxCitySevenLine.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选中一个或者多个七线图层!", "提示");
                return;
            }
            if (listBoxPolylineLayers.SelectedItems == null || listBoxPolylineLayers.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选中一个或者多个管线图层!", "提示");
                return;
            }
            if (textBoxRedLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市红线的容限值!", "提示");
                return;
            }
            if (textBoxOrangeLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市橙线的容限值!", "提示");
                return;
            }
            if (textBoxYellowLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市黄线的容限值!", "提示");
                return;
            }
            if (textBoxGreenLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市绿线的容限值!", "提示");
                return;
            }
            if (textBoxBlueLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市蓝线的容限值!", "提示");
                return;
            }
            if (textBoxPurpleLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市紫线的容限值!", "提示");
                return;
            }
            if (textBoxBlackLine.Text.Trim() == "")
            {
                MessageBox.Show("请输入城市黑线的容限值!", "提示");
                return;
            }
            double redAllowDistance = 0.0;
            double orangeAllowDistance = 0.0;
            double yellowAllowDistance = 0.0;
            double greenAllowDistance = 0.0;
            double blueAllowDistance = 0.0;
            double purpleAllowDistance = 0.0;
            double blackAllowDistance = 0.0;
            if (double.TryParse(textBoxRedLine.Text.Trim(), out redAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市红线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxOrangeLine.Text.Trim(), out orangeAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市橙线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxYellowLine.Text.Trim(), out yellowAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市黄线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxGreenLine.Text.Trim(), out greenAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市绿线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxBlueLine.Text.Trim(), out blueAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市蓝线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxPurpleLine.Text.Trim(), out purpleAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市紫线的容限值!", "提示");
                return;
            }
            if (double.TryParse(textBoxBlackLine.Text.Trim(), out blackAllowDistance) == false)
            {
                MessageBox.Show("请输入正确的城市黑线的容限值!", "提示");
                return;
            }
            dicAllowDistance.Clear();
            dicAllowDistance.Add("城市红线", redAllowDistance);
            dicAllowDistance.Add("城市橙线", orangeAllowDistance);
            dicAllowDistance.Add("城市黄线", yellowAllowDistance);
            dicAllowDistance.Add("城市绿线", greenAllowDistance);
            dicAllowDistance.Add("城市蓝线", blueAllowDistance);
            dicAllowDistance.Add("城市紫线", purpleAllowDistance);
            dicAllowDistance.Add("城市黑线", blackAllowDistance);

            globeControl1.TrackPolygonEndEvent += globeControl1_TrackPolygonEnd;
            globeControl1.Globe.Action = EnumAction3D.TrackPolygon;
            isDrawPolygonAnalysis = true;
        }

        void globeControl1_TrackPolygonEnd(object sender, TrackPolygonEndEventArgs e)
        {
            if (e.Polygon != null && isDrawPolygonAnalysis)
            {
                dataGridView1.Rows.Clear();
                for (int i = 0; i < listBoxPolylineLayers.SelectedItems.Count; i++)
                {
                    GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(listBoxPolylineLayers.SelectedItems[i].ToString().Trim());
                    if (layer != null)
                    {
                        GSOFeatures fs = layer.FindFeaturesInPolygon(e.Polygon, false);
                        for (int j = 0; j < fs.Length; j++)
                        {
                            GSOFeature feature = fs[j];
                            if (feature != null && feature.Geometry != null && feature.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                            {
                                for (int m = 0; m < listBoxCitySevenLine.SelectedItems.Count; m++)
                                {
                                    GSOLayer layerSevenLine = globeControl1.Globe.Layers.GetLayerByCaption(listBoxCitySevenLine.SelectedItems[m].ToString().Trim());
                                    if (layerSevenLine != null)
                                    {
                                        double allowDistance = dicAllowDistance[layerSevenLine.Caption];
                                        GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D;
                                        GSOGeoPolygon3D polygon = line.CreateBuffer(allowDistance, true, 5, false, false);
                                        if (polygon != null)
                                        {
                                            GSOFeatures features = layerSevenLine.FindFeaturesInPolygon(polygon, false);
                                            if (features == null)
                                            {
                                                continue;
                                            }
                                            for (int n = 0; n < features.Length; n++)
                                            {
                                                GSOFeature featureSevenLine = features[n];
                                                if (featureSevenLine != null)
                                                {
                                                    int rowIndex = dataGridView1.Rows.Add();
                                                    dataGridView1.Rows[rowIndex].Tag = featureSevenLine;
                                                    dataGridView1.Rows[rowIndex].Cells[0].Value = feature.Name;
                                                    dataGridView1.Rows[rowIndex].Cells[1].Value = layer.Caption;
                                                    dataGridView1.Rows[rowIndex].Cells[2].Value = featureSevenLine.Name;
                                                    dataGridView1.Rows[rowIndex].Cells[3].Value = layerSevenLine.Caption;
                                                }
                                            }
                                        }

                                        //GSOFeatures features = layerSevenLine.GetAllFeatures();
                                        //for (int n = 0; n < features.Length; n++)
                                        //{
                                        //    GSOFeature featureSevenLine = features[n];
                                        //    if (featureSevenLine != null && featureSevenLine.Geometry != null && featureSevenLine.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                                        //    {
                                        //        GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D;
                                        //        GSOGeoPolyline3D lineSevenLine = feature.Geometry as GSOGeoPolyline3D;
                                        //        GSOPipeLineStyle3D styleLine = line.Style as GSOPipeLineStyle3D;
                                        //        GSOPipeLineStyle3D styleSevenLine = lineSevenLine.Style as GSOPipeLineStyle3D;
                                        //        if (styleLine == null || styleSevenLine == null)
                                        //        {
                                        //            continue;
                                        //        }

                                        //        GSOPoint3d pntIntersect = new GSOPoint3d();
                                        //        GSOPoint3d pntIntersectSevenLine = new GSOPoint3d();
                                        //        GSOPoint3d pntProIntersect = new GSOPoint3d();
                                        //        GSOPoint3d pntProIntersectSevenLine = new GSOPoint3d();

                                        //        double distance = globeControl1.Globe.Analysis3D.ComputeHorizonDistance(line, lineSevenLine, out pntIntersect, out pntIntersectSevenLine, out pntProIntersect, out pntProIntersectSevenLine, false);
                                        //        if (distance > -1)
                                        //        {
                                        //            distance = Math.Abs(pntIntersect.Z - pntIntersectSevenLine.Z) - styleLine.Radius - styleSevenLine.Radius;
                                        //            if (distance < 0)
                                        //            {
                                        //                dt.Rows.Add(new object[] { feature.Name, layer.Caption, features[n].Name, layerSevenLine.Caption });
                                        //            }
                                        //        }
                                        //    }
                                        //}
                                    }
                                }
                            }
                        }
                    }
                }

                globeControl1.TrackPolygonEndEvent -= globeControl1_TrackPolygonEnd;
                isDrawPolygonAnalysis = false;
            }
        }

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) //有错
        {
            if (e.Button == MouseButtons.Left && e.RowIndex > -1)
            {
                int rowIndex = e.RowIndex;
                GSOFeature feature = dataGridView1.Rows[rowIndex].Tag as GSOFeature;
                if (feature != null && feature.Geometry != null && feature.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                {
                    GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D;
                    double lineLength = line.GetSpaceLength(true, 6378137.0);
                    GSOGeoPolyline3D middleLine = line.GetSegment(0, lineLength / 2);
                    if (middleLine != null)
                    {
                        GSOPoint3d point3d = middleLine[middleLine.PartCount - 1][middleLine[middleLine.PartCount - 1].Count - 1];
                        globeControl1.Globe.JumpToPosition(point3d, EnumAltitudeMode.RelativeToGround, 5);
                    }
                }
            }
        }
    }
}