Exemplo n.º 1
0
        /// <summary>
        /// 获取与标注对应的关联设备
        /// </summary>
        /// <param name="pAnnoFeature"></param>
        /// <returns></returns>
        public static IFeature GetLinkedFeature(IAnnotationFeature2 pAnnoFeature)
        {
            // 方法一
            IFeature               pFeature      = (IFeature)pAnnoFeature;
            IFeatureClass          pfClass       = (IFeatureClass)pFeature.Class;
            IEnumRelationshipClass pEnumRelation =
                pfClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
            IRelationshipClass pRelationship = pEnumRelation.Next();

            if (pRelationship == null)
            {
                return(null);
            }

            ISet pSet = pRelationship.GetObjectsRelatedToObject(pFeature);

            if (pSet == null)
            {
                return(null);
            }

            object o = pSet.Next();

            if (o == null || !(o is IFeature))
            {
                return(null);
            }

            pFeature = (IFeature)o;
            return(pFeature);

            // 方法二

            /*
             * IFeature pFeature = (IFeature)pAnnoFeature;
             * IFeatureClass pfClass = (IFeatureClass)pFeature.Class;
             * IEnumRelationshipClass enumRelCls =
             *          pfClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
             * IRelationshipClass pRelationship = enumRelCls.Next();
             * if (pRelationship == null)
             *  return null;
             *
             * // 注记的FeatureClass
             * IFeatureClass pDestionClass = (IFeatureClass)pRelationship.OriginClass;
             * if (pDestionClass == null)
             *  return null;
             *
             * string foreignKey = pRelationship.DestinationPrimaryKey;
             * if (string.IsNullOrEmpty(foreignKey))
             *  return null;
             *
             * pFeature = pDestionClass.GetFeature(pAnnoFeature.LinkedFeatureID);
             * return pFeature;
             */
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取与要素设置的releationshipclss对应的标注要素

        /// </summary>
        /// <param name="pFeature">地图要素</param>
        /// <returns>标注要素</returns>
        public static IAnnotationFeature2 GetLinkedFeature(IFeature pFeature)
        {
            // 方法一
            IFeatureClass          pfClass       = (IFeatureClass)pFeature.Class;
            IEnumRelationshipClass pEnumRelation =
                pfClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
            IRelationshipClass pRelationship = pEnumRelation.Next();

            if (pRelationship == null)
            {
                return(null);
            }

            ISet pSet = pRelationship.GetObjectsRelatedToObject(pFeature);

            if (pSet == null)
            {
                return(null);
            }

            object o = pSet.Next();

            if (o == null || !(o is IAnnotationFeature2))
            {
                return(null);
            }

            IAnnotationFeature2 pAnnoFeature = (IAnnotationFeature2)o;

            return(pAnnoFeature);

            /*
             * 方法二
             *
             * // 注记的FeatureClass
             * IFeatureClass pDestionClass = (IFeatureClass)pRelationship.DestinationClass;
             * if (pDestionClass == null)
             *  return null;
             *
             * string foreignKey = pRelationship.OriginForeignKey;
             * if (string.IsNullOrEmpty(foreignKey))
             *  return null;
             *
             * string where = foreignKey + "='" + pFeature.OID + "'";
             * IAnnotationFeature2 pAnnoFeature =
             *  (IAnnotationFeature2)GeometryHelper.SearchFeature(pDestionClass, where);
             *
             * return pAnnoFeature;
             */
        }
Exemplo n.º 3
0
        /// <summary>
        /// 配置指定的注记要素
        /// </summary>
        /// <param name="feature">要修改的注记要素</param>
        /// <param name="pointGeometry">注记要素坐标</param>
        /// <param name="text">注记内容</param>
        /// <param name="fontSize"></param>
        /// <param name="verticalAlignment"></param>
        /// <param name="horizontalAlignment"></param>
        public void ConfigAnnotation(IFeature feature, IGeometry pointGeometry, string text, int fontSize, esriTextVerticalAlignment verticalAlignment, esriTextHorizontalAlignment horizontalAlignment)
        {
            IFontDisp font = new StdFontClass() as IFontDisp;

            font.Name = "宋体";
            font.Bold = true;

            IFormattedTextSymbol formattedTextSymbol = new TextSymbolClass();

            formattedTextSymbol.Font = font;
            formattedTextSymbol.Size = fontSize;
            formattedTextSymbol.VerticalAlignment   = verticalAlignment;
            formattedTextSymbol.HorizontalAlignment = horizontalAlignment;
            formattedTextSymbol.Angle            = 0;
            formattedTextSymbol.CharacterSpacing = 10;
            formattedTextSymbol.CharacterWidth   = 80;
            formattedTextSymbol.FlipAngle        = 90;
            formattedTextSymbol.Leading          = 0;
            formattedTextSymbol.WordSpacing      = 10;
            formattedTextSymbol.Text             = text;
            IColor rgb = new RgbColorClass();

            rgb.RGB = 15354;
            formattedTextSymbol.Color = rgb;


            ITextElement textElement = new TextElementClass();

            textElement.Symbol = formattedTextSymbol;
            textElement.Text   = text;
            IElement element = textElement as IElement;

            element.Geometry = pointGeometry;
            element.Geometry.Envelope.Width = 0.06;

            IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;

            try
            {
                // annotationFeature2.Annotation.Geometry = pointGeometry;

                annotationFeature2.Annotation = element;
                annotationFeature2.Status     = esriAnnotationStatus.esriAnnoStatusPlaced;

                feature.Store();
            }
            catch { }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 创建图形要素和标注要素之间的关联关系[使用前确保要素层与标注层,确实存在关联关系]
        /// </summary>
        /// <param name="OriginObject">图形要素</param>
        /// <param name="DestinationObject">标注要素</param>
        /// <returns></returns>
        public static IRelationship CreateRelationship(IFeature OriginObject,
                                                       IAnnotationFeature2 DestinationObject)
        {
            IFeatureClass          pfClass       = (IFeatureClass)OriginObject.Class;
            IEnumRelationshipClass pEnumRelation =
                pfClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
            IRelationshipClass pRelationship = pEnumRelation.Next();

            if (pRelationship == null)
            {
                return(null);
            }

            IRelationship pRelation = null;

            pRelation = pRelationship.CreateRelationship((IObject)OriginObject,
                                                         (IObject)DestinationObject);
            return(pRelation);
            //IObject OriginObject, IObject DestinationObject
        }
Exemplo n.º 5
0
        public static string SketchMouseDown(IPoint ipoint_0, IActiveView iactiveView_0, IFeatureLayer ifeatureLayer_0)
        {
            INewPolylineFeedback feedback;
            string str;
            INewPolygonFeedbackEx newPolygonFeedbackEx;
            object value;
            INewPolylineFeedback newPolylineFeedback;
            double num;

            string[] strArrays;
            double   num1;
            double   length;

            if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Line)
            {
                if (SketchToolAssist.Feedback != null)
                {
                    feedback = (INewPolylineFeedback)SketchToolAssist.Feedback;
                    feedback.AddPoint(SketchShareEx.m_pAnchorPoint);
                    object obj    = Missing.Value;
                    object value1 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj, ref value1);
                }
                else
                {
                    SketchShareEx.m_bInUse    = true;
                    SketchToolAssist.Feedback = new NewPolylineFeedback();
                    feedback = (INewPolylineFeedback)SketchToolAssist.Feedback;
                    SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay;
                    feedback.ChangeLineType((enumLineType)SketchToolAssist.LineType);
                    feedback.Start(SketchShareEx.m_pAnchorPoint);
                    SketchToolAssist.m_pPointColn = new Polyline();
                    object obj1   = Missing.Value;
                    object value2 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj1, ref value2);
                }
                str = "";
            }
            else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Fill)
            {
                if (SketchToolAssist.Feedback != null)
                {
                    newPolygonFeedbackEx = (INewPolygonFeedbackEx)SketchToolAssist.Feedback;
                    newPolygonFeedbackEx.AddPoint(SketchShareEx.m_pAnchorPoint);
                    object obj2   = Missing.Value;
                    object value3 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj2, ref value3);
                }
                else
                {
                    SketchShareEx.m_bInUse            = true;
                    SketchToolAssist.Feedback         = new NewPolygonFeedbackEx();
                    newPolygonFeedbackEx              = (INewPolygonFeedbackEx)SketchToolAssist.Feedback;
                    SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay;
                    newPolygonFeedbackEx.ChangeLineType((enumLineType)SketchToolAssist.LineType);
                    newPolygonFeedbackEx.Start(SketchShareEx.m_pAnchorPoint);
                    SketchToolAssist.m_pPointColn = new Polygon();
                    object obj3   = Missing.Value;
                    object value4 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj3, ref value4);
                }
                str = "";
            }
            else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Point)
            {
                SketchToolAssist.TempLine = SketchShareEx.m_pAnchorPoint;
                str = "";
            }
            else if (ifeatureLayer_0 == null)
            {
                str = "";
            }
            else if (ifeatureLayer_0.FeatureClass != null)
            {
                string str1 = "";
                string unit = "";
                SketchShareEx.IsFixDirection = false;
                SketchShareEx.IsFixLength    = false;
                if (SketchToolAssist.Feedback == null)
                {
                    if (ifeatureLayer_0.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        try
                        {
                            Editor.EditWorkspace.StartEditOperation();
                            IFeature feature    = ifeatureLayer_0.FeatureClass.CreateFeature();
                            int      num2       = 0;
                            object   fieldValue = Editor.CurrentEditTemplate.GetFieldValue("SymbolID");
                            if (fieldValue != null)
                            {
                                num2 = Convert.ToInt32(fieldValue);
                            }
                            ITextElement        textElement        = CreateFeatureTool.MakeTextElement("文本", 0, ipoint_0, num2);
                            IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;
                            annotationFeature2.LinkedFeatureID   = -1;
                            annotationFeature2.AnnotationClassID = 0;
                            annotationFeature2.Annotation        = textElement as IElement;
                            EditorEvent.NewRow(feature);
                            feature.Store();
                            Editor.EditWorkspace.StopEditOperation();
                            EditorEvent.AfterNewRow(feature);
                            iactiveView_0.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                            iactiveView_0.FocusMap.ClearSelection();
                            iactiveView_0.FocusMap.SelectFeature(ifeatureLayer_0, feature);
                            iactiveView_0.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                        }
                        catch (Exception exception)
                        {
                            Logger.Current.Error("", exception, "");
                        }
                    }
                    else if (ifeatureLayer_0.FeatureClass.FeatureType != esriFeatureType.esriFTDimension)
                    {
                        value = Missing.Value;
                        switch (ifeatureLayer_0.FeatureClass.ShapeType)
                        {
                        case esriGeometryType.esriGeometryPoint:
                        {
                            CreateFeatureTool.CreateFeature(ipoint_0, iactiveView_0, ifeatureLayer_0);
                            break;
                        }

                        case esriGeometryType.esriGeometryMultipoint:
                        {
                            SketchShareEx.m_bInUse    = true;
                            SketchToolAssist.Feedback = new NewMultiPointFeedback();
                            INewMultiPointFeedback newMultiPointFeedback =
                                (INewMultiPointFeedback)SketchToolAssist.Feedback;
                            SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay;
                            SketchShareEx.m_pPointCollection  = new Multipoint();
                            newMultiPointFeedback.Start(SketchShareEx.m_pPointCollection, ipoint_0);
                            break;
                        }

                        case esriGeometryType.esriGeometryPolyline:
                        {
                            SketchShareEx.m_bInUse            = true;
                            SketchToolAssist.Feedback         = new NewPolylineFeedback();
                            newPolylineFeedback               = (INewPolylineFeedback)SketchToolAssist.Feedback;
                            SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay;
                            newPolylineFeedback.Start(ipoint_0);
                            SketchShareEx.PointCount      = 1;
                            SketchShareEx.StartPoint      = ipoint_0;
                            SketchToolAssist.m_pPointColn = new Polyline();
                            SketchToolAssist.m_pPointColn.AddPoint(ipoint_0, ref value, ref value);
                            unit = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits);
                            num  = CommonHelper.measureLength(ipoint_0, 1, ref SketchShareEx.m_pLastPoint1,
                                                              ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength);
                            strArrays = new string[]
                            {
                                "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ",
                                SketchShareEx.m_totalLength.ToString("0.###"), unit
                            };
                            str1 = string.Concat(strArrays);
                            break;
                        }

                        case esriGeometryType.esriGeometryPolygon:
                        {
                            SketchShareEx.m_bInUse    = true;
                            SketchToolAssist.Feedback = new NewPolygonFeedbackEx();
                            INewPolygonFeedbackEx feedback1 = (INewPolygonFeedbackEx)SketchToolAssist.Feedback;
                            SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay;
                            feedback1.Start(ipoint_0);
                            SketchShareEx.PointCount      = 0;
                            SketchToolAssist.m_pPointColn = new Polygon();
                            SketchShareEx.StartPoint      = ipoint_0;
                            unit   = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits);
                            num1   = CommonHelper.measureArea(ipoint_0, 1, ref SketchToolAssist.m_pPointColn);
                            length = (SketchToolAssist.m_pPointColn as IPolygon).Length;
                            if (num1 <= 0)
                            {
                                break;
                            }
                            str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num1);
                            break;
                        }
                        }
                    }
                    else
                    {
                        SketchToolAssist.Feedback = new NewDimensionFeedback();
                        try
                        {
                            (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScale =
                                (iactiveView_0 as IMap).ReferenceScale;
                            (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScaleUnits =
                                (iactiveView_0 as IMap).MapUnits;
                        }
                        catch
                        {
                        }
                        SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay;
                        (SketchToolAssist.Feedback as INewDimensionFeedback).Start(ipoint_0);
                        SketchShareEx.PointCount = 1;
                    }
                }
                else if (SketchToolAssist.Feedback is INewDimensionFeedback)
                {
                    SketchShareEx.PointCount = SketchShareEx.PointCount + 1;
                    (SketchToolAssist.Feedback as INewDimensionFeedback).AddPoint(ipoint_0);
                    if (SketchShareEx.PointCount == 3)
                    {
                        IDimensionShape dimensionShape = (SketchToolAssist.Feedback as INewDimensionFeedback).Stop();
                        CreateFeatureTool.CreateDimensionFeature(dimensionShape,
                                                                 (SketchToolAssist.Feedback as INewDimensionFeedback).DimensionType, iactiveView_0,
                                                                 ifeatureLayer_0);
                    }
                }
                else if (SketchToolAssist.Feedback is INewMultiPointFeedback)
                {
                    value = Missing.Value;
                    SketchShareEx.m_pPointCollection.AddPoint(ipoint_0, ref value, ref value);
                    (SketchToolAssist.Feedback as INewMultiPointFeedback).Start(SketchShareEx.m_pPointCollection,
                                                                                ipoint_0);
                }
                else if (SketchToolAssist.Feedback is INewLineFeedback)
                {
                    newPolylineFeedback = (INewPolylineFeedback)SketchToolAssist.Feedback;
                    value = Missing.Value;
                    newPolylineFeedback.AddPoint(ipoint_0);
                    SketchToolAssist.m_pPointColn.AddPoint(ipoint_0, ref value, ref value);
                    SketchShareEx.PointCount = SketchShareEx.PointCount + 1;
                    unit = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits);
                    num  = CommonHelper.measureLength(ipoint_0, 1, ref SketchShareEx.m_pLastPoint1,
                                                      ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength);
                    strArrays = new string[]
                    {
                        "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ", SketchShareEx.m_totalLength.ToString("0.###"),
                        unit
                    };
                    str1 = string.Concat(strArrays);
                }
                else if (SketchToolAssist.Feedback is INewPolygonFeedback)
                {
                    ((INewPolygonFeedbackEx)SketchToolAssist.Feedback).AddPoint(ipoint_0);
                    SketchShareEx.PointCount = SketchShareEx.PointCount + 1;
                    unit   = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits);
                    num1   = CommonHelper.measureArea(ipoint_0, 1, ref SketchToolAssist.m_pPointColn);
                    length = (SketchToolAssist.m_pPointColn as IPolygon).Length;
                    if (num1 > 0)
                    {
                        str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num1);
                    }
                }
                if (SketchShareEx.LastPoint == null)
                {
                    SketchShareEx.LastPoint = new ESRI.ArcGIS.Geometry.Point();
                }
                SketchShareEx.LastPoint.PutCoords(ipoint_0.X, ipoint_0.Y);
                str = str1;
            }
            else
            {
                str = "";
            }
            return(str);
        }
