Example #1
0
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            if (PickResult.Type == gviObjectType.gviObjectLabel)
            {
                ILabelPickResult tlpr = PickResult as ILabelPickResult;
                gviObjectType    type = tlpr.Type;
                ILabel           fl   = tlpr.Label;
                MessageBox.Show("拾取到" + type + "类型,内容为" + fl.Text);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderModelPoint)
            {
                IRenderModelPointPickResult tlpr = PickResult as IRenderModelPointPickResult;
                gviObjectType     type           = tlpr.Type;
                IRenderModelPoint fl             = tlpr.ModelPoint;
                MessageBox.Show("拾取到" + type + "类型,模型名称为" + fl.ModelName);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPoint)
            {
                IRenderPointPickResult tlpr = PickResult as IRenderPointPickResult;
                gviObjectType          type = tlpr.Type;
                IRenderPoint           fl   = tlpr.Point;
                MessageBox.Show("拾取到" + type + "类型,大小为" + fl.Symbol.Size);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPolyline)
            {
                IRenderPolylinePickResult tlpr = PickResult as IRenderPolylinePickResult;
                gviObjectType             type = tlpr.Type;
                IRenderPolyline           fl   = tlpr.Polyline;
                MessageBox.Show("拾取到" + type + "类型,GUID为" + fl.Guid);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPolygon)
            {
                IRenderPolygonPickResult tlpr = PickResult as IRenderPolygonPickResult;
                gviObjectType            type = tlpr.Type;
                IRenderPolygon           fl   = tlpr.Polygon;
                MessageBox.Show("拾取到" + type + "类型,GUID为" + fl.Guid);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPOI)
            {
                IRenderPOIPickResult tlpr = PickResult as IRenderPOIPickResult;
                gviObjectType        type = tlpr.Type;
                IRenderPOI           fl   = tlpr.POI;
                MessageBox.Show("拾取到" + type + "类型,名称为" + ((IPOI)fl.GetFdeGeometry()).Name);
            }
            else if (PickResult.Type == gviObjectType.gviObjectTerrainRegularPolygon)
            {
                ITerrainRegularPolygonPickResult regPolygonPick = PickResult as ITerrainRegularPolygonPickResult;
                gviObjectType          type       = regPolygonPick.Type;
                ITerrainRegularPolygon regPolygon = regPolygonPick.TerrainRegularPolygon;
                MessageBox.Show("拾取到" + type + "类型,geometryCount为" + regPolygon.GetFdeGeometry().GeometryType);
            }
            else if (PickResult.Type == gviObjectType.gviObjectTerrainArrow)
            {
                ITerrainArrowPickResult arrowPickResult = PickResult as ITerrainArrowPickResult;
                gviObjectType           type            = arrowPickResult.Type;
                ITerrainArrow           arrow           = arrowPickResult.TerrainArrow;
                MessageBox.Show("拾取到" + type + "类型,geometryType" + arrow.GetFdeGeometry().GeometryType);
            }
            else if (PickResult.Type == gviObjectType.gviObjectReferencePlane)
            {
                switch (this.toolStripComboBoxObjectManager.Text)
                {
                case "CreateLabel":
                {
                    label                     = this.axRenderControl1.ObjectManager.CreateLabel(rootId);
                    label.Text                = "我是testlabel";
                    label.Position            = IntersectPoint;
                    textSymbol                = new TextSymbol();
                    textAttribute             = new TextAttribute();
                    textAttribute.TextColor   = System.Drawing.Color.Yellow;
                    textAttribute.TextSize    = 20;
                    textAttribute.Underline   = true;
                    textAttribute.Font        = "楷体";
                    textSymbol.TextAttribute  = textAttribute;
                    textSymbol.VerticalOffset = 10;
                    textSymbol.DrawLine       = true;
                    textSymbol.MarginColor    = System.Drawing.Color.Yellow;
                    label.TextSymbol          = textSymbol;
                    this.axRenderControl1.Camera.FlyToObject(label.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderModelPoint":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    string tmpOSGPath = (strMediaPath + @"\osg\Buildings\Apartment\Apartment.osg");
                    fde_modelpoint = gfactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint,
                                                             gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    fde_modelpoint.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_modelpoint.ModelName = tmpOSGPath;
                    rmodelpoint = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fde_modelpoint, null, rootId);
                    rmodelpoint.MaxVisibleDistance = double.MaxValue;
                    rmodelpoint.MinVisiblePixels   = 0;
                    rmodelpoint.ShowOutline        = checkShowOutline.Checked;
                    IEulerAngle angle = new EulerAngle();
                    angle.Set(0, -20, 0);
                    this.axRenderControl1.Camera.LookAt(IntersectPoint.Position, 100, angle);
                }
                break;

                case "CreateRenderPoint":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_point = (IPoint)gfactory.CreateGeometry(gviGeometryType.gviGeometryPoint,
                                                                gviVertexAttribute.gviVertexAttributeZ);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);

                    pointSymbol           = new SimplePointSymbol();
                    pointSymbol.FillColor = System.Drawing.Color.Red;
                    pointSymbol.Size      = 10;
                    rpoint             = this.axRenderControl1.ObjectManager.CreateRenderPoint(fde_point, pointSymbol, rootId);
                    rpoint.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpoint.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderPolyline":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_polyline = (IPolyline)gfactory.CreateGeometry(gviGeometryType.gviGeometryPolyline,
                                                                      gviVertexAttribute.gviVertexAttributeZ);
                    fde_point = (IPoint)gfactory.CreateGeometry(gviGeometryType.gviGeometryPoint,
                                                                gviVertexAttribute.gviVertexAttributeZ);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polyline.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 20, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polyline.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 20, IntersectPoint.Y + 20, IntersectPoint.Z, 0, 0);
                    fde_polyline.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 20, IntersectPoint.Y + 20, IntersectPoint.Z + 20, 0, 0);
                    fde_polyline.AppendPoint(fde_point);

                    lineSymbol            = new CurveSymbol();
                    lineSymbol.Color      = System.Drawing.Color.Red;     // 紫红色
                    rpolyline             = this.axRenderControl1.ObjectManager.CreateRenderPolyline(fde_polyline, lineSymbol, rootId);
                    rpolyline.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpolyline.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderPolygon":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_polygon = (IPolygon)gfactory.CreateGeometry(gviGeometryType.gviGeometryPolygon,
                                                                    gviVertexAttribute.gviVertexAttributeZ);

                    fde_point = (IPoint)gfactory.CreateGeometry(gviGeometryType.gviGeometryPoint,
                                                                gviVertexAttribute.gviVertexAttributeZ);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 10, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 10, IntersectPoint.Y + 10, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y + 10, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);

                    surfaceSymbol        = new SurfaceSymbol();
                    surfaceSymbol.Color  = System.Drawing.Color.Blue;         // 蓝色
                    rpolygon             = this.axRenderControl1.ObjectManager.CreateRenderPolygon(fde_polygon, surfaceSymbol, rootId);
                    rpolygon.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpolygon.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderPOI":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_poi = (IPOI)gfactory.CreateGeometry(gviGeometryType.gviGeometryPOI, gviVertexAttribute.gviVertexAttributeZ);
                    fde_poi.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_poi.ImageName = "#(1)";
                    fde_poi.Name      = (++poiCount).ToString();
                    fde_poi.Size      = 50;
                    rpoi             = this.axRenderControl1.ObjectManager.CreateRenderPOI(fde_poi);
                    rpoi.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpoi.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateFixedBillboard":
                {
                    TextAttribute ta = new TextAttribute();
                    ta.TextSize  = 10;
                    ta.TextColor = System.Drawing.Color.Yellow;
                    IImage image     = null;
                    IModel model     = null;
                    string imageName = "";
                    this.axRenderControl1.Utility.CreateFixedBillboard("I'm fixed billboard!", ta, 50, 100, true, out model, out image, out imageName);
                    this.axRenderControl1.ObjectManager.AddModel("fixedModel", model);
                    this.axRenderControl1.ObjectManager.AddImage(imageName, image);

                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }
                    fde_modelpoint = gfactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint,
                                                             gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    fde_modelpoint.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_modelpoint.ModelName = "fixedModel";
                    rmodelpoint = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fde_modelpoint, null, rootId);
                    rmodelpoint.MaxVisibleDistance = double.MaxValue;
                    rmodelpoint.MinVisiblePixels   = 0;
                    rmodelpoint.ShowOutline        = checkShowOutline.Checked;
                    IEulerAngle angle = new EulerAngle();
                    angle.Set(0, -20, 0);
                    this.axRenderControl1.Camera.LookAt(IntersectPoint.Position, 100, angle);
                }
                break;

                case "CreateRegularPolygon":
                {
                    IPosition pos = new Position();
                    pos.X        = IntersectPoint.X;
                    pos.Y        = IntersectPoint.Y;
                    pos.Altitude = IntersectPoint.Z;
                    ITerrainRegularPolygon regPolygon = this.axRenderControl1.ObjectManager.CreateRegularPolygon(pos, 10, 10, System.Drawing.Color.Red, System.Drawing.Color.White, rootId);
                    this.axRenderControl1.Camera.FlyToObject(regPolygon.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateArrow":
                {
                    IPosition pos = new Position();
                    pos.X        = IntersectPoint.X;
                    pos.Y        = IntersectPoint.Y;
                    pos.Altitude = IntersectPoint.Z;
                    ITerrainArrow regArrow = this.axRenderControl1.ObjectManager.CreateArrow(pos, 30, 4, System.Drawing.Color.Red, System.Drawing.Color.White, rootId);
                    this.axRenderControl1.Camera.FlyToObject(regArrow.Guid, gviActionCode.gviActionFlyTo);
                }
                break;
                }
            }
        }
