Newer
Older
EMS_REFACTOR / FrmHDMAnalysis3.cs
nn-203 on 26 Jul 2017 10 KB first commit
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;

namespace Cyberpipe
{
    public partial class FrmHDMAnalysis3 : Office2007Form
    {
        static DataTable table = new DataTable();
        GSOGlobeControl globeControl1;
        EnumTrackPolylineEndMode mode;

        Dictionary<GSOFeature, HDMCoordinate> hdmDic;

        public FrmHDMAnalysis3(Dictionary<GSOFeature, HDMCoordinate> hdmDic,
            GSOGlobeControl globeControl, EnumTrackPolylineEndMode mode)
        {
            InitializeComponent();

            this.hdmDic = hdmDic;
            globeControl1 = globeControl;
            this.mode = mode;
        }
      
        private void initControls()
        {
            chart1.Series["管线"].ChartType = SeriesChartType.Point;
            chart1.Series["管线"]["DrawingStyle"] = "Cylinder";
            chart1.Series["管线"].MarkerStyle = MarkerStyle.Circle; //点的类型     
            chart1.Series["管线"].MarkerBorderColor = Color.Black;  //点的边框颜色
            //chart1.ChartAreas[0].AxisX.Minimum = 0;              //x轴的起始点大小
            chart1.ChartAreas[0].AxisY.Maximum = 0;               //y轴的最大值
            chart1.ChartAreas[0].AxisX.Title = "距离 (米)";
            chart1.ChartAreas[0].AxisY.Title = "埋深 (米)";
            chart1.ChartAreas[0].AxisY2.Title = "高程 (米)";
            chart1.Series["管线"].Points.Clear();
            //chart1.ChartAreas[0].AxisX.Maximum = Math.Round(line.GetSpaceLength(true, 6378137), 2);

            table.Columns.Add("编号", typeof(string));
            table.Columns.Add("管线类型", typeof(string));
            table.Columns.Add("管线编码", typeof(string));
            table.Columns.Add("管径_毫米", typeof(string));
            table.Columns.Add("材质", typeof(string));
            table.Columns.Add("管线埋深", typeof(string));

            if (mode == EnumTrackPolylineEndMode.DLDM_Analysis)
            {
                pictureBox1.Visible = true;
            }
            else
            {
                pictureBox1.Visible = false;
            }
        }

        private void draw()
        {
            int i = 0;
            foreach (KeyValuePair<GSOFeature, HDMCoordinate> kvp in hdmDic)
            {
                GSOFeature feature = kvp.Key;
                HDMCoordinate coor = kvp.Value;

                chart1.Series["管线"].Points.AddXY(coor.Dis, coor.Z);//绑定数据

                string pipeType = feature.Dataset == null ? "" : feature.Dataset.Caption;
                string number = Convert.ToString(i + 1);
                string material = feature.GetFieldAsString("材质");
                string diameter = feature.GetFieldAsString("管径_毫米");
                table.Rows.Add(number, pipeType, feature.Name, diameter, material, Convert.ToDecimal(coor.Z).ToString("f2"));
                chart1.Series["管线"].Points[i].LegendText = number;
                if (feature.Geometry.Style.GetType() == typeof(GSOPipeLineStyle3D))
                {
                    GSOPipeLineStyle3D style = (GSOPipeLineStyle3D)feature.Geometry.Style;
                    chart1.Series["管线"].Points[i].MarkerBorderColor = style.LineColor;     //点的填充色
                }
                else
                {
                    chart1.Series["管线"].Points[i].MarkerBorderColor = Color.Black;
                }

                chart1.Series["管线"].Points[i].MarkerBorderWidth = 3;        //边框的宽度
                chart1.Series["管线"].Points[i].MarkerColor = Color.Transparent;
                chart1.Series["管线"].Points[i].MarkerSize = Convert.ToInt32(Math.Floor((feature.GetFieldAsDouble("管径_毫米") / 0.35 + 
                chart1.Series["管线"].Points[i].MarkerBorderWidth) / 100.0));
                i++;
            }
        }
       
