Newer
Older
GHFX_REFACTOR / FrmCompareFeature.cs
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 bool InvalParam()
        {
            if (srcFeature == null || dscFeature == null)
            {
                MessageBox.Show("请选择要对比的管段!", "提示");
                return false;
            }
            if (srcFeature.Geometry.Type != dscFeature.Geometry.Type)
            {
                MessageBox.Show("请选择同种类型图层!");
                return  false;
            }
            if (srcFeature.Geometry.Type != dscFeature.Geometry.Type ||
                srcFeature.Geometry.Type != EnumGeometryType.GeoPolyline3D)
                return false;
            return true;
        }

        private void buttonAnalysis_Click(object sender, EventArgs e)
        {
            bool isvalid = InvalParam();
            if (!isvalid) return;
            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;
            if (srcLine == null) return;

            GSOGeoPolyline3D dscLine = dscFeature.Geometry as GSOGeoPolyline3D;
            if (dscLine == null) return;
            double srcLineLength = srcLine.GetSpaceLength(false, 6378137);
            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();
        }


        void globeControl1_MouseClick(object sender, MouseEventArgs e)
        {

            if (globeControl1.Globe.SelectedObject == null) return;
            FeatureTools.ClearAllFeatureHighLight(globeControl1);
            FeatureTools.ClearAllFeatureHighLight(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;
            FeatureTools.ClearAllFeatureHighLight(globeControl1);
            FeatureTools.ClearAllFeatureHighLight(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;
        }

    }
}