Newer
Older
GHFX_REFACTOR / FrmCompareFeature.cs
xiaowei on 16 Nov 2016 7 KB 修改双屏分析
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;

namespace Cyberpipe
{
    public partial class FrmCompareFeature : Office2007Form
    {
        private GSOFeature srcFeature, dscFeature;
        private GSOGlobeControl globeControl1, globeControl2;
        GSOGeoPolygon3D resPolygon;
        static FrmCompareFeature frm;

        public static void ShowForm(GSOGlobeControl _globeControl1, GSOGlobeControl _globeControl2, int width)
        {
            if (frm == null)
            {
                frm = new FrmCompareFeature(_globeControl1, _globeControl2);
                frm.Location = new Point((width - frm.Width)/2, 50);
                frm.Show(_globeControl1.Parent);
            }
            else
            {
                if (frm.WindowState == FormWindowState.Minimized)
                    frm.WindowState = FormWindowState.Normal;
            }
        }

        public FrmCompareFeature(GSOGlobeControl _globeControl1, GSOGlobeControl _globeControl2)
        {
            globeControl1 = _globeControl1;
            globeControl2 = _globeControl2;
            InitializeComponent();

            globeControl1.Globe.Action = EnumAction3D.SelectObject;
            globeControl2.Globe.Action = EnumAction3D.SelectObject;

            globeControl1.MouseClick += globeControl1_MouseClick;
            globeControl2.MouseClick += globeControl2_MouseClick;
        }

        private void invalParam()
        {
            if (srcFeature == null || dscFeature == null)
            {
                MessageBox.Show("请选择要对比的管段!", "提示");
                return;
            }
            else if (srcFeature.Geometry.Type != dscFeature.Geometry.Type)
            {
                MessageBox.Show("请选择同种类型图层!");
                return;
            }
            else if (srcFeature.Geometry.Type != dscFeature.Geometry.Type ||
                     srcFeature.Geometry.Type != EnumGeometryType.GeoPolyline3D)
                return;
        }

        private void buttonAnalysis_Click(object sender, EventArgs e)
        {
            invalParam();

            dataGridViewX1.DataSource = null;
            lineFeatureCompare(srcFeature, dscFeature);
        }
        /// <summary>
        /// 分析两根管段的具体差异
        /// </summary>
        /// <param name="srcFeature"></param>
        /// <param name="dscFeature"></param>
        private void lineFeatureCompare(GSOFeature srcFeature, GSOFeature dscFeature)
        {
            GSOGeoPolyline3D srcLine = srcFeature.Geometry as GSOGeoPolyline3D;
            double srcLineLength = srcLine.GetSpaceLength(false, 6378137);

            GSOGeoPolyline3D dscLine = dscFeature.Geometry as GSOGeoPolyline3D;
            double dscLineLength = dscLine.GetSpaceLength(false, 6378137);

            double horizonDistance, verticalDistance;

            ClassDoubleScreenCompare.CalculateDistance(srcLine, dscLine, out horizonDistance, 
                out verticalDistance,globeControl1,globeControl2);

            DataTable dt = new DataTable();
            dt.Columns.Add("数据名称");
            dt.Columns.Add("图层名称");
            dt.Columns.Add("管段编号");
            dt.Columns.Add("管段长度");
            dt.Columns.Add("材质");
            dt.Columns.Add("水平距离/米");
            dt.Columns.Add("垂直距离/米");

            DataRow srcRow = dt.NewRow();
            srcRow[0] = "实测数据";
            srcRow[1] = srcFeature.Dataset.Caption;
            srcRow[2] = srcFeature.Name;
            srcRow[3] = srcLineLength.ToString("0.000");
            srcRow[4] = srcFeature.GetFieldAsString("材质");
            srcRow[5] = horizonDistance.ToString("0.000");
            srcRow[6] = verticalDistance.ToString("0.000");
            dt.Rows.Add(srcRow);

            DataRow dscRow = dt.NewRow();
            dscRow[0] = "施工数据";
            dscRow[1] = dscFeature.Dataset.Caption;
            dscRow[2] = dscFeature.Name;
            dscRow[3] = dscLineLength.ToString("0.000");
            dscRow[4] = dscFeature.GetFieldAsString("材质");
            dscRow[5] = horizonDistance.ToString("0.000");
            dscRow[6] = verticalDistance.ToString("0.000");
            dt.Rows.Add(dscRow);

            dataGridViewX1.DataSource = dt;
            globeControl1.Refresh();
            globeControl2.Refresh();
        }