Exemplo n.º 6
0
        public static string SketchMouseDown(IActiveView pActiveView, IFeatureLayer pFeatureLayer)
        {
            INewPolylineFeedback feedback;
            string str;
            INewPolygonFeedbackEx newPolygonFeedbackEx;
            object value;
            INewPolylineFeedback  newPolylineFeedback;
            INewPolygonFeedbackEx feedback1;
            double num;
            double length;

            if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Line)
            {
                if (SketchToolAssist.Feedback != null)
                {
                    feedback = (INewPolylineFeedback)SketchToolAssist.Feedback;
                    feedback.AddPoint(SketchToolAssist.m_pAnchorPoint);
                    object obj    = Missing.Value;
                    object value1 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj, ref value1);
                }
                else
                {
                    SketchToolAssist.m_bInUse = true;
                    SketchToolAssist.Feedback = new NewPolylineFeedback() as IDisplayFeedback2;
                    feedback = (INewPolylineFeedback)SketchToolAssist.Feedback;
                    SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay;
                    feedback.ChangeLineType(SketchToolAssist.LineType);
                    feedback.Start(SketchToolAssist.m_pAnchorPoint);
                    SketchToolAssist.m_pPointColn = new Polyline();
                    object obj1   = Missing.Value;
                    object value2 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj1, ref value2);
                }
                str = "";
            }
            else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Fill)
            {
                if (SketchToolAssist.Feedback != null)
                {
                    newPolygonFeedbackEx = (INewPolygonFeedbackEx)SketchToolAssist.Feedback;
                    newPolygonFeedbackEx.AddPoint(SketchToolAssist.m_pAnchorPoint);
                    object obj2   = Missing.Value;
                    object value3 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj2, ref value3);
                }
                else
                {
                    SketchToolAssist.m_bInUse         = true;
                    SketchToolAssist.Feedback         = new NewPolygonFeedbackEx();
                    newPolygonFeedbackEx              = (INewPolygonFeedbackEx)SketchToolAssist.Feedback;
                    SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay;
                    newPolygonFeedbackEx.ChangeLineType(SketchToolAssist.LineType);
                    newPolygonFeedbackEx.Start(SketchToolAssist.m_pAnchorPoint);
                    SketchToolAssist.m_pPointColn = new Polygon();
                    object obj3   = Missing.Value;
                    object value4 = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj3, ref value4);
                }
                str = "";
            }
            else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Point)
            {
                SketchToolAssist.TempLine = SketchToolAssist.m_pAnchorPoint;
                str = "";
            }
            else if (pFeatureLayer == null)
            {
                str = "";
            }
            else if (pFeatureLayer.FeatureClass != null)
            {
                string str1 = "";
                string unit = "";
                SketchToolAssist.IsFixDirection = false;
                SketchToolAssist.IsFixLength    = false;
                if (SketchToolAssist.Feedback == null)
                {
                    if (pFeatureLayer.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        try
                        {
                            Editor.EditWorkspace.StartEditOperation();
                            IFeature     feature     = pFeatureLayer.FeatureClass.CreateFeature();
                            ITextElement textElement = CreateFeatureTool.MakeTextElement("文本", 0,
                                                                                         SketchToolAssist.m_pAnchorPoint);
                            IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;
                            annotationFeature2.LinkedFeatureID   = -1;
                            annotationFeature2.AnnotationClassID = 0;
                            annotationFeature2.Annotation        = textElement as IElement;
                            EditorEvent.NewRow(feature);
                            feature.Store();
                            Editor.EditWorkspace.StopEditOperation();
                            EditorEvent.AfterNewRow(feature);
                            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                            pActiveView.FocusMap.ClearSelection();
                            pActiveView.FocusMap.SelectFeature(pFeatureLayer, feature);
                            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                        }
                        catch (Exception exception)
                        {
                            Logger.Current.Error("", exception, "");
                        }
                    }
                    else if (pFeatureLayer.FeatureClass.FeatureType != esriFeatureType.esriFTDimension)
                    {
                        value = Missing.Value;
                        switch (pFeatureLayer.FeatureClass.ShapeType)
                        {
                        case esriGeometryType.esriGeometryPoint:
                        {
                            CreateFeatureTool.CreateFeature(SketchToolAssist.m_pAnchorPoint, pActiveView,
                                                            pFeatureLayer);
                            break;
                        }

                        case esriGeometryType.esriGeometryMultipoint:
                        {
                            SketchToolAssist.m_bInUse = true;
                            SketchToolAssist.Feedback = new NewMultiPointFeedback();
                            INewMultiPointFeedback newMultiPointFeedback =
                                (INewMultiPointFeedback)SketchToolAssist.Feedback;
                            SketchToolAssist.Feedback.Display   = pActiveView.ScreenDisplay;
                            SketchToolAssist.m_pPointCollection = new Multipoint();
                            newMultiPointFeedback.Start(SketchToolAssist.m_pPointCollection,
                                                        SketchToolAssist.m_pAnchorPoint);
                            break;
                        }

                        case esriGeometryType.esriGeometryPolyline:
                        {
                            SketchToolAssist.m_bInUse = true;
                            SketchToolAssist.Feedback = new NewPolylineFeedback();
                            newPolylineFeedback       = (INewPolylineFeedback)SketchToolAssist.Feedback;
                            newPolylineFeedback.ChangeLineType(SketchToolAssist.LineType);
                            SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay;
                            newPolylineFeedback.Start(SketchToolAssist.m_pAnchorPoint);
                            SketchToolAssist.m_PointCount = 1;
                            SketchToolAssist.StartPoint   = SketchToolAssist.m_pAnchorPoint;
                            SketchToolAssist.m_pPointColn = new Polyline();
                            SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value,
                                                                   ref value);
                            unit = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits);
                            break;
                        }

                        case esriGeometryType.esriGeometryPolygon:
                        {
                            SketchToolAssist.m_bInUse = true;
                            SketchToolAssist.Feedback = new NewPolygonFeedbackEx();
                            feedback1 = (INewPolygonFeedbackEx)SketchToolAssist.Feedback;
                            feedback1.ChangeLineType(SketchToolAssist.LineType);
                            SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay;
                            feedback1.Start(SketchToolAssist.m_pAnchorPoint);
                            SketchToolAssist.m_PointCount = 0;
                            SketchToolAssist.m_pPointColn = new Polygon();
                            SketchToolAssist.StartPoint   = SketchToolAssist.m_pAnchorPoint;
                            unit = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits);
                            num  = CommonHelper.measureArea(SketchToolAssist.m_pAnchorPoint, 1,
                                                            ref SketchToolAssist.m_pPointColn);
                            length = (SketchToolAssist.m_pPointColn as IPolygon).Length;
                            if (num <= 0)
                            {
                                break;
                            }
                            str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num);
                            break;
                        }
                        }
                    }
                    else
                    {
                        SketchToolAssist.Feedback = new NewDimensionFeedback();
                        try
                        {
                            (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScale =
                                (pActiveView as IMap).ReferenceScale;
                            (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScaleUnits =
                                (pActiveView as IMap).MapUnits;
                        }
                        catch
                        {
                        }
                        SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay;
                        (SketchToolAssist.Feedback as INewDimensionFeedback).Start(SketchToolAssist.m_pAnchorPoint);
                        SketchToolAssist.m_PointCount = 1;
                    }
                }
                else if (SketchToolAssist.Feedback is INewDimensionFeedback)
                {
                    SketchToolAssist.m_PointCount = SketchToolAssist.m_PointCount + 1;
                    (SketchToolAssist.Feedback as INewDimensionFeedback).AddPoint(SketchToolAssist.m_pAnchorPoint);
                    if (SketchToolAssist.m_PointCount == 3)
                    {
                        IDimensionShape dimensionShape = (SketchToolAssist.Feedback as INewDimensionFeedback).Stop();
                        CreateFeatureTool.CreateDimensionFeature(dimensionShape,
                                                                 (SketchToolAssist.Feedback as INewDimensionFeedback).DimensionType, pActiveView,
                                                                 pFeatureLayer);
                    }
                }
                else if (SketchToolAssist.Feedback is INewMultiPointFeedback)
                {
                    value = Missing.Value;
                    SketchToolAssist.m_pPointCollection.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value, ref value);
                    (SketchToolAssist.Feedback as INewMultiPointFeedback).Start(SketchToolAssist.m_pPointCollection,
                                                                                SketchToolAssist.m_pAnchorPoint);
                }
                else if (SketchToolAssist.Feedback is INewLineFeedback)
                {
                    newPolylineFeedback = (INewPolylineFeedback)SketchToolAssist.Feedback;
                    value = Missing.Value;
                    newPolylineFeedback.AddPoint(SketchToolAssist.m_pAnchorPoint);
                    SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value, ref value);
                    SketchToolAssist.m_PointCount = SketchToolAssist.m_PointCount + 1;
                    unit = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits);
                }
                else if (SketchToolAssist.Feedback is INewPolygonFeedback)
                {
                    feedback1 = (INewPolygonFeedbackEx)SketchToolAssist.Feedback;
                    feedback1.AddPoint(SketchToolAssist.m_pAnchorPoint);
                    SketchToolAssist.m_PointCount = SketchToolAssist.m_PointCount + 1;
                    unit   = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits);
                    num    = CommonHelper.measureArea(SketchToolAssist.m_pAnchorPoint, 1, ref SketchToolAssist.m_pPointColn);
                    length = (SketchToolAssist.m_pPointColn as IPolygon).Length;
                    if (num > 0)
                    {
                        str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num);
                    }
                    object value5 = Missing.Value;
                    object obj5   = Missing.Value;
                    SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value5, ref obj5);
                }
                if (SketchToolAssist.LastPoint == null)
                {
                    SketchToolAssist.LastPoint = new ESRI.ArcGIS.Geometry.Point();
                }
                SketchToolAssist.LastPoint.PutCoords(SketchToolAssist.m_pAnchorPoint.X,
                                                     SketchToolAssist.m_pAnchorPoint.Y);
                str = str1;
            }
            else
            {
                str = "";
            }
            return(str);
        }