        /// <summary>
        /// 图表的鼠标单击事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chart1_MouseClick(object sender, MouseEventArgs e)
        {
            HitTestResult result = chart1.HitTest(e.X, e.Y, true); 
            if (result.PointIndex >= 0)
            {
                DataPoint p = (DataPoint)result.Object;
                if (p == null)
                {
                    return;
                }
                string number = p.LegendText;
                int indexInTableRows = 0;
                bool isInt = int.TryParse(number, out indexInTableRows);
                if (isInt)
                {
                    DataRow row = table.Rows[indexInTableRows - 1];
                    string htmlCode = "<html><head><style>#hor-minimalist-b " +
                        "{-moz-background-clip:border;" +
                                "-moz-background-inline-policy:continuous;" +
                                    "-moz-background-origin:padding;" +
                                    "background:#FFFFFF none repeat scroll 0 0;" +
                                    "border-collapse:collapse;" +
                                    "font-family:'Lucida Sans Unicode','Lucida Grande',Sans-Serif;" +
                                   " font-size:12px;" +
                                   " margin:10px;" +
                                   " text-align:left;" +
                                   " width:80%;" +
                                   " }" +
                                   " #hor-minimalist-b th {" +
                                   " border-bottom:2px solid #6678B1;" +
                                   " color:#003399;" +
                                   " font-size:12px;" +
                                "font-weight:normal;" +
                                  "  padding:10px 8px;" +
                                   " }" +
                                  "  #hor-minimalist-b td {" +
                                   " border-bottom:1px solid #CCCCCC;" +
                                   " font-size:12px;" +
                                   " color:#666699;" +
                                "padding:6px 8px;}" +
                                "#hor-minimalist-b tbody tr:hover td {" +
                                "color:#000099;}" +
                                "</style></head>" +
                        "<body style='border:none;' ><table align='center' summary='Employee Pay Sheet' id='hor-minimalist-b'><thead><tr><th scope='col'>管线类型</th><th scope='col'>管线编码</th><th scope='col'>管径_毫米</th>" +
                                        "<th scope='col'>材质</th><th scope='col'>管线埋深</th></tr></thead>" +
                                        "<tbody><tr><td>" + row[1] +
                                        "</td><td>" + row[2] +
                                        "</td><td>" + row[3] +
                                        "</td><td>" + row[4] +
                                        "</td><td>" + row[5] +
                                        "</td></tr></tbody></table></body></html>";
                    webBrowser1.DocumentText = htmlCode;
                }
            }
        }

        /// <summary>
        /// 图表的鼠标移动事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chart1_MouseMove(object sender, MouseEventArgs e)
        {
            HitTestResult result = chart1.HitTest(e.X, e.Y, true);
            Cursor = result.PointIndex >= 0 ? Cursors.Hand : Cursors.Default;
        }
        /// <summary>
        /// 导出CAD按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExportCAD_Click(object sender, EventArgs e)
        {
            //globeControl1.Globe.MemoryLayer.RemoveAllFeature();
           GSOLayer layerTemp = globeControl1.Globe.Layers.
               Add(Application.StartupPath + "\\tempLgdExport.lgd");
           if (layerTemp == null)
               return;

            layerTemp.RemoveAllFeature();
            foreach (KeyValuePair<GSOFeature, HDMCoordinate> kvp in hdmDic)
            {
                GSOFeature feature = kvp.Key;
                HDMCoordinate coor = kvp.Value;
                if (feature.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                {
                    GSOPipeLineStyle3D style = feature.Geometry.Style as GSOPipeLineStyle3D;
                    double r = style.Radius;
                    addPoint(coor.Dis, coor.Z, r, layerTemp);
                }
            }
            layerTemp.Dataset.ImportProjectionRefFromProj4("");
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "*.dxf|*.dxf";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                layerTemp.SaveAs(dlg.FileName);
                MessageBox.Show("导出CAD完成!", "提示");
            }
            layerTemp.RemoveAllFeature();
        }

        private void addPoint(double a, double b, double r, GSOLayer layerTemp)
        {
            GSOPoint3ds pnts = new GSOPoint3ds();
            for (int i = 0; i <= 64; i++)
            {
                double x = a + r * Math.Cos(i * 5.625 * Math.PI / 180);
                double y = b - r * Math.Sin(i * 5.625 * Math.PI / 180);
                GSOPoint2d pt2d = new GSOPoint2d(x, y);
                GSOPoint3d pnt = new GSOPoint3d();
                pnt.X = pt2d.X;
                pnt.Y = pt2d.Y;
                pnt.Z = 0;
                pnts.Add(pnt);
            }
            GSOGeoPolyline3D line = new GSOGeoPolyline3D();
            line.AddPart(pnts);
            GSOFeature f = new GSOFeature();
            f.Geometry = line;
            f.Geometry.LatLonCoord = false;
            f.Visible = false;
            layerTemp.AddFeature(f);            
        }

        private void FrmHDMAnalysis3_Load(object sender, EventArgs e)
        {
            table = new DataTable();
            initControls();
            draw();
        }
    }
}