        private void addPologyToGlobeControl(GSOGeoPolyline3D line, double bufferWidth)
        {
            globeControl1.Globe.MemoryLayer.RemoveAllFeature();
            globeControl2.Globe.MemoryLayer.RemoveAllFeature();

            GSOFeature new_feat = new GSOFeature();
            resPolygon = line.CreateBuffer(bufferWidth*2, true, 0, false, false);
            resPolygon.AltitudeMode = EnumAltitudeMode.RelativeToGround;
            new_feat.Geometry = resPolygon;

            globeControl1.Globe.MemoryLayer.AddFeature(new_feat);
            globeControl2.Globe.MemoryLayer.AddFeature(new_feat);

            globeControl1.Refresh();
            globeControl2.Refresh();
        }

        public static void clearFeatureHighLight(GSOGlobeControl glb)
        {
            for (int i = 0; i < glb.Globe.Layers.Count; i++)
            {
                GSOLayer layer = glb.Globe.Layers[i];
                if (!(layer is GSOFeatureLayer)) continue;
                GSOFeatures feats = layer.GetAllFeatures();
                for (int j = 0; j < feats.Length; j++)
                {
                    feats[j].HighLight = false;
                }
            }
        }

        void globeControl1_MouseClick(object sender, MouseEventArgs e)
        {

            if (globeControl1.Globe.SelectedObject == null) return;
            clearFeatureHighLight(globeControl1);
            clearFeatureHighLight(globeControl2);

            try
            {
                double bufferWidth = Convert.ToDouble(textBox1.Text);
                resPolygon = null;

                if (globeControl1.Globe.Action != EnumAction3D.SelectObject ||
                    globeControl1.Globe.SelectedObject == null)
                    return;
                GSOGeoPolyline3D line = globeControl1.Globe.SelectedObject.Geometry as GSOGeoPolyline3D;
                addPologyToGlobeControl(line, bufferWidth);

                srcFeature = globeControl1.Globe.SelectedObject;
                dscFeature = ClassDoubleScreenCompare.getSameFeatureFromOtherGlobe(srcFeature,
                    globeControl1,globeControl2,bufferWidth,resPolygon);

            }
            catch (Exception ex)
            {
                LogError.PublishError(ex);
            }
        }

        void globeControl2_MouseClick(object sender, MouseEventArgs e)
        {

            if (globeControl2.Globe.SelectedObject == null) return;
            clearFeatureHighLight(globeControl1);
            clearFeatureHighLight(globeControl2);

            try
            {
                double bufferWidth = Convert.ToDouble(textBox1.Text);
                resPolygon = null;

                if (globeControl2.Globe.Action != EnumAction3D.SelectObject ||
                    globeControl2.Globe.SelectedObject == null)
                    return;

                GSOGeoPolyline3D line = globeControl2.Globe.SelectedObject.Geometry as GSOGeoPolyline3D;
                addPologyToGlobeControl(line, bufferWidth);

                dscFeature = globeControl2.Globe.SelectedObject;
                srcFeature = ClassDoubleScreenCompare.getSameFeatureFromOtherGlobe(dscFeature,
                    globeControl1, globeControl2, bufferWidth, resPolygon);
            }
            catch (Exception ex)
            {
                LogError.PublishError(ex);
            }

        }

        private void FrmCompareFeature_FormClosing(object sender, FormClosingEventArgs e)
        {
            globeControl1.Globe.Action = EnumAction3D.ActionNull;
            globeControl2.Globe.Action = EnumAction3D.ActionNull;
            frm = null;
        }

    }
}