Exemplo n.º 7
0
        private void method_2(IPoint ipoX)
        {
            string unit;
            double num;

            string[] str;
            string   str1;
            double   num1;
            string   str2;

            SketchShareEx.IsFixDirection = false;
            SketchShareEx.IsFixLength    = false;
            IActiveView focusMap = (IActiveView)_context.FocusMap;

            if (!SketchShareEx.m_bInUse)
            {
                if (Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer != null)
                {
                    IFeatureLayer featureLayer = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer;
                    if (featureLayer.FeatureClass == null)
                    {
                        return;
                    }
                    if (featureLayer.FeatureClass.FeatureType != esriFeatureType.esriFTAnnotation)
                    {
                        switch (featureLayer.FeatureClass.ShapeType)
                        {
                        case esriGeometryType.esriGeometryPoint:
                        {
                            CreateFeatureTool.CreateFeature(ipoX, _context.FocusMap as IActiveView,
                                                            Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer);
                            break;
                        }

                        case esriGeometryType.esriGeometryMultipoint:
                        {
                            SketchShareEx.m_bInUse    = true;
                            SketchToolAssist.Feedback = new NewMultiPointFeedback();
                            INewMultiPointFeedback feedback = (INewMultiPointFeedback)SketchToolAssist.Feedback;
                            SketchShareEx.m_pPointCollection = new Multipoint();
                            feedback.Start(SketchShareEx.m_pPointCollection, ipoX);
                            break;
                        }

                        case esriGeometryType.esriGeometryPolyline:
                        {
                            SketchShareEx.m_bInUse    = true;
                            SketchToolAssist.Feedback = new NewLineFeedback();
                            ((INewLineFeedback)SketchToolAssist.Feedback).Start(ipoX);
                            SketchShareEx.PointCount = SketchShareEx.PointCount + 1;
                            if (!this.bool_0)
                            {
                                break;
                            }
                            unit = Common.GetUnit(_context.FocusMap.MapUnits);
                            num  = Common.measureLength(ipoX, 1, ref SketchShareEx.m_pLastPoint1,
                                                        ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength);
                            str = new string[]
                            {
                                "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ",
                                SketchShareEx.m_totalLength.ToString("0.###"), unit
                            };
                            str1 = string.Concat(str);
                            _context.SetStatus(str1);
                            break;
                        }

                        case esriGeometryType.esriGeometryPolygon:
                        {
                            SketchShareEx.m_bInUse    = true;
                            SketchToolAssist.Feedback = new NewPolygonFeedback();
                            ((INewPolygonFeedback)SketchToolAssist.Feedback).Start(ipoX);
                            SketchShareEx.PointCount = SketchShareEx.PointCount + 1;
                            if (!this.bool_0)
                            {
                                break;
                            }
                            unit = string.Concat(" 平方", Common.GetUnit(_context.FocusMap.MapUnits));
                            num1 = Common.measureArea(ipoX, 1, ref SketchToolAssist.m_pPointColn);
                            if (num1 <= 0)
                            {
                                break;
                            }
                            str2 = string.Concat("总面积 = ", num1.ToString("0.###"), unit);
                            _context.SetStatus(str2);
                            break;
                        }
                        }
                    }
                    else
                    {
                        try
                        {
                            Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation();
                            IFeature            feature            = featureLayer.FeatureClass.CreateFeature();
                            ITextElement        textElement        = CreateFeatureTool.MakeTextElement("文本", 0, ipoX);
                            IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;
                            annotationFeature2.LinkedFeatureID   = -1;
                            annotationFeature2.AnnotationClassID = 0;
                            annotationFeature2.Annotation        = textElement as IElement;
                            EditorEvent.NewRow(feature);
                            feature.Store();
                            Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation();
                            EditorEvent.AfterNewRow(feature);
                            focusMap.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                            _context.FocusMap.ClearSelection();
                            _context.FocusMap.SelectFeature(featureLayer, feature);
                            focusMap.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                        }
                        catch (Exception exception)
                        {
                            CErrorLog.writeErrorLog(this, exception, "");
                        }
                    }
                    if (SketchToolAssist.Feedback != null)
                    {
                        SketchToolAssist.Feedback.Display = focusMap.ScreenDisplay;
                    }
                }
                else
                {
                    return;
                }
            }
            else if (SketchToolAssist.Feedback is INewMultiPointFeedback)
            {
                object value = Missing.Value;
                SketchShareEx.m_pPointCollection.AddPoint(ipoX, ref value, ref value);
            }
            else if (SketchToolAssist.Feedback is INewLineFeedback)
            {
                ((INewLineFeedback)SketchToolAssist.Feedback).AddPoint(ipoX);
                SketchShareEx.PointCount = SketchShareEx.PointCount + 1;
                if (this.bool_0)
                {
                    unit = Common.GetUnit(_context.FocusMap.MapUnits);
                    num  = Common.measureLength(ipoX, 1, ref SketchShareEx.m_pLastPoint1, ref SketchShareEx.m_pEndPoint1,
                                                ref SketchShareEx.m_totalLength);
                    str = new string[]
                    {
                        "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ", SketchShareEx.m_totalLength.ToString("0.###"),
                        unit
                    };
                    str1 = string.Concat(str);
                    _context.SetStatus(str1);
                }
            }
            else if (SketchToolAssist.Feedback is INewPolygonFeedback)
            {
                ((INewPolygonFeedback)SketchToolAssist.Feedback).AddPoint(ipoX);
                SketchShareEx.PointCount = SketchShareEx.PointCount + 1;
                if (this.bool_0)
                {
                    unit = string.Concat(" 平方", Common.GetUnit(_context.FocusMap.MapUnits));
                    num1 = Common.measureArea(ipoX, 1, ref SketchToolAssist.m_pPointColn);
                    if (num1 > 0)
                    {
                        str2 = string.Concat("总面积 = ", num1.ToString("0.###"), unit);
                        _context.SetStatus(str2);
                    }
                }
            }
            SketchShareEx.LastPoint = new ESRI.ArcGIS.Geometry.Point();
            SketchShareEx.LastPoint.PutCoords(ipoX.X, ipoX.Y);
        }