Ejemplo n.º 1
0
        /// <summary>
        /// 加载地下管道线
        /// </summary>
        public void LoadPipeLine3D()
        {
            try
            {
                m_SelectedGeoNetwork = new List <NetworkGeometry>();
                DatasetVector dataset_PipeLine  = m_workspace.Datasources["Pipeline3D"].Datasets["PipeLine3D"] as DatasetVector;
                DatasetVector dataset_PipePoint = m_workspace.Datasources["Pipeline3D"].Datasets["PipePoint3D"] as DatasetVector;

                Layer3DSettingVector setvetor = new Layer3DSettingVector();
                setvetor.Style.AltitudeMode = AltitudeMode.RelativeToGround;
                setvetor.Style.LineSymbolID = 962048;
                setvetor.Style.LineWidth    = 0.35;


                Layer3DDataset layer_ditie     = m_sceneControl.Scene.Layers.Add(dataset_PipeLine, setvetor, true, "PipeLine3D");
                Layer3DDataset layer_pipepoint = m_sceneControl.Scene.Layers.Add(dataset_PipePoint, setvetor, true, "PipePoint3D");

                if (dataset_PipePoint != null)
                {
                    Theme3DUnique theme = new Theme3DUnique();
                    theme.UniqueExpression = "SmID";
                    GeoStyle3D style3D = new GeoStyle3D();
                    style3D.AltitudeMode   = AltitudeMode.RelativeToGround;
                    style3D.Marker3DScaleX = 2.2;
                    style3D.Marker3DScaleY = 2.2;
                    style3D.Marker3DScaleZ = 2.2;

                    style3D.IsMarker3D = true;
                    theme.DefaultStyle = style3D;
                    Recordset rs = dataset_PipePoint.Query("", CursorType.Static);
                    rs.MoveFirst();
                    while (!rs.IsEOF)
                    {
                        Theme3DUniqueItem item = new Theme3DUniqueItem();
                        item.Unique = rs.GetID().ToString();
                        item.IsModellingStyleEnabled = true;
                        GeoStyle3D tempStyle = new GeoStyle3D(style3D);
                        PickNodeToLine(rs.GetID());
                        GeoPoint3D geoPoint3D = rs.GetGeometry() as GeoPoint3D;

                        List <Vector3d> arrVector3d = new List <Vector3d>();
                        for (Int32 curIndex = 0; curIndex < m_SelectedGeoNetwork.Count; curIndex++)
                        {
                            NetworkGeometry geoNetWork = m_SelectedGeoNetwork[curIndex];

                            if (geoNetWork != null)
                            {
                                Vector3d  vec     = new Vector3d();
                                GeoLine3D geoLine = geoNetWork.geometry as GeoLine3D;
                                if (geoNetWork.bIsIn)
                                {
                                    if (geoLine != null)
                                    {
                                        Point3Ds point3D  = geoLine[0];
                                        Point3D  pntTNode = point3D[1];
                                        Point3D  pntFNode = point3D[0];
                                        Vector3d vecTNode = SphericalToCartesian(pntTNode.X * DTOR, pntTNode.Y * DTOR, pntTNode.Z);
                                        Vector3d vecFNode = SphericalToCartesian(pntFNode.X * DTOR, pntFNode.Y * DTOR, pntFNode.Z);

                                        vec = new Vector3d(vecFNode.x - vecTNode.x, vecFNode.y - vecTNode.y, vecFNode.z - vecTNode.z);
                                        vec.Normalize();
                                    }
                                }
                                else
                                {
                                    if (geoLine != null)
                                    {
                                        Point3Ds point3D  = geoLine[0];
                                        Point3D  pntFNode = point3D[0];
                                        Point3D  pntTNode = point3D[1];
                                        Vector3d vecTNode = SphericalToCartesian(pntTNode.X * DTOR, pntTNode.Y * DTOR, pntTNode.Z);
                                        Vector3d vecFNode = SphericalToCartesian(pntFNode.X * DTOR, pntFNode.Y * DTOR, pntFNode.Z);

                                        vec = new Vector3d(vecTNode.x - vecFNode.x, vecTNode.y - vecFNode.y, vecTNode.z - vecFNode.z);
                                        vec.Normalize();
                                    }
                                }

                                vec = FromAngleAxis(vec, -geoPoint3D.X * DTOR, new Vector3d(0, 1, 0));
                                vec = FromAngleAxis(vec, geoPoint3D.Y * DTOR, new Vector3d(1, 0, 0));
                                vec.Normalize();
                                arrVector3d.Add(vec);
                            }
                        }

                        Vector3d vecX = new Vector3d();
                        Vector3d vecY = new Vector3d();
                        Vector3d vecZ = new Vector3d();
                        switch (m_SelectedGeoNetwork.Count)
                        {
                        case 2:    //弯头或阀门
                        {
                            if (arrVector3d.Count == 2)
                            {
                                vecX = arrVector3d[0].Normalize().Sub();
                                vecY = arrVector3d[1].Normalize();
                            }

                            double dAngle1_2 = vecX.DotProduct(vecY);
                            if (Math.Abs(dAngle1_2) < 0.3)
                            {
                                tempStyle.MarkerSymbolID = 54441;
                            }
                            else if (-1 < dAngle1_2 && dAngle1_2 < 0.7)
                            {
                                tempStyle.MarkerSymbolID = 54442;
                            }
                            else
                            {
                                vecY.z = 0;
                                Vector3d vec = new Vector3d(0, 0, 1);
                                vecX = vecY.CrossProduct(vec);
                                tempStyle.MarkerSymbolID = 54435;
                            }
                        }
                        break;

                        case 3:    //三通
                        {
                            tempStyle.MarkerSymbolID = 54437;

                            if (arrVector3d.Count == 3)
                            {
                                Vector3d vec1 = arrVector3d[0];
                                Vector3d vec2 = arrVector3d[1];
                                Vector3d vec3 = arrVector3d[2];

                                double dAngle1_2 = vec1.DotProduct(vec2);
                                double dAngle1_3 = vec1.DotProduct(vec3);
                                double dAngle2_3 = vec2.DotProduct(vec3);
                                if (Math.Abs(dAngle1_2) < 0.3)
                                {
                                    if (Math.Abs(dAngle1_3) < 0.3)
                                    {
                                        vecX = vec1.Normalize().Sub();
                                        vecY = vec2.Normalize();
                                    }
                                    else
                                    {
                                        vecX = vec2.Normalize().Sub();
                                        vecY = vec1.Normalize();
                                    }
                                }
                                else
                                {
                                    vecX = vec3.Normalize().Sub();
                                    vecY = vec1.Normalize();
                                }
                            }
                        }
                        break;

                        case 4:    //四通
                        {
                            tempStyle.MarkerSymbolID = 54438;
                            if (arrVector3d.Count == 4)
                            {
                                Vector3d vec1 = arrVector3d[0];
                                Vector3d vec2 = arrVector3d[1];
                                Vector3d vec3 = arrVector3d[2];

                                double dAngle1_2 = vec1.DotProduct(vec2);
                                double dAngle1_3 = vec1.DotProduct(vec3);

                                vecX = vec1;
                                if (Math.Abs(dAngle1_2) < 0.3)
                                {
                                    vecY = vec2.Normalize();
                                }
                                else
                                {
                                    vecY = vec3.Normalize();
                                }
                            }
                        }
                        break;

                        default:    //结点
                        {
                            tempStyle.MarkerSymbolID = 330101;
                        }
                        break;
                        }

                        if (m_SelectedGeoNetwork.Count > 1)
                        {
                            vecZ = vecX.CrossProduct(vecY);
                            vecZ.Normalize();

                            Vector3d vecRotate = ToEulerAnglesXYZ(vecX, vecY, vecZ);

                            tempStyle.Marker3DRotateX = -vecRotate.x * RTOD;
                            tempStyle.Marker3DRotateY = -vecRotate.y * RTOD;
                            tempStyle.Marker3DRotateZ = -vecRotate.z * RTOD;
                        }
                        item.Style = tempStyle;
                        theme.Add(item);
                        rs.MoveNext();
                    }
                    rs.Dispose();
                    Layer3D layer_theme = m_sceneControl.Scene.Layers.Add(dataset_PipePoint, theme, true, "underPipeLine3D");
                    layer_theme.IsSelectable = false;
                    if (m_sceneControl.Scene.Layers.Contains("PipePoint3D"))
                    {
                        m_sceneControl.Scene.Layers.Remove("PipePoint3D");
                    }

                    Camera camera = m_sceneControl.Scene.Camera;
                    camera.AltitudeMode = AltitudeMode.RelativeToGround;
                    camera.Altitude     = 26.978640816174448;
                    camera.Latitude     = 39.992608337161023;
                    camera.Longitude    = 116.3898561529368;
                    camera.Tilt         = 59.567389444384283;
                    camera.Heading      = 300.19323029928478;
                    m_sceneControl.Scene.Fly(camera, 1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void btn_Refresh_Click(object sender, EventArgs e)
        {
            Recordset objRt = null;

            try
            {
                Layer3DDataset layer = m_SceneControl.Scene.Layers[txt_Name.Text.Trim() + "@SpaceData"] as Layer3DDataset;
                GeoStyle3D     style = new GeoStyle3D
                {
                    LineSymbolID = Convert.ToInt32(btn_SelectColor.Tag)
                };

                Theme3DUnique theme = layer.Theme as Theme3DUnique;
                theme.UniqueExpression = "SmID";
                theme.DefaultStyle     = style;
                theme.Clear();

                m_lstItems.Clear();
                objRt = (m_Application.Workspace.Datasources["SpaceData"].Datasets[txt_Name.Text.Trim()] as DatasetVector).GetRecordset(false, CursorType.Static);
                objRt.MoveFirst();
                while (!objRt.IsEOF)
                {
                    Dictionary <string, object> dic = new Dictionary <string, object>
                    {
                        { "lon", objRt.GetFieldValue("Longitude") },
                        { "lat", objRt.GetFieldValue("Latitude") },
                        { "alt", objRt.GetFieldValue("Altitude") },
                        { "tilt", objRt.GetFieldValue("Tilt") },
                        { "heading", objRt.GetFieldValue("Heading") },
                        { "geo", objRt.GetGeometry() }
                    };
                    bool flag = false;
                    if (objRt.GetFieldValue("Longitude") == null)
                    {
                        flag = true;
                    }
                    Label lbl = new Label
                    {
                        Text = flag ? "第【" + objRt.GetID() + "】分段(无视角)" : "第【" + objRt.GetID() + "】分段",
                        Tag  = objRt.GetID()
                    };
                    m_lstItems.Add(lbl);

                    Theme3DUniqueItem item = new Theme3DUniqueItem
                    {
                        Caption   = objRt.GetID().ToString(),
                        Style     = style,
                        IsVisible = true,
                        Unique    = objRt.GetID().ToString()
                    };
                    theme.Add(item);

                    objRt.MoveNext();
                }

                lst_Items.DataSource    = null;
                lst_Items.DataSource    = m_lstItems;
                lst_Items.DisplayMember = "Text";
            }
            catch (Exception ex)
            {
                Log.OutputBox(ex);
            }
            finally
            {
                if (objRt != null)
                {
                    objRt.Close();
                    objRt.Dispose();
                }
            }
        }