Example #2
0
        private void ShowFlowDirect(IFeatureLayerPickResult pr)
        {
            if (pr == null)
            {
                return;
            }
            IRowBuffer row    = null;
            IFdeCursor cursor = null;

            try
            {
                int fid = pr.FeatureId;
                DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(pr.FeatureLayer.FeatureClassId.ToString());
                if (dffc == null)
                {
                    return;
                }
                IFeatureClass fc  = dffc.GetFeatureClass();
                FacilityClass fac = dffc.GetFacilityClass();
                if (fc == null || fac == null || fac.Name != "PipeLine")
                {
                    return;
                }
                DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("FlowDirect");
                if (fi == null)
                {
                    return;
                }
                IFieldInfoCollection fiCol = fc.GetFields();
                int index = fiCol.IndexOf(fi.Name);
                if (index == -1)
                {
                    return;
                }
                int indexShape = fiCol.IndexOf("Shape");

                IQueryFilter filter = new QueryFilter();
                filter.WhereClause = "oid=" + fid;
                cursor             = fc.Search(filter, false);
                row = cursor.NextRow();
                if (row == null)
                {
                    return;
                }

                IPolyline line = null;
                if (indexShape != -1 && !row.IsNull(indexShape))
                {
                    object obj = row.GetValue(indexShape);
                    if (obj != null && obj is IPolyline)
                    {
                        line = obj as IPolyline;
                    }
                }
                string flowDirectValue = "0";
                int    type            = 1;// 1表示具有流向字段;2表示从高到低
                if (!row.IsNull(index))
                {
                    flowDirectValue = row.GetValue(index).ToString();
                    if (flowDirectValue != "0" && flowDirectValue != "1")
                    {
                        flowDirectValue = "0";
                    }
                    type = 1;
                }
                else if (line != null)
                {
                    if (line.StartPoint.Z > line.EndPoint.Z)
                    {
                        flowDirectValue = "0";
                    }
                    else
                    {
                        flowDirectValue = "1";
                    }
                    type = 2;
                }
                if (line == null)
                {
                    return;
                }

                if (this._isAuth)
                {
                    #region 流向渲染1
                    FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString());
                    if (reg == null)
                    {
                        return;
                    }
                    TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode);
                    if (tc == null)
                    {
                        return;
                    }
                    FacStyleClass        style          = null;
                    List <FacStyleClass> facilityStyles = FacilityInfoService.GetFacStyleByFacClassCode(reg.FacClassCode);
                    if ((facilityStyles != null) && (facilityStyles.Count > 0))
                    {
                        style = facilityStyles[0];
                    }
                    PipeLineFac       plfac = new PipeLineFac(reg, style, row, tc);
                    IRenderModelPoint rmp   = null;
                    DrawGeometry.Ocx = DF3DApplication.Application.Current3DMapControl;
                    plfac.ShowFlowDirection(int.Parse(flowDirectValue), out rmp);
                    if (rmp != null)
                    {
                        this._listRender.Add(rmp.Guid);
                    }
                    #endregion
                }
                else
                {
                    #region 流向渲染2
                    IEulerAngle angle    = DF3DApplication.Application.Current3DMapControl.Camera.GetAimingAngles2(line.StartPoint, line.EndPoint);
                    double      dia      = 0.0;
                    string      diaField = fac.GetFieldInfoNameBySystemName("Diameter");
                    int         indexDia = fiCol.IndexOf(diaField);
                    if (indexDia != -1 && !row.IsNull(indexDia))
                    {
                        string diaStr    = row.GetValue(indexDia).ToString();
                        int    indexDia1 = diaStr.ToString().IndexOf('*');
                        if (indexDia1 != -1)
                        {
                            var dia1 = int.Parse(diaStr.ToString().Substring(0, indexDia1));
                            var dia2 = int.Parse(diaStr.ToString().Substring(indexDia1 + 1, diaStr.ToString().Length));
                            dia = ((dia1 > dia2) ? dia1 : dia2) * 0.001;
                        }
                        else
                        {
                            dia = int.Parse(diaStr) * 0.001;
                        }
                    }
                    List <IPoint> points = new List <IPoint>();
                    if (flowDirectValue == "0")
                    {
                        for (int i = 0; i < line.PointCount; i++)
                        {
                            IPoint pt = line.GetPoint(i);
                            pt.Z += dia / 2;
                            points.Add(pt);
                        }
                    }
                    else if (flowDirectValue == "1")
                    {
                        for (int i = line.PointCount - 1; i >= 0; i--)
                        {
                            IPoint pt = line.GetPoint(i);
                            pt.Z += dia / 2;
                            points.Add(pt);
                        }
                    }
                    for (int i = 0; i < points.Count - 1; i++)
                    {
                        IPoint pt1 = points[i];
                        var    pt2 = points[i + 1];

                        double delt = 0;
                        double _rate, _distance;
                        if (!(Math.Abs(dia) < 0.0000001))
                        {
                            delt = 2.0 * dia;
                            if (dia <= 0.5 && dia >= 0.3)
                            {
                                _rate     = 7 * dia;
                                _distance = 3 * dia / 0.4;
                            }
                            else if (dia < 0.3 && dia > 0.1)
                            {
                                _rate     = 12 * dia;
                                _distance = 6 * dia / 0.4;
                            }
                            else if (dia <= 0.1)
                            {
                                _rate     = 22 * dia;
                                _distance = 9 * dia / 0.4;
                            }
                            else
                            {
                                _rate     = 3.5 * dia;
                                _distance = 1.5 * dia / 0.4;
                            }
                        }
                        else
                        {
                            _rate     = 2.0;
                            _distance = 3.0;
                            //z = maxZ + 0.2;
                            delt = 0.2;
                        }
                        List <IPoint> list = DisPerseLine(pt1, pt2, _distance);
                        if (list.Count < 2)
                        {
                            return;
                        }
                        List <IPoint>    list1   = new List <IPoint>();
                        IGeometryFactory geoFact = new GeometryFactoryClass();
                        for (int j = 0; j < list.Count - 1; j++)
                        {
                            IPoint p = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            p.X = (list[j].X + list[j + 1].X) / 2;
                            p.Y = (list[j].Y + list[j + 1].Y) / 2;
                            p.Z = (list[j].Z + list[j + 1].Z) / 2;
                            list1.Add(p);
                        }

                        for (var m = 0; m < list1.Count; m++)
                        {
                            IPosition pos = new PositionClass();
                            pos.X            = list1[m].X;
                            pos.Y            = list1[m].Y;
                            pos.Altitude     = list1[m].Z + delt;
                            pos.AltitudeType = gviAltitudeType.gviAltitudeTerrainAbsolute;
                            pos.Heading      = angle.Heading;
                            pos.Tilt         = angle.Tilt;
                            pos.Roll         = angle.Roll;
                            UInt32 color;
                            if (type == 1)
                            {
                                color = 0xFFFFFF00;
                            }
                            else
                            {
                                color = 0xFF00FFFF;
                            }
                            ITerrainArrow rArrow = DF3DApplication.Application.Current3DMapControl.ObjectManager.CreateArrow(pos, 0.8 * _rate, 3, color, color, DF3DApplication.Application.Current3DMapControl.ProjectTree.RootID);
                            this._listRender.Add(rArrow.Guid);
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
        }