Example #1
0
        /// <summary>
        /// 完成地图对象移动,取得移动后的对象,并将其更新到图层中
        /// 建议在Map.MouseUp事件中调用本方法
        /// </summary>
        public void MoveFeatureEnd()
        {
            IGeometry pGeometry;

            try
            {
                if (m_pFeedback == null)
                {
                    return;
                }

                if (m_pFeedback is IMovePointFeedback)
                {
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                    pGeometry = pPointMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is IMoveLineFeedback)
                {
                    IMoveLineFeedback pLineMove = (IMoveLineFeedback)m_pFeedback;
                    pGeometry = pLineMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is IMovePolygonFeedback)
                {
                    IMovePolygonFeedback pPolyMove = (IMovePolygonFeedback)m_pFeedback;
                    pGeometry = pPolyMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }

                m_pFeedback = null;
                IActiveView pActiveView = (IActiveView)m_pMap;
                pActiveView.Refresh();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
Example #2
0
 public override void OnDblClick()
 {
     if (this._displayFeedback != null)
     {
         IPolygon polygon = (this._displayFeedback as INewPolygonFeedback).Stop();
         this._displayFeedback = null;
         if ((polygon as IArea).Area != 0.0)
         {
             if ((polygon as ITopologicalOperator).IsSimple)
             {
                 polygon.SpatialReference                       = this._context.FocusMap.SpatialReference;
                 this._context.FocusMap.ClipGeometry            = polygon;
                 (this._context.FocusMap as IActiveView).Extent = polygon.Envelope;
                 this._context.ActiveView.Refresh();
             }
             else
             {
                 System.Windows.Forms.MessageBox.Show("多边形非简单多边形!");
             }
         }
     }
 }
Example #3
0
        private void CalculateDistanceMouseDown(IPoint pPoint)
        {
            if (!m_bInUse)//如果命令没有使用
            {
                m_bInUse = true;

                m_pRecordPointArray.Add(pPoint);

                m_pLastPoint = pPoint;

                CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, pPoint);

                m_pFeedback = new NewLineFeedbackClass();
                m_pLineFeed = (INewLineFeedback)m_pFeedback;
                m_pLineFeed.Start(pPoint);
                if (m_pFeedback != null)
                {
                    m_pFeedback.Display = m_pActiveView.ScreenDisplay;
                }
            }
            else//若果命令正使用中
            {
                m_pLineFeed.Stop();
                m_pLineFeed.Start(pPoint);

                IPoint tempPoint = new PointClass();
                tempPoint.X = pPoint.X;
                tempPoint.Y = pPoint.Y;
                m_pRecordPointArray.Add(tempPoint);

                m_pLastPoint = tempPoint;

                m_dblDistance      = CommonFunction.GetDistance_P12((IPoint)m_pRecordPointArray.get_Element(m_pRecordPointArray.Count - 2), m_pLastPoint); //最后一段的长度
                m_dblTotalDistance = m_dblTotalDistance + m_dblDistance;                                                                                   //总长度

                CommonFunction.DisplaypSegmentColToScreen(m_MapControl, ref m_pRecordPointArray);                                                          //可以刷新屏幕了
            }
        }
Example #4
0
        private void Reset()
        {
            m_bFirst             = false;
            m_bSecond            = false;
            m_bThree             = false;
            m_bModify            = false;
            m_bInputWindowCancel = true;
            m_pCircleFeed        = null;
            m_pLineFeed          = null;
            m_pFeedback          = null;
            if (m_pLastPoint != null)
            {
                m_pLastPoint.SetEmpty();
            }
            ;
            m_pSegment = null;

            m_pActiveView.GraphicsContainer.DeleteAllElements();
            m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_pEnvelope);            //视图刷新
            m_pEnvelope = null;

            m_pStatusBarService.SetStateMessage("就绪");
        }
Example #5
0
 public override void OnMouseDown(int button, int Shift, int x, int y)
 {
     if (button != 2)
     {
         this.int_2 = Shift;
         if (_context.MapControl.ActiveView is IPageLayout)
         {
             IPoint mapPoint = _context.MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
             IMap   map      = _context.MapControl.ActiveView.HitTestMap(mapPoint);
             if (map == null)
             {
                 return;
             }
             _context.MapControl.ActiveView.FocusMap = map;
             _context.MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
         }
         this.int_1 = x;
         IActiveView focusMap = GetMap() as IActiveView;
         this._mPoint = focusMap.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
         this._isFree = true;
         if (this._subType == 1)
         {
             if (this._displayFeedback != null)
             {
                 (this._displayFeedback as INewPolygonFeedback).AddPoint(this._mPoint);
             }
             else
             {
                 this._displayFeedback = new NewPolygonFeedback()
                 {
                     Display = focusMap.ScreenDisplay
                 };
                 (this._displayFeedback as INewPolygonFeedback).Start(this._mPoint);
             }
         }
     }
 }
Example #6
0
        private void DrawArc3PMouseDown(IPoint pPoint, int shift)
        {
            if (!m_bInUse)
            {
                m_pFeedback         = new NewLineFeedbackClass();
                m_pLineFeed         = (INewLineFeedback)m_pFeedback;
                m_pLineFeed.Display = m_pActiveView.ScreenDisplay;

                pLineArray.Add(pPoint);

                if (pLineArray.Count == 1)
                {
                    m_pLineFeed.Start(pPoint);
                }

                m_pLastPoint = pPoint;

                CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, pPoint);

                if (pLineArray.Count == 2)
                {
                    m_bInUse = true;
                    m_pLineFeed.Stop();
                    m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pEnvelope);
                }
            }
            else
            {
                if (pLineArray.Count >= 2)
                {
                    EndDrawArc3P(pPoint, shift);
                }
            }

            m_pSegment = null;            //清空捕捉到的片断
        }
Example #7
0
        //右键菜单点击事件
        private void toolManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            string strItemName = e.Tool.SharedProps.Caption.ToString();

            switch (strItemName)
            {
            case "键回退(&U)":
                Undo();

                break;

            case "输入左折角(&N)...":
                frmLeftCorner fromFixLeftCorner = new frmLeftCorner();
                fromFixLeftCorner.ShowDialog();

                break;

            case "长度+方位角(&F)..":
                frmLengthAzim.m_pPoint = m_pLastPoint;
                frmLengthAzim fromLengthDirect = new frmLengthAzim();
                fromLengthDirect.ShowDialog();
                if (m_bInputWindowCancel == false)                       //若用户没用取消输入
                {
                    DrawBezierCurveMouseDown(m_pAnchorPoint);
                }

                break;

            case "输入方位角(&O)...":
                frmFixAzim fromFixAzim = new frmFixAzim();
                fromFixAzim.ShowDialog();

                break;

            case "输入长度(&D)...":
                frmFixLength fromFixLength = new frmFixLength();
                fromFixLength.ShowDialog();

                break;

            case "绝对坐标(&A)...":
                frmAbsXYZ.m_pPoint = m_pAnchorPoint;
                frmAbsXYZ formXYZ = new frmAbsXYZ();
                formXYZ.ShowDialog();
                if (m_bInputWindowCancel == false)                       //若用户没用取消输入
                {
                    DrawBezierCurveMouseDown(m_pAnchorPoint);
                }

                break;

            case "相对坐标(&R)...":
                frmRelaXYZ.m_pPoint = m_pLastPoint;
                frmRelaXYZ formRelaXYZ = new frmRelaXYZ();
                formRelaXYZ.ShowDialog();
                if (m_bInputWindowCancel == false)                       //若用户没用取消输入
                {
                    DrawBezierCurveMouseDown(m_pAnchorPoint);
                }

                break;

            case "平行(&P)...":
                m_pSegment  = null;
                m_bKeyCodeP = true;
                CommonFunction.ParallelRule(ref m_bKeyCodeP, m_pActiveView, m_dblTolerance, ref m_pSegment, m_pLastPoint, m_BeginConstructParallelPoint, ref m_pAnchorPoint);

                break;

            case "直角(&S)...":
                m_bkeyCodeS = true;

                if (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    m_pLastFeedback = new NewLineFeedbackClass();
                    m_pLastLineFeed = (INewLineFeedback)m_pLastFeedback;
                    m_pLastLineFeed.Start((IPoint)m_pUndoArray.get_Element(0));
                }

                break;

            case "封闭完成(&C)":
                if (m_bInUse)
                {
                    m_pUndoArray.Add((IPoint)m_pUndoArray.get_Element(0));

                    EndDrawBezierCurve();
                }

                break;

            case "完成(&E)":
                EndDrawBezierCurve();

                break;

            case "取消(ESC)":
                Reset();

                break;

            default:

                break;
            }
        }
Example #8
0
        private void DrawBezierCurveMouseDown(IPoint pPoint)
        {
            if (!m_bInUse)           //如果命令没有使用
            {
                m_bInUse = true;

                m_pUndoArray.Add(pPoint);

                CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, pPoint);

                m_pFeedback        = new NewBezierCurveFeedbackClass();
                m_pBezierCurveFeed = (INewBezierCurveFeedback)m_pFeedback;
                m_pBezierCurveFeed.Start(pPoint);
                if (m_pFeedback != null)
                {
                    m_pFeedback.Display = m_pActiveView.ScreenDisplay;
                }

                if (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                     
                    //若当前图层是面层,则显示回馈开始点到鼠标点的线段
                        m_pLastFeedback = new NewLineFeedbackClass();
                    m_pLastLineFeed = (INewLineFeedback)m_pLastFeedback;
                    m_pLastLineFeed.Start(pPoint);
                    if (m_pLastFeedback != null)
                    {
                        m_pLastFeedback.Display = m_pActiveView.ScreenDisplay;
                    }
                }
            }
            else            //若果命令正使用中
            {
                m_pBezierCurveFeed = (INewBezierCurveFeedback)m_pFeedback;
                m_pBezierCurveFeed.AddPoint(pPoint);

                IPoint tempPoint = new PointClass();
                tempPoint.X = pPoint.X;
                tempPoint.Y = pPoint.Y;
                m_pUndoArray.Add(tempPoint);
                UpdataBezierCurveFeed(m_MapControl, ref m_pUndoArray);               //刷新屏幕

                if ((m_bFixLength == true) && (m_bFixDirection == false))            //可以给定一个长度值
                {
                    m_bFixLength = false;
                }
                else if ((m_bFixLength == false) && (m_bFixDirection == true))                 //可以给定一个固定方向值
                {
                    m_bFixDirection = false;
                }
                else if ((m_bFixLength == true) && (m_bFixDirection == true))
                {
                    m_bFixLength    = false;
                    m_bFixDirection = false;
                }

                if (m_bFixLeftCorner)
                {
                    m_bFixLeftCorner = false;
                }
            }

            m_pLastPoint = pPoint;

            if (m_bkeyCodeS == true)             //直角结束
            {
                m_bkeyCodeS = false;
                if (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    m_pLastLineFeed.Stop();
                }
            }

            m_pSegment = null;            //清空捕捉到的片断
        }
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     foreach (ToolStripItem i in this.toolStrip1.Items)
     {
         ((ToolStripButton)i).Checked = false;
     }
     ((ToolStripButton)sender).Checked = true;
     this.pDisplayFeedback = null;
     NewPolyline pNewPolyline = new NewPolyline();
     pNewPolyline.OnCreate(this.axMapControl1.Object);
     this.axMapControl1.CurrentTool = ((ITool)pNewPolyline);
 }
Example #10
0
        /// <summary>
        /// 松开鼠标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
        {
            if (this.pDisplayFeedback != null)
            {
                if (this.btnLineMovePoint.Checked)//移动多义线节点
                {
                    IGeometry pGeometry = ((ILineMovePointFeedback)this.pDisplayFeedback).Stop();
                    if (pGeometry != null)
                    {
                        this.hitElement.Geometry = pGeometry;
                        this.pGraphicContainer.UpdateElement(this.hitElement);
                    }

                    this.hitElement = null;
                    this.pDisplayFeedback = null;
                    this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);

                }
                else if (this.btnNewCircle.Checked)//画圆
                {
                    IGeometry pGeometry = ((INewCircleFeedback)this.pDisplayFeedback).Stop();

                    this.AddElement(pGeometry);
                    this.pDisplayFeedback = null;
                }
                else if (this.btnNewEnvelope.Checked)//画矩形
                {
                    IGeometry pGeometry = ((INewEnvelopeFeedback)this.pDisplayFeedback).Stop();

                    this.AddElement(pGeometry);
                    this.pDisplayFeedback = null;
                }
                else if (this.btnPolygonMovePoint.Checked)//移动多边形节点
                {
                    IGeometry pGeometry = ((IPolygonMovePointFeedback)this.pDisplayFeedback).Stop();
                    if (pGeometry != null)
                    {
                        this.hitElement.Geometry = pGeometry;
                        this.pGraphicContainer.UpdateElement(this.hitElement);
                    }

                    this.hitElement = null;
                    this.pDisplayFeedback = null;
                    this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);

                }
                else if (this.btnMoveGeometry.Checked)//移动几何对象
                {
                    if (this.pEnumElement != null)
                    {
                        this.pEnumElement.Reset();
                        IElement pElement;
                        ITransform2D pTransform2D;
                        //需要用ITransform2D接口逐个逐个的移动element
                        for (pElement = this.pEnumElement.Next(); pElement != null; pElement = this.pEnumElement.Next())
                        {
                            pTransform2D = pElement as ITransform2D;
                            pTransform2D.Move(e.mapX - this.moveGeometryStartPoint.X, e.mapY - this.moveGeometryStartPoint.Y);
                            this.pGraphicContainer.UpdateElement(pElement);
                        }
                        this.moveGeometryStartPoint = null;
                        this.pEnumElement = null;
                        this.pDisplayFeedback = null;
                        this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    }
                }
                else if (this.btnStretchLine.Checked)//拉伸多义线
                {
                    if (this.hitElement != null)
                    {
                        IGeometry pGeometry = ((IStretchLineFeedback)this.pDisplayFeedback).Stop();
                        this.hitElement.Geometry = pGeometry;
                        this.pGraphicContainer.UpdateElement(this.hitElement);

                        this.hitElement = null;
                        this.pDisplayFeedback = null;
                        this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    }
                }
            }
        }
        public bool EditFeature(int x, int y, IGeometry geometry)
        {
            GetFeatureOnMouseDown(x, y);
            SelectOnMouseDown();
            if (MyselectedFeature.Count < 1)
            {
                return(false);
            }
            if (geometry == null)
            {
                return(false);
            }

            IPoint pHitPoint = null;
            double hitDist = 0, tol = 0;
            int    vertexIndex = 0, vertexOffset = 0, numVertices = 0, partIndex = 0;
            bool   vertex = false;

            IFeature editedFeature = MyselectedFeature[0];
            IPoint   point         = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            tol = ConvertPixelsToMapUnits(4);
            //IGeometry pGeo = editedFeature.Shape;
            //m_EditingFeature = editedFeature;

            try
            {
                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                    MyfeedBack         = new MovePointFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePointFeedback pointMove = MyfeedBack as IMovePointFeedback;
                    pointMove.Start(geometry as IPoint, point);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;

                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new LineMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        ILineMovePointFeedback lineMove = MyfeedBack as ILineMovePointFeedback;
                        lineMove.Start(geometry as IPolyline, vertexIndex, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;
                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new PolygonMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        IPolygonMovePointFeedback polyMove = MyfeedBack as IPolygonMovePointFeedback;
                        polyMove.Start(geometry as IPolygon, vertexIndex + vertexOffset, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }
            }
            catch { return(false); }
            return(true);
        }
        void twoPart_Click(object sender, EventArgs e)
        {
            if (_segmentCollection != null)
            {
                if (_segmentCollection.SegmentCount > 0)
                {
                    if (_insertionFeedback != null && _vertexPoint != null)
                    {
                        if (_insertionFeedback is INewLineFeedback)
                        {
                            INewLineFeedback lineEditFeed = (INewLineFeedback)_insertionFeedback;
                            lineEditFeed.Stop();

                            IEnumSegment enumSegs = _segmentCollection.EnumSegments;
                            enumSegs.Reset();

                            int i = 0, j = 0;
                            ISegment segment;
                            enumSegs.Next(out segment, ref i, ref i);
                            while (segment != null)
                            {
                                IPolyline polyLine = new PolylineClass { FromPoint = segment.FromPoint, ToPoint = segment.ToPoint };
                                CreateFeature(polyLine as IGeometry);
                                j++;
                                enumSegs.Next(out segment, ref i, ref i);
                            }
                        }
                        _insertionFeedback = null;
                    }
                    _insertionFeedbackInUse = false;
                }
            }
        }
        /// <summary>
        /// ����½�����ȡ�û��ƵĶ��󣬲���ӵ�ͼ����
        /// ������Map.DblClick��Map.MouseDown(Button = 2)�¼��е��ñ�����
        /// </summary>
        public void NewFeatureEnd()
        {
            IGeometry pGeom = null;
            IPointCollection pPointCollection;
            object obj = Type.Missing;
            try
            {
                if (m_pFeedback is INewMultiPointFeedback)
                {
                    INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback;
                    pMPFeed.Stop();
                    pGeom = (IGeometry)m_pPointCollection;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PointClass() as IGeometryCollection;
                    }

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewLineFeedback)
                {
                    INewLineFeedback pLineFeed = (INewLineFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolylineClass() as IGeometryCollection;
                    }

                    IPolyline pPolyLine = pLineFeed.Stop();

                    pPointCollection = (IPointCollection)pPolyLine;
                    if (pPointCollection.PointCount < 2)
                        MessageBox.Show("�������������ڵ�");
                    else
                        pGeom = (IGeometry)pPointCollection;

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewPolygonFeedback)
                {
                    INewPolygonFeedback pPolyFeed = (INewPolygonFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolygonClass() as IGeometryCollection;
                    }

                    IPolygon pPolygon;
                    pPolygon = pPolyFeed.Stop();
                    if (pPolygon != null)
                    {
                        pPointCollection = (IPointCollection)pPolygon;
                        if (pPointCollection.PointCount < 3)
                            MessageBox.Show("�������������ڵ�");
                        else
                            pGeom = (IGeometry)pPointCollection;

                        m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                    }
                }

                CreateFeature(m_GeometryCollection as IGeometry);
                m_pFeedback = null;
                m_bInUse = false;
                m_GeometryCollection = null;
            }
            catch (Exception e)
            {
                m_pFeedback = null;
                m_bInUse = false;
                m_GeometryCollection = null;
                Console.WriteLine(e.Message.ToString());
            }
        }
Example #14
0
        //回退操作
        private void  Undo()
        {
            //删除数组中最后一组点
            int count = m_pUndoArray.Count;

            if (count == 0)
            {
                Reset();
                return;
            }

            #region 计算最小刷新的矩形
            IArray pTempArray = new ArrayClass();
            for (int i = 0; i < m_pUndoArray.Count; i++)
            {
                pTempArray.Add(((PointStruct)m_pUndoArray.get_Element(i)).Point);
            }
            if (pTempArray.Count > 2)
            {
                m_pEnvelope = CommonFunction.GetMinEnvelopeOfTheArray(pTempArray);
            }
            else if (pTempArray.Count == 2)
            {
                IPoint pTempPoint = new PointClass();
                m_pEnvelope = CommonFunction.GetMinEnvelopeOfTheArray(pTempArray);
                m_pEnvelope.Union(m_pPoint.Envelope);
            }
            if (m_pEnvelope != null)
            {
                m_pEnvelope.Expand(10, 10, false);
            }
            pTempArray.RemoveAll();
            #endregion

            PointStruct pointStruct = (PointStruct)m_pUndoArray.get_Element(count - 1);

            IPoint pPoint0 = new PointClass();
            pPoint0 = pointStruct.Point;
            IEnvelope enve = new EnvelopeClass();
            enve = CommonFunction.NewRect(pPoint0, m_dblTolerance);

            IEnumElement pEnumElement = m_MapControl.ActiveView.GraphicsContainer.LocateElementsByEnvelope(enve);
            if (pEnumElement != null)
            {
                pEnumElement.Reset();
                IElement pElement = pEnumElement.Next();

                while (pElement != null)
                {
                    m_MapControl.ActiveView.GraphicsContainer.DeleteElement(pElement);
                    pElement = pEnumElement.Next();
                }
            }

            if (pointStruct.Type == 1)
            {
                m_pUndoArray.Remove(m_pUndoArray.Count - 1);
                m_pUndoArray.Remove(m_pUndoArray.Count - 1);
            }
            else if (pointStruct.Type == 2)
            {
                m_pUndoArray.Remove(m_pUndoArray.Count - 1);
                m_pUndoArray.Remove(m_pUndoArray.Count - 1);
                m_pUndoArray.Remove(m_pUndoArray.Count - 1);
            }

            //屏幕刷新
            m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pEnvelope);             //视图刷新
            m_pActiveView.ScreenDisplay.UpdateWindow();

            //开始作复位工作
            m_pLineFeedArray.RemoveAll();
            if (m_pUndoArray.Count != 0)
            {
                m_pLastPoint = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 1)).Point;

                DisplaypSegmentColToScreen(m_MapControl, ref m_pUndoArray);

                m_drawState = "Line_Line";              //默认回退之后,绘制直线

                IPoint pPoint = new PointClass();
                pPoint = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 1)).Point;
                m_pLineFeedArray.Add(pPoint);         

                    m_pFeedback = new NewLineFeedbackClass();
                m_pLineFeed         = (NewLineFeedback)m_pFeedback;
                m_pLineFeed.Display = m_pActiveView.ScreenDisplay;
                if (m_pLineFeed != null)
                {
                    m_pLineFeed.Stop();
                }
                m_pLineFeed.Start(pPoint);
                m_pLineFeed.MoveTo(m_pPoint);

                //调整m_pFromPoint、m_pMiddlePoint、m_pToPoint
                if (((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 1)).Type == 1)              //若数组最后一段为线段
                {
                    m_pFromPoint = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 2)).Point;
                    m_pToPoint   = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 1)).Point;
                }
                else if (((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 1)).Type == 2)              //若数组最后一段为圆弧
                {
                    m_pFromPoint   = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 3)).Point;
                    m_pMiddlePoint = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 2)).Point;
                    m_pToPoint     = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 1)).Point;
                }
            }
            else             //if (m_pUndoArray.Count = 0)
            {
                Reset();     //复位
            }
        }
Example #15
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (e.button == 1)
            {
                //给m_graphicsContainer赋值
                m_graphicsContainer = axMapControl1.Map as IGraphicsContainer;
                //在添加polygon被选中时
                if (miAddPolygon.Checked)
                {
                    //在鼠标点击的位置生成一个点
                    IPoint p_Point = new PointClass();
                    p_Point.PutCoords(e.mapX, e.mapY);
                    IActiveView    p_activeview    = axMapControl1.Map as IActiveView;
                    IScreenDisplay p_ScreenDisplay = p_activeview.ScreenDisplay;
                    //标记符等于0时
                    if (m_marker == 0)
                    {
                        //对m_DisplayFeedback重新初始化
                        m_DisplayFeedback = new NewPolygonFeedbackClass();
                        //设置m_DisplayFeedback的display
                        m_DisplayFeedback.Display = p_ScreenDisplay;
                        //开始绘制polygon的第一个点
                        ((INewPolygonFeedback)m_DisplayFeedback).Start(p_Point);
                        //将m_polyline转为pointcollection
                        IPointCollection p_PointCollection = m_polyline as IPointCollection;
                        //将第一个点加入pointcollection中
                        p_PointCollection.AddPoint(p_Point);
                        //将第一个点记录到m_point中
                        m_point = p_Point;
                        //对m_polyline重新赋值
                        m_polyline = p_PointCollection as IPolyline;
                        if (m_marker == 0)
                        {
                            m_marker = 1;
                        }
                        //刷新
                        axMapControl1.ActiveView.Refresh();
                    }
                    //如果不是第一次点击,就添加节点
                    else
                    {
                        //初始化红线和蓝线
                        if (m_element_red != null)
                        {
                            m_graphicsContainer.DeleteElement(m_element_red);
                        }
                        if (m_element_green != null)
                        {
                            m_graphicsContainer.DeleteElement(m_element_green);
                        }
                        //向m_DisplayFeedback中添加顶点
                        ((INewPolygonFeedback)m_DisplayFeedback).AddPoint(p_Point);
                        IPointCollection p_PointCollection = m_polyline as IPointCollection;
                        p_PointCollection.AddPoint(p_Point);
                        //生成红线
                        m_polyline = p_PointCollection as IPolyline;
                        ILineElement p_LineElement_red = new LineElementClass();
                        m_element_red          = p_LineElement_red as IElement;
                        m_element_red.Geometry = m_polyline;
                        ISimpleLineSymbol p_SimpleLineSymbol = new SimpleLineSymbolClass();
                        IRgbColor         p_rgbcolor         = new RgbColorClass();
                        p_rgbcolor.Red           = 255;
                        p_rgbcolor.Green         = 0;
                        p_rgbcolor.Blue          = 0;
                        p_SimpleLineSymbol.Color = p_rgbcolor as IColor;
                        p_LineElement_red.Symbol = p_SimpleLineSymbol as ILineSymbol;
                        //设置蓝线symbol
                        ISimpleLineSymbol p_SimpleLine_green = new SimpleLineSymbolClass();
                        IRgbColor         p_rgbcolor_green   = new RgbColorClass();
                        p_rgbcolor_green.Red     = 0;
                        p_rgbcolor_green.Green   = 255;
                        p_rgbcolor_green.Blue    = 255;
                        p_SimpleLine_green.Color = p_rgbcolor_green as IColor;
                        //生成蓝线
                        IPolyline        p_polyline        = new PolylineClass();
                        IPointCollection p_pointColl_green = p_polyline as IPointCollection;
                        //向蓝线中添加两个顶点
                        p_pointColl_green.AddPoint(m_point);
                        p_pointColl_green.AddPoint(p_Point);
                        p_polyline = p_pointColl_green as IPolyline;
                        ILineElement p_LineElement_green = new LineElementClass();
                        m_element_green            = p_LineElement_green as IElement;
                        p_LineElement_green.Symbol = p_SimpleLine_green as ILineSymbol;
                        m_element_green.Geometry   = p_polyline;
                        //将红线和蓝线加入containner显示
                        m_graphicsContainer.AddElement(m_element_red, 0);
                        m_graphicsContainer.AddElement(m_element_green, 0);
                        //更新视图
                        axMapControl1.ActiveView.Refresh();
                    }
                }
                //当选择polygon被选中时
                if (miSelectPolygon.Checked)
                {
                    //如果m_list不为空,则从容器中把其所对应element删除并将m_list清空
                    if (m_list.Count != 0)
                    {
                        for (int i = 0; i < m_list.Count; i++)
                        {
                            m_graphicsContainer.DeleteElement(m_list[i]);
                        }
                        m_list.Clear();
                    }
                    //刷新
                    axMapControl1.ActiveView.Refresh();
                    IPoint p_point = new PointClass();
                    //记录点下的点
                    p_point.PutCoords(e.mapX, e.mapY);
                    //得到选中的element集合
                    IEnumElement p_EnumElement = m_graphicsContainer.LocateElements(p_point, 5);
                    IGeometry    p_geometry;
                    //选中的element集合不为空时
                    if (p_EnumElement != null)
                    {
                        m_hitElement = p_EnumElement.Next();
                        p_geometry   = m_hitElement.Geometry;
                        //循环找到类型为polygon的element
                        while (p_geometry.GeometryType != esriGeometryType.esriGeometryPolygon && m_hitElement != null)
                        {
                            m_hitElement = p_EnumElement.Next();
                            if (m_hitElement != null)
                            {
                                p_geometry = m_hitElement.Geometry;
                            }
                        }
                        if (p_geometry.GeometryType == esriGeometryType.esriGeometryPolygon)
                        {
                            m_polygon   = (IPolygon)p_geometry;
                            m_PointColl = m_polygon as IPointCollection;
                            //循环将选中的polygon的每个点以element加入容器中
                            for (int k = 1; k < m_PointColl.PointCount; k++)
                            {
                                IMarkerElement      p_MarkerElement = new MarkerElementClass();
                                ISimpleMarkerSymbol p_simpleMarker  = new SimpleMarkerSymbolClass();
                                p_simpleMarker.Size = 5;

                                IElement p_element = (IElement)p_MarkerElement;
                                p_MarkerElement.Symbol = p_simpleMarker as IMarkerSymbol;

                                if (!(p_element == null))
                                {
                                    p_element.Geometry = m_PointColl.get_Point(k);

                                    m_graphicsContainer.AddElement(p_element, 0);
                                }
                                m_list.Add(p_element);
                            }
                            axMapControl1.ActiveView.Refresh();
                        }
                    }
                }
                //当编辑polygon被选中时
                if (miEditPolygon.Checked)
                {
                    if (m_polygon != null)
                    {
                        //在鼠标点击的位置生成一个点
                        IPoint p_Point = new PointClass();
                        p_Point.PutCoords(e.mapX, e.mapY);
                        IActiveView    p_ActiveView    = axMapControl1.Map as IActiveView;
                        IScreenDisplay p_ScreenDisplay = p_ActiveView.ScreenDisplay;
                        //建立新的hittest,设置相关变量,获取点击处polygon的顶点
                        IHitTest p_HitTest         = m_polygon as IHitTest;
                        IPoint   p_hitPoint        = new PointClass();
                        double   p_distance        = 0;
                        bool     p_isOnRightSide   = true;
                        int      p_hitPartIndex    = 0;
                        int      p_hitSegmentIndex = 0;
                        bool     p_isHit           = p_HitTest.HitTest(p_Point, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, p_hitPoint, ref p_distance, ref p_hitPartIndex, ref p_hitSegmentIndex, ref p_isOnRightSide);
                        //如果有点被选中,开始拖动该点
                        if (p_isHit)
                        {
                            m_DisplayFeedback         = new PolygonMovePointFeedbackClass();
                            m_marker                  = 2;
                            m_DisplayFeedback.Display = p_ScreenDisplay;
                            ((IPolygonMovePointFeedback)m_DisplayFeedback).Start(m_polygon, p_hitSegmentIndex, p_Point);
                        }
                    }
                }
            }
        }
Example #16
0
        private void  Undo()
        {
            if (m_pUndoArray.Count > 1)
            {
                m_pEnvelope = Class.Common.GetMinEnvelopeOfTheArray(m_pUndoArray);
            }
            else if (m_pUndoArray.Count == 1)
            {
                IPoint pTempPoint = new PointClass();
                pTempPoint.X = (m_pUndoArray.get_Element(0) as Point).X;
                pTempPoint.Y = (m_pUndoArray.get_Element(0) as Point).Y;

                m_pEnvelope.Width  = Math.Abs(m_pPoint.X - pTempPoint.X);
                m_pEnvelope.Height = Math.Abs(m_pPoint.Y - pTempPoint.Y);

                pTempPoint.X = (pTempPoint.X + m_pPoint.X) / 2;
                pTempPoint.Y = (pTempPoint.Y + m_pPoint.Y) / 2;

                m_pEnvelope.CenterAt(pTempPoint);
            }
            if (m_pEnvelope != null && !m_pEnvelope.IsEmpty)
            {
                m_pEnvelope.Expand(10, 10, false);
            }

            IPoint pPoint = new PointClass();

            pPoint = (IPoint)m_pUndoArray.get_Element(m_pUndoArray.Count - 1);
            IEnvelope enve = new EnvelopeClass();

            enve = Class.Common.NewRect(pPoint, m_dblTolerance);

            IEnumElement pEnumElement = m_MapControl.ActiveView.GraphicsContainer.LocateElementsByEnvelope(enve);

            if (pEnumElement != null)
            {
                pEnumElement.Reset();
                IElement pElement = pEnumElement.Next();

                while (pElement != null)
                {
                    m_MapControl.ActiveView.GraphicsContainer.DeleteElement(pElement);
                    pElement = pEnumElement.Next();
                }
            }

            m_pUndoArray.Remove(m_pUndoArray.Count - 1);          //删除数组中最后一个点

            //屏幕刷新
            m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pEnvelope);            //视图刷新
            m_pActiveView.ScreenDisplay.UpdateWindow();

            //开始作复位工作
            if (m_pUndoArray.Count != 0)
            {
                Class.Common.DisplaypSegmentColToScreen(m_MapControl, ref m_pUndoArray);

                m_pLastPoint = (IPoint)m_pUndoArray.get_Element(m_pUndoArray.Count - 1);

                m_pFeedback         = new NewLineFeedbackClass();
                m_pLineFeed         = (NewLineFeedback)m_pFeedback;
                m_pLineFeed.Display = m_pActiveView.ScreenDisplay;
                if (m_pLineFeed != null)
                {
                    m_pLineFeed.Stop();
                }
                m_pLineFeed.Start(m_pLastPoint);
                m_pLineFeed.MoveTo(m_pPoint);
            }
            else
            {
                Reset();                 //复位
            }
        }
 private void DeactivateCurrentTool()
 {
     _newFeature = null;
     if (_movePointFeedback != null) _movePointFeedback.Stop();
     if (_insertionFeedback != null) _insertionFeedback = null;
     _insertionFeedbackInUse = false;
 }
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            _absX = arg.X;
            _absY = arg.Y;
            if (arg.Button == MouseButtons.Left)
            {
                _constrainedAngle = 0;
                _constrainedDistance = 0;

                if (_currentTargetLayer != null)
                {
                    if (ArcMap.Document.ActiveView.ScreenDisplay != null)
                    {
                        IPoint anchor = ArcMap.Document.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);
                        GISApplication.SnapPoint(anchor);

                        if (_currentTargetLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                        {
                            _initialAnchorPoint = null;
                            try
                            {
                                if (_moveDeviceAlongLineOnInsert)
                                {
                                    if (!arg.Control)
                                    {
                                        //get connected section which is longer
                                        IFeature nearestEdge = null;// GetNearestEdge(anchor, null, new List<string>() { "PrimaryConductor" });// NetworkAnalysis.GetEdgeNearestToPoint(((INetworkClass)_currentTargetLayer.FeatureClass).GeometricNetwork, ArcMap.Document.FocusMap, anchor);
                                        if (nearestEdge != null)
                                        {
                                            if (nearestEdge.Shape is IPolyline)
                                            {
                                                bool rightSide = false;
                                                double distanceAlongCurve = 0, distanceFromCurve = 0;

                                                IPoint outPoint = new PointClass();
                                                IPolyline pLine = nearestEdge.Shape as IPolyline;
                                                pLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, anchor, true, outPoint, ref distanceAlongCurve, ref distanceFromCurve, ref rightSide);

                                                bool asRatio = false;
                                                IPoint newAnchor = new PointClass();
                                                double distanceToMoveAlongCurve = 30;// (double)UserDefinedElectricSettings.PrimaryDeviceInsertionOffset;//TODO.configurable

                                                if (pLine.Length < 10) //TODO.configurable
                                                {
                                                    MessageBox.Show("The line you are trying to split is shorter than the " + Environment.NewLine + "[MinimumLineSplitDistanceForPrimaryDevices] setting value of 10", "Invalid Operation.", MessageBoxButtons.OK);
                                                    return;
                                                }

                                                if (pLine.Length <= (distanceToMoveAlongCurve + 1))
                                                {
                                                    distanceToMoveAlongCurve = .3;
                                                    asRatio = true;
                                                }

                                                if (distanceAlongCurve <= .5)
                                                    pLine.QueryPoint(esriSegmentExtension.esriNoExtension, distanceToMoveAlongCurve, asRatio, newAnchor);
                                                else if (distanceAlongCurve > .5)
                                                {
                                                    if (asRatio)
                                                        distanceToMoveAlongCurve = 1 - distanceToMoveAlongCurve;
                                                    else
                                                        distanceToMoveAlongCurve = pLine.Length - distanceToMoveAlongCurve;
                                                    pLine.QueryPoint(esriSegmentExtension.esriNoExtension, distanceToMoveAlongCurve, asRatio, newAnchor);
                                                }

                                                if (DisplayMap.IsGeometryValid(newAnchor))
                                                {
                                                    //Center on the insertion point if it is outside the visible extent.
                                                    if (DisplayMap.IsPointInExtent(newAnchor, ArcMap.Document.ActiveView.Extent) == false)
                                                        DisplayMap.ZoomToPoint(ArcMap.Document.ActiveView, newAnchor);
                                                    anchor = newAnchor;
                                                    _movePointFeedback.MoveTo(anchor);
                                                }
                                            }
                                        }
                                    }
                                }
                                CreateFeature(anchor);
                            }
                            catch(Exception ex)
                            {
                                DeactivateCurrentTool();
                            }
                        }
                        else
                        {
                            if (!_insertionFeedbackInUse)
                            {
                                _segmentCollection = new PolylineClass();
                                _segmentAnchorPoint = null;

                                if (_currentTargetLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                                {
                                    _insertionFeedbackInUse = true;
                                    _insertionFeedback = new NewLineFeedbackClass();
                                    INewLineFeedback lineEditFeedback = (INewLineFeedback)_insertionFeedback;
                                    lineEditFeedback.Start(anchor);
                                    _initialAnchorPoint = anchor;

                                }
                                else if (_currentTargetLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                                {
                                    _insertionFeedbackInUse = true;
                                    _insertionFeedback = new NewLineFeedbackClass();
                                    INewPolygonFeedback polygonEditFeedback = (INewPolygonFeedback)_insertionFeedback;
                                    polygonEditFeedback.Start(anchor);
                                }
                                if (_insertionFeedback != null)
                                    _insertionFeedback.Display = ArcMap.Document.ActiveView.ScreenDisplay;
                            }
                            else//LINES
                            {
                                if (_constrainedAnchor != null)
                                    ProcessSegment(_constrainedAnchor);
                                else
                                    ProcessSegment(anchor);
                            }
                        }
                        anchor.SnapToSpatialReference();
                    }
                }
            }
            else //if (_insertionFeedbackInUse)
                DisplayContextMenu(_currentTargetLayer.FeatureClass.ShapeType);
        }
        protected override void OnDoubleClick()
        {
            IGeometry geom = null;

            if (_contextMenu != null)
                _contextMenu.Close();

            IPointCollection pointCollection = null;
            if (_insertionFeedback != null && _vertexPoint != null)
            {
                if (_insertionFeedback is INewLineFeedback)
                {
                    INewLineFeedback lineEditFeed = (INewLineFeedback)_insertionFeedback;
                    lineEditFeed.Stop();
                    IPolyline polyLine = (IPolyline)_segmentCollection;
                    pointCollection = (IPointCollection)polyLine;

                    if (pointCollection.PointCount < 2)
                        MessageBox.Show("You must have at least two vertices in a line.", "Bad Line Geometry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    else
                        geom = (IGeometry)pointCollection;
                }
                else if (_insertionFeedback is INewPolygonFeedback)
                {
                    INewPolygonFeedback polyFeed = (INewPolygonFeedback)_insertionFeedback;
                    polyFeed.AddPoint(_vertexPoint);

                    IPolygon polygon = polyFeed.Stop();
                    if (polygon != null)
                        pointCollection = (IPointCollection)polygon;
                    if (pointCollection.PointCount < 3)
                        MessageBox.Show("You must have at least three vertices in a polygon.", "Bad Polygon Geometry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    else
                        geom = (IGeometry)pointCollection;
                }
                if (geom != null)
                {
                    CreateFeature(geom);
                    DisplayMap.SelectFeature(_newFeature, ArcMap.Document.FocusMap, ArcMap.Document.ActiveView, true);
                }
                _insertionFeedback = null;
            }
            _insertionFeedbackInUse = false;
        }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button == 2)
                return;
            INewLineFeedback pLineFeed;

            if (m_pPoint1 == null)
            {
                m_pPoint1 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_pPoint1 = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_pPoint1);
                m_pFeedback = new NewLineFeedbackClass();
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.Start(m_pPoint1);
                if (m_pFeedback != null)
                    m_pFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;

            }
            else if (m_pPoint2 == null)
            {
                ///20140216 lyf
                ICursor pCursor = null;
                m_selectionSet.Search(null, false, out pCursor);
                IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
                IFeature m_pFeature = pFeatureCursor.NextFeature();

                if (pCursor != null)
                {
                    pCursor = null;
                    ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pCursor);
                }

                if (m_pFeature == null)
                {
                    MessageBox.Show(@"��ѡҪ��Ϊ�գ�������ѡ��Ҫ�ء�", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                m_pPoint2 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_pPoint2 = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_pPoint2);
                //�ߺ�Ҫ�ض���ȫ�ˣ���ʼ����
                //IFeatureLayer pFeatureLayer = m_pCurrentLayer as IFeatureLayer;
                IFeatureClass pFeatureClass = m_featureLayer.FeatureClass;
                ILine nLine = new LineClass();//��������
                nLine.PutCoords(m_pPoint1, m_pPoint2);
                ITransformation nTransformation = new AffineTransformation2DClass();
                IAffineTransformation2D nAffineTransformation2D = nTransformation as IAffineTransformation2D;
                nAffineTransformation2D.DefineReflection(nLine);

                //����༭
                IWorkspaceEdit pWorkspaceEdit = DataEditCommon.g_CurWorkspaceEdit;// GetWorkspaceEdit();

                ITransform2D nTransform2D = m_pFeature.Shape as ITransform2D;//����Ŀ��

                nTransform2D.Transform(esriTransformDirection.esriTransformForward, nTransformation);

                if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry0Dimension)
                {
                    pWorkspaceEdit.StartEditOperation();
                    IFeature pNewFeature = pFeatureClass.CreateFeature();
                    IPoint pNewPoint = nTransform2D as IPoint;
                    pNewFeature.Shape = pNewPoint;
                    pNewFeature.Store();
                    pWorkspaceEdit.StopEditOperation();
                    DataEditCommon.g_pMyMapCtrl.Map.ClearSelection();
                    DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(m_pCurrentLayer, pNewFeature);
                }
                else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry1Dimension)
                {
                    pWorkspaceEdit.StartEditOperation();
                    IFeature pNewFeature = pFeatureClass.CreateFeature();
                    IPolyline pNewPolyline = nTransform2D as IPolyline;//��������
                    pNewFeature.Shape = pNewPolyline;
                    pNewFeature.Store();
                    pWorkspaceEdit.StopEditOperation();
                    DataEditCommon.g_pMyMapCtrl.Map.ClearSelection();
                    DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(m_pCurrentLayer, pNewFeature);
                }
                else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry2Dimension)
                {
                    pWorkspaceEdit.StartEditOperation();
                    IFeature pNewFeature = pFeatureClass.CreateFeature();
                    IPolygon pNewPolygon = nTransform2D as IPolygon;//��������
                    pNewFeature.Shape = pNewPolygon;
                    pNewFeature.Store();
                    pWorkspaceEdit.StopEditOperation();
                    DataEditCommon.g_pMyMapCtrl.Map.ClearSelection();
                    DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(m_pCurrentLayer, pNewFeature);
                }
                else
                { }
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.AddPoint(m_pPoint2);

                pLineFeed.Stop();//��קֹͣ
                m_pFeature = null;
                m_pPoint1 = null;
                m_pPoint2 = null;
            }

            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Example #21
0
 private void axMapControl1_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e)
 {
     //当“添加polygon”被勾选时,结束polygon的绘制
     if (miAddPolygon.Checked)
     {
         //结束反馈
         IPolygon p_polygon = ((INewPolygonFeedback)m_DisplayFeedback).Stop();
         //当多边形不为空
         if (p_polygon != null)
         {
             //IGraphicsContainer转换接口,用于在当前地图存放多边形
             m_graphicsContainer = (IGraphicsContainer)(axMapControl1.Map);
             IActiveView    p_activeView  = axMapControl1.Map as IActiveView;
             IScreenDisplay screenDisplay = p_activeView.ScreenDisplay;
             //设置多边形的符号
             ISimpleFillSymbol p_simpleFillSymbol = new SimpleFillSymbolClass();
             IRgbColor         p_rgbColor         = new RgbColorClass();
             p_rgbColor.Red   = 255;
             p_rgbColor.Green = 255;
             IColor p_color = p_rgbColor;
             p_color.Transparency     = 0;
             p_simpleFillSymbol.Color = p_color;
             //新建element对象存放多边形
             IPolygonElement p_polygonElement = new PolygonElementClass();
             IElement        p_element        = (IElement)p_polygonElement;
             //将多边形以element的形式储存在graphisContainer中
             if (p_element != null)
             {
                 p_element.Geometry = p_polygon;
                 IFillShapeElement pFillShapeElement = p_element as IFillShapeElement;
                 pFillShapeElement.Symbol = p_simpleFillSymbol;
                 m_graphicsContainer.AddElement(p_element, 0);
             }
             //更改标记符为零
             m_marker = 0;
             //取消勾选“添加polygon”
             miAddPolygon.Checked = false;
             if (m_element_red != null)
             {
                 m_graphicsContainer.DeleteElement(m_element_red);
             }
             if (m_element_green != null)
             {
                 m_graphicsContainer.DeleteElement(m_element_green);
             }
             m_polyline      = new PolylineClass();
             m_point         = new PointClass();
             m_element_red   = null;
             m_element_green = null;
             p_activeView.Refresh();
         }
         //如果多边形为空,初始化所有变量
         else
         {
             if (m_element_red != null)
             {
                 m_graphicsContainer.DeleteElement(m_element_red);
             }
             if (m_element_green != null)
             {
                 m_graphicsContainer.DeleteElement(m_element_green);
             }
             m_hitElement      = null;
             m_DisplayFeedback = null;
             m_marker          = 0;
             m_polyline        = new PolylineClass();
             m_point           = new PointClass();
             m_element_red     = null;
             m_element_green   = null;
             axMapControl1.ActiveView.Refresh();
         }
     }
 }
Example #22
0
        public override void OnKeyDown(int keyCode, int shift)
        {
            // TODO:  添加 DrawPolyline.OnKeyDown 实现
            base.OnKeyDown(keyCode, shift);

            IPoint tempPoint = new PointClass();

            tempPoint.X = m_pLastPoint.X;
            tempPoint.Y = m_pLastPoint.Y;

            if (keyCode == 72)            //按H键,绘制圆弧
            {
                if (m_drawType == 1)
                {
                    m_drawState = "Line_Arc";                  //绘制直线……圆弧
                }
                else if (m_drawType == 2)
                {
                    m_drawState = "Arc_Arc";                  //绘制圆弧……圆弧
                }

                return;
            }

            if (keyCode == 76)            //按L键,绘制直线
            {
                if (m_drawType == 1)
                {
                    m_drawState = "Line_Line";;                  //绘制直线……直线
                }
                else if (m_drawType == 2)
                {
                    m_drawState = "Line_Line";                  //绘制圆弧……直线
                }

                return;
            }

            if (keyCode == 84)            //按T键,绘制圆弧……切线
            {
                m_drawState = "Arc_TLine";

                return;
            }

            if (keyCode == 85)            //按U键,回退
            {
                Undo();

                return;
            }

            if (keyCode == 78 && m_pUndoArray.Count >= 2)          //按N键,输入左折角
            {
                frmLeftCorner fromFixLeftCorner = new frmLeftCorner();
                fromFixLeftCorner.ShowDialog();

                return;
            }

            if (keyCode == 79 && m_bInUse)            //按(O)orientation键,输入方向
            {
                frmFixAzim fromFixAzim = new frmFixAzim();
                fromFixAzim.ShowDialog();

                return;
            }

            if (keyCode == 68 && m_bInUse)            //按D键,输入固定长度
            {
                frmFixLength fromFixLength = new frmFixLength();
                fromFixLength.ShowDialog();

                return;
            }


            if (keyCode == 70 && m_bInUse)            //按F键,输入长度+方位角
            {
                frmLengthAzim.m_pPoint = tempPoint;
                frmLengthAzim fromLengthDirect = new frmLengthAzim();
                fromLengthDirect.ShowDialog();

                if (m_bInputWindowCancel == false)               //若用户没用取消输入
                {
                    DrawPolylineMouseDown(m_pAnchorPoint, m_drawState);
                }

                return;
            }

            if (keyCode == 65)             //按A键,输入绝对坐标
            {
                frmAbsXYZ.m_pPoint = m_pAnchorPoint;
                frmAbsXYZ formXYZ = new frmAbsXYZ();
                formXYZ.ShowDialog();
                if (m_bInputWindowCancel == false)               //若用户没用取消输入
                {
                    DrawPolylineMouseDown(m_pAnchorPoint, m_drawState);
                }

                return;
            }

            if (keyCode == 82 && m_bInUse)            //按R键,输入相对坐标
            {
                frmRelaXYZ.m_pPoint = tempPoint;      // m_pToPoint;
                frmRelaXYZ formRelaXYZ = new frmRelaXYZ();
                formRelaXYZ.ShowDialog();

                if (m_bInputWindowCancel == false)               //若用户没用取消输入
                {
                    DrawPolylineMouseDown(m_pAnchorPoint, m_drawState);
                }

                return;
            }

            if (keyCode == 80 && m_bInUse)            //按P键,生成平行线
            {
                m_pSegment  = null;
                m_bKeyCodeP = true;

                return;
            }

            if (keyCode == 83 && m_pUndoArray.Count >= 2)          //按S键,生成直角
            {
                m_bkeyCodeS = true;
                if (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    m_pLastFeedback = new NewLineFeedbackClass();
                    m_pLastLineFeed = (INewLineFeedback)m_pLastFeedback;
                    IPoint pStartPoint = ((PointStruct)m_pUndoArray.get_Element(0)).Point;
                    m_pLastLineFeed.Start(pStartPoint);
                }

                return;
            }

            if (keyCode == 67 && m_pUndoArray.Count >= 4)          //按C键,封闭结束绘制
            {
                IPoint pStartPoint = new PointClass();
                IPoint pEndPoint   = new PointClass();
                pStartPoint = ((PointStruct)m_pUndoArray.get_Element(0)).Point;
                pEndPoint   = ((PointStruct)m_pUndoArray.get_Element(m_pUndoArray.Count - 1)).Point;

                AddPointUndoArray(pEndPoint, 1, ref m_pUndoArray);
                AddPointUndoArray(pStartPoint, 1, ref m_pUndoArray);

                EndDrawPolyline();

                return;
            }


            if ((keyCode == 69 || keyCode == 13 || keyCode == 32) && m_bInUse)            //按E键、ENTER 键、SPACEBAR 键结束绘制
            {
                EndDrawPolyline();

                return;
            }

            if (keyCode == 27)             //ESC 键,取消所有操作
            {
                Reset();

                this.Stop();
                WSGRI.DigitalFactory.Commands.ICommand command = DFApplication.Application.GetCommand("WSGRI.DigitalFactory.DF2DControl.cmdPan");
                if (command != null)
                {
                    command.Execute();
                }

                return;
            }
        }
        private void EditMouseUp(IPoint pPnt)
        {
            IPolygon       pPolyResult;
            IPolyline      pPolylineResult;
            IFeatureCursor pFeatureCursor;
            IFeature       pFeature;
            IFeatureLayer  pFeatLyr = m_EngineEditLayers.TargetLayer;

            //检查编辑的地物
            if (m_editDispFeed != null)
            {
                switch (m_pHitElem.Geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryLine:
                case esriGeometryType.esriGeometryPolyline:
                    pPolylineResult = m_polylineMvPtFeed.Stop();
                    //作有效性检查
                    if ((pPolylineResult != null))
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolylineResult;

                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolylineResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        EditVertexClass.ShowAllVertex(pFeatLyr);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                case esriGeometryType.esriGeometryEnvelope:
                    //得到反馈的结果
                    pPolyResult = m_polyMvPtFeed.Stop();
                    //作有效性检查
                    if (pPolyResult != null)
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolyResult;
                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolyResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon ||
                            pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                        {
                            EditVertexClass.ShowAllVertex(pFeatLyr);
                        }
                    }
                    IFeature pTempParcel;
                    //定义存储多边形要素的局部变量
                    IPoint pDestPoint;
                    //定义节点移动的目标位置
                    pDestPoint = pPnt;
                    IZAware pZAware = pDestPoint as IZAware;
                    pZAware.ZAware = true;
                    pDestPoint.Z   = 0;
                    //所有包含该节点的多边形都进行操作
                    for (int i = 0; i <= EditVertexClass.m_featArray.Count - 1; i++)
                    {
                        pTempParcel = EditVertexClass.m_featArray.get_Element(i) as IFeature;
                        //记录节点序号
                        int pIndex = 0;
                        pIndex = EditVertexClass.GetVertexIndex(m_fromPoint, pTempParcel.Shape);
                        if (!(pIndex == -2))
                        {
                            ITopologicalOperator pTopoOpt         = default(ITopologicalOperator);
                            IPolygon             pPolygon         = default(IPolygon);
                            IPointCollection     pPolygonPointCol = default(IPointCollection);
                            pPolygonPointCol = pTempParcel.ShapeCopy as IPointCollection;
                            pPolygonPointCol.UpdatePoint(pIndex, pDestPoint);
                            pPolygon = pPolygonPointCol as IPolygon;
                            pPolygon.Close();
                            pTopoOpt = pPolygon as ITopologicalOperator;
                            pTopoOpt.Simplify();
                            pTempParcel.Shape = pPolygon;
                            pTempParcel.Store();
                        }
                    }
                    EditVertexClass.m_featArray.RemoveAll();
                    break;
                }

                //释放内存
                m_polyMvPtFeed     = null;
                m_polylineMvPtFeed = null;
                m_editDispFeed     = null;
                m_pHitElem         = null;
                //刷新地图
                m_activeView.Refresh();
            }
        }
Example #24
0
 private void TryTrim(IPoint point)
 {
     if (this.idisplayFeedback_0 != null)
     {
         IEnvelope ienvelope_ = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
         this.idisplayFeedback_0 = null;
         this.double_1           = point.X;
         //this.iapplication_0.ShowCommandString("找到" + _context.FocusMap.SelectionCount.ToString() + "个对象", CommandTipsType.CTTLog);
         double double_ = Common.ConvertPixelsToMapUnits(_context.FocusMap as IActiveView, 6.0);
         System.Collections.Generic.IList <IFeature> intersectsLineFeatures =
             Yutai.ArcGIS.Common.Editor.Editor.GetIntersectsLineFeatures(_context.FocusMap, ienvelope_);
         IWorkspaceEdit workspaceEdit = null;
         for (int i = 0; i < intersectsLineFeatures.Count; i++)
         {
             IWorkspaceEdit workspaceEdit2 =
                 (intersectsLineFeatures[i].Class as IDataset).Workspace as IWorkspaceEdit;
             if (workspaceEdit2.IsBeingEdited())
             {
                 if (workspaceEdit == null)
                 {
                     workspaceEdit = workspaceEdit2;
                     workspaceEdit.StartEditOperation();
                 }
                 this.method_0(ienvelope_, double_, intersectsLineFeatures[i]);
             }
         }
         if (workspaceEdit != null)
         {
             workspaceEdit.StopEditOperation();
             _context.ActiveView.Refresh();
         }
     }
     else
     {
         double        double_ = Common.ConvertPixelsToMapUnits(_context.FocusMap as IActiveView, 6.0);
         IFeatureLayer layer;
         IFeature      hitLineFeature = Yutai.ArcGIS.Common.Editor.Editor.GetHitLineFeature(_context.FocusMap, point,
                                                                                            double_, out layer);
         if (hitLineFeature != null)
         {
             IPolyline polyline = Yutai.ArcGIS.Common.Editor.Editor.TrimPolyLine(_context.FocusMap,
                                                                                 hitLineFeature.Shape, point, double_);
             if (polyline != null && !polyline.IsEmpty && (polyline as IPointCollection).PointCount > 1)
             {
                 (polyline as ITopologicalOperator).Simplify();
                 IWorkspaceEdit workspaceEdit = (hitLineFeature.Class as IDataset).Workspace as IWorkspaceEdit;
                 workspaceEdit.StartEditOperation();
                 hitLineFeature.Shape = polyline;
                 hitLineFeature.Store();
                 workspaceEdit.StopEditOperation();
                 _context.ActiveView.Refresh();
             }
             // this.ShowCommandLine();
         }
         else
         {
             this.idisplayFeedback_0         = new NewEnvelopeFeedback();
             this.idisplayFeedback_0.Display = (_context.FocusMap as IActiveView).ScreenDisplay;
             (this.idisplayFeedback_0 as INewEnvelopeFeedback).Start(point);
             //this.double_0 = point.X;
             //this.iapplication_0.ShowCommandString("指定下一个角点:", CommandTipsType.CTTCommandTip);
         }
     }
 }
 public override void OnKeyDown(int keyCode, int Shift)
 {
     if (keyCode == (int)Keys.Escape)
     {
         m_IsFirstPoint = true;
         m_pFeedback = null;
         m_bInUse = false;
         m_GeometryCollection = null;
         IGraphicsContainer pGra = m_pMapControl.Map as IGraphicsContainer;
         for (int i = 0; i < m_ElementArray.Count; i++)
         {
             pGra.DeleteElement(m_ElementArray.get_Element(i) as IElement);
         }
         m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
         m_ElementArray.RemoveAll();
     }
 }
Example #26
0
        /// <summary>
        /// 移动当前图层中鼠标击中地图对象的位置(开始移动)
        /// 建议在Map.MouseDown事件中调用本方法
        /// </summary>
        /// <param name="x">鼠标X坐标,屏幕坐标</param>
        /// <param name="y">鼠标Y坐标,屏幕坐标</param>
        /// <returns></returns>
        public bool MoveFeatureMouseDown(int x, int y)
        {
            try
            {
                m_pMap.ClearSelection();

                SelectMouseDown(x, y);
                IEnumFeature pSelected = (IEnumFeature)m_pMap.FeatureSelection;
                IFeature pFeature = pSelected.Next();
                if (pFeature == null) return false;

                IActiveView pActiveView = (IActiveView)m_pMap;
                IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

                IGeometry pGeom = pFeature.Shape;
                m_pEditFeature = pFeature;

                switch (pGeom.GeometryType)
                {
                    case esriGeometryType.esriGeometryPoint:
                        m_pFeedback = new MovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                        pPointMove.Start((IPoint)pGeom, pPoint);
                        break;
                    case esriGeometryType.esriGeometryPolyline:

                        m_pFeedback = new MoveLineFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        IMoveLineFeedback pLineMove = (IMoveLineFeedback)m_pFeedback;
                        pLineMove.Start((IPolyline)pGeom, pPoint);
                        break;
                    case esriGeometryType.esriGeometryPolygon:
                        m_pFeedback = new MovePolygonFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        IMovePolygonFeedback pPolyMove = (IMovePolygonFeedback)m_pFeedback;
                        pPolyMove.Start((IPolygon)pGeom, pPoint);
                        break;
                }
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                return false;
            }
        }
Example #27
0
        private void TryExtend(IPoint point)
        {
            bool isAddNode = false;

            if (this.idisplayFeedback_0 != null)
            {
                IEnvelope ienvelope_ = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
                this.idisplayFeedback_0 = null;
                this.double_1           = point.X;
                //this.iapplication_0.ShowCommandString("找到" + _context.FocusMap.SelectionCount.ToString() + "个对象", CommandTipsType.CTTLog);
                double num = Common.ConvertPixelsToMapUnits(_context.FocusMap as IActiveView, 6.0);
                System.Collections.Generic.IList <IFeature> intersectsLineFeatures =
                    Yutai.ArcGIS.Common.Editor.Editor.GetIntersectsLineFeatures(_context.FocusMap, ienvelope_);
                IWorkspaceEdit workspaceEdit = null;
                if (intersectsLineFeatures.Count > 0)
                {
                    isAddNode = MessageService.Current.Ask("在相交处产生交点吗?");
                }
                for (int i = 0; i < intersectsLineFeatures.Count; i++)
                {
                    IWorkspaceEdit workspaceEdit2 =
                        (intersectsLineFeatures[i].Class as IDataset).Workspace as IWorkspaceEdit;
                    if (workspaceEdit2.IsBeingEdited())
                    {
                        if (workspaceEdit == null)
                        {
                            workspaceEdit = workspaceEdit2;
                            workspaceEdit.StartEditOperation();
                        }
                        IPolyline polyline;
                        if (isAddNode == false)
                        {
                            polyline = Yutai.ArcGIS.Common.Editor.Editor.ExtendPolyLine(_context.FocusMap,
                                                                                        intersectsLineFeatures[i].Shape);
                        }
                        else
                        {
                            polyline = Yutai.ArcGIS.Common.Editor.Editor.ExtendPolyLineEx(_context.FocusMap,
                                                                                          intersectsLineFeatures[i].Shape);
                        }
                        if (polyline != null && !polyline.IsEmpty && (polyline as IPointCollection).PointCount > 1)
                        {
                            (polyline as ITopologicalOperator).Simplify();
                            intersectsLineFeatures[i].Shape = polyline;
                            intersectsLineFeatures[i].Store();
                        }
                    }
                }
                if (workspaceEdit != null)
                {
                    workspaceEdit.StopEditOperation();
                    _context.ActiveView.Refresh();
                }
            }
            else
            {
                double        num = Common.ConvertPixelsToMapUnits(_context.FocusMap as IActiveView, 6.0);
                IFeatureLayer layer;
                IFeature      hitLineFeature = Yutai.ArcGIS.Common.Editor.Editor.GetHitLineFeature(_context.FocusMap, point,
                                                                                                   num, out layer);
                if (hitLineFeature != null)
                {
                    isAddNode = MessageService.Current.Ask("在相交处产生交点吗?");

                    IPolyline polyline;
                    if (isAddNode == false)
                    {
                        polyline = Yutai.ArcGIS.Common.Editor.Editor.ExtendPolyLine(_context.FocusMap,
                                                                                    hitLineFeature.Shape);
                    }
                    else
                    {
                        polyline = Yutai.ArcGIS.Common.Editor.Editor.ExtendPolyLineEx(_context.FocusMap,
                                                                                      hitLineFeature.Shape);
                    }
                    if (polyline != null && !polyline.IsEmpty && (polyline as IPointCollection).PointCount > 1)
                    {
                        (polyline as ITopologicalOperator).Simplify();
                        IWorkspaceEdit workspaceEdit = (hitLineFeature.Class as IDataset).Workspace as IWorkspaceEdit;
                        workspaceEdit.StartEditOperation();
                        hitLineFeature.Shape = polyline;
                        hitLineFeature.Store();
                        workspaceEdit.StopEditOperation();
                        _context.ActiveView.Refresh();
                    }
                }
                else
                {
                    this.idisplayFeedback_0         = new NewEnvelopeFeedback();
                    this.idisplayFeedback_0.Display = (_context.FocusMap as IActiveView).ScreenDisplay;
                    (this.idisplayFeedback_0 as INewEnvelopeFeedback).Start(point);
                    this.double_0 = point.X;
                }
            }
        }
Example #28
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ModifyShape.OnMouseDown implementation

            m_MapControl.Map.ClearSelection();
            m_MapControl.ActiveView.Refresh();
            SelectMouseDown(X, Y);
            IEnumFeature pSelected = (IEnumFeature)m_MapControl.Map.FeatureSelection;
            IFeature pFeature = pSelected.Next();
            if (pFeature == null)
                return;
            IActiveView pActiveView = m_MapControl.ActiveView;
            IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            //���ò�׽�ݲ�
            double tol = ConvertPixelsToMapUnits(pActiveView, 4);
            IGeometry pGeom = pFeature.Shape;
            IObjectClass pObjectClass = pFeature.Class;
            m_EditFeature = pFeature;

            switch (pGeom.GeometryType)
            {
                case esriGeometryType .esriGeometryPoint :
                    m_Feedback = new MovePointFeedbackClass();
                    m_Feedback.Display = pActiveView.ScreenDisplay;
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_Feedback;
                    pPointMove.Start((IPoint)pGeom, pPoint);
                    break;
                case esriGeometryType .esriGeometryPolyline :
                    m_Feedback = new MoveLineFeedbackClass ();
                    m_Feedback.Display = pActiveView.ScreenDisplay;
                    IMoveLineFeedback m_MoveLineFeedback = (IMoveLineFeedback)m_Feedback;
                    m_MoveLineFeedback.Start((IPolyline)pGeom, pPoint);
                    break;
                case esriGeometryType .esriGeometryPolygon :
                    m_Feedback = new MovePolygonFeedbackClass();
                    m_Feedback.Display = pActiveView.ScreenDisplay;
                    IMovePolygonFeedback m_MovePolygonFeedback = (IMovePolygonFeedback)m_Feedback;
                    m_MovePolygonFeedback.Start((IPolygon)pGeom, pPoint);
                    break;
            }
        }
Example #29
0
File: 1.cs Project: trainsn/LBS
        /// <summary>
        /// 回退到前一个草图节点
        /// </summary>
        public override void VertexBack()
        {
            try
            {
                if (_pointColl == null || _pointColl.PointCount == 0)
                {
                    return;
                }

                if(_subType == 1)
                {
                    _geometryFeedback = new NewLineFeedbackClass();
                    (_geometryFeedback as INewLineFeedback).Display = myHook.ActiveView.ScreenDisplay;
                }
                else if(_subType == 2)
                {
                    _geometryFeedback = new NewPolygonFeedbackClass();
                    (_geometryFeedback as INewPolygonFeedback).Display = myHook.ActiveView.ScreenDisplay;
                }

                _startPoint = null;
                _endPoint = null;
                _geometry = null;//每次重设矩形

                if (_pointColl.PointCount == 1)
                {
                    _pointColl.RemovePoints(0, 1);
                    myHook.ActiveView.Refresh();
                }
                else if (_pointColl.PointCount > 1)
                {
                    int iCount = _pointColl.PointCount;
                    _pointColl.RemovePoints(iCount - 1, 1);
                    bool bIsFirst = true;

                    for (int i = 0; i < _pointColl.PointCount; i++)
                    {
                        if (bIsFirst)
                        {
                            _startPoint = _pointColl.get_Point(i);
                            if (_subType == 1)
                                (_geometryFeedback as INewLineFeedback).Start(_startPoint);
                            else if (_subType == 2)
                                (_geometryFeedback as INewPolygonFeedback).Start(_startPoint);

                            bIsFirst = false;
                        }
                        _endPoint = _pointColl.get_Point(i);
                        if (_endPoint != null)
                        {
                            if (_subType == 1)
                                (_geometryFeedback as INewLineFeedback).AddPoint(_endPoint);
                            else if (_subType == 2)
                                (_geometryFeedback as INewPolygonFeedback).AddPoint(_endPoint);
                        }
                    }
                }

                myHook.ActiveView.Refresh();
            }
            catch (System.Exception e)
            {
                throw new Exception(String.Format("回退到前一个草图节点失败!\n{0}", e.Message));
            }
        }
Example #30
0
        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ModifyShape.OnMouseUp implementation
            if (m_Feedback == null)
                return;
            IActiveView pActiveView = m_MapControl.ActiveView;
            IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            if (m_Feedback is IMovePointFeedback)
            {
                IMovePointFeedback pPointMove = (IMovePointFeedback)m_Feedback;
                IGeometry pGeometry = pPointMove.Stop();
                UpdateFeature(m_EditFeature, pGeometry);
            }
            else if (m_Feedback is IMoveLineFeedback) //�� �����ƶ�
            {
                IMoveLineFeedback pLineMove = (IMoveLineFeedback)m_Feedback;
                IGeometry pGeometry = pLineMove.Stop();
                UpdateFeature(m_EditFeature, pGeometry);

            }
            else if (m_Feedback is IMovePolygonFeedback)
            {
                IMovePolygonFeedback pPolygonMove = (IMovePolygonFeedback)m_Feedback;
                IGeometry pGeometry = pPolygonMove.Stop();
                UpdateFeature(m_EditFeature, pGeometry);

            }

            m_Feedback = null;
            pActiveView.Refresh();
        }
Example #31
0
        /// <summary>
        /// 鼠标点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            try
            {
                if (e.button == 1)//按左键的话
                {
                    IPoint pPoint = new PointClass();//在鼠标点击的位置生成一个点
                    pPoint.PutCoords(e.mapX, e.mapY);

                    if (this.btnNewPolyline.Checked)//画多义线
                    {
                        if (this.pDisplayFeedback == null)//如果是第一次点击,就建立第一个节点
                        {
                            this.pDisplayFeedback = new NewLineFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((INewLineFeedback)this.pDisplayFeedback).Start(pPoint);
                        }
                        else//如果不是第一次点击,就添加节点
                        {
                            ((INewLineFeedback)this.pDisplayFeedback).AddPoint(pPoint);
                        }
                    }
                    else if (this.btnLineMovePoint.Checked)//移动多义线节点
                    {
                        IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolyline);
                        if (pElement != null)
                        {
                            IPolyline pPolyline = pElement.Geometry as IPolyline;
                            IHitTest pHitTest = pPolyline as IHitTest;
                            IPoint hitPoint = new PointClass();
                            double distance = 0;
                            bool isOnRightSide = false;
                            int hitPartIndex = 0;
                            int hitSegmentIndex = 0;
                            bool isHit = pHitTest.HitTest(pPoint, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref distance, ref hitPartIndex, ref hitSegmentIndex, ref isOnRightSide);
                            if (isHit)
                            {
                                this.pDisplayFeedback = new LineMovePointFeedbackClass();
                                this.pDisplayFeedback.Display = this.pScreenDisplay;
                                ((ILineMovePointFeedback)this.pDisplayFeedback).Start(pPolyline, hitSegmentIndex, pPoint);
                            }
                        }
                    }
                    else if (this.btnNewCircle.Checked)//画圆
                    {
                        this.pDisplayFeedback = new NewCircleFeedbackClass();
                        this.pDisplayFeedback.Display = this.pScreenDisplay;
                        ((INewCircleFeedback)this.pDisplayFeedback).Start(pPoint);
                    }
                    else if (this.btnNewEnvelope.Checked)//画矩形
                    {
                        this.pDisplayFeedback = new NewEnvelopeFeedbackClass();
                        this.pDisplayFeedback.Display = this.pScreenDisplay;
                        ((INewEnvelopeFeedback)this.pDisplayFeedback).Constraint = esriEnvelopeConstraints.esriEnvelopeConstraintsNone;
                        ((INewEnvelopeFeedback)this.pDisplayFeedback).Start(pPoint);
                    }
                    else if (this.btnNewPolygon.Checked)//画多边形
                    {
                        if (this.pDisplayFeedback == null)//如果是第一次点击,就建立第一个节点
                        {
                            this.pDisplayFeedback = new NewPolygonFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((INewPolygonFeedback)this.pDisplayFeedback).Start(pPoint);
                        }
                        else//如果不是第一次点击,就添加节点
                        {
                            ((INewPolygonFeedback)this.pDisplayFeedback).AddPoint(pPoint);
                        }
                    }
                    else if (this.btnPolygonMovePoint.Checked)//移动多边形节点
                    {
                        IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolygon);
                        if (pElement != null)
                        {
                            IPolygon pPolygon = pElement.Geometry as IPolygon;
                            IHitTest pHitTest = pPolygon as IHitTest;
                            IPoint hitPoint = new PointClass();
                            double distance = 0;
                            bool isOnRightSide = true;
                            int hitPartIndex = 0;
                            int hitSegmentIndex = 0;
                            bool isHit = pHitTest.HitTest(pPoint, this.axMapControl1.ActiveView.Extent.Width / 100, esriGeometryHitPartType.esriGeometryPartVertex, hitPoint, ref distance, ref hitPartIndex, ref hitSegmentIndex, ref isOnRightSide);
                            if (isHit)
                            {
                                this.pDisplayFeedback = new PolygonMovePointFeedbackClass();
                                this.pDisplayFeedback.Display = this.pScreenDisplay;
                                ((IPolygonMovePointFeedback)this.pDisplayFeedback).Start(pPolygon, hitSegmentIndex, pPoint);
                            }
                        }
                    }
                    else if (this.btnNewBezierCurve.Checked)//新建Bezier曲线
                    {
                        if (this.pDisplayFeedback == null)//如果是第一次点击
                        {
                            this.pDisplayFeedback = new NewBezierCurveFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((INewBezierCurveFeedback)this.pDisplayFeedback).Start(pPoint);
                        }
                        else//如果不是第一次点击
                        {
                            ((INewBezierCurveFeedback)this.pDisplayFeedback).AddPoint(pPoint);
                        }
                    }
                    else if (this.btnMoveGeometry.Checked)//移动几何对象
                    {
                        this.pEnumElement = this.pGraphicContainer.LocateElements(pPoint, this.pActiveView.Extent.Width / 100);
                        if (this.pEnumElement != null)
                        {
                            this.pDisplayFeedback = new MoveGeometryFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;

                            IElement pElement;
                            this.pEnumElement.Reset();
                            //需要逐个逐个添加Geometry
                            for (pElement = this.pEnumElement.Next(); pElement != null; pElement = this.pEnumElement.Next())
                            {
                                ((IMoveGeometryFeedback)this.pDisplayFeedback).AddGeometry(pElement.Geometry);
                            }
                            ((IMoveGeometryFeedback)this.pDisplayFeedback).Start(pPoint);
                            this.moveGeometryStartPoint = pPoint;
                        }
                    }
                    else if (this.btnStretchLine.Checked)//拉伸多义线
                    {
                        IElement pElement = this.getElement(pPoint, esriGeometryType.esriGeometryPolyline);
                        if (pElement != null)
                        {
                            IPolyline pPolyline = pElement.Geometry as IPolyline;
                            this.pDisplayFeedback = new StretchLineFeedbackClass();
                            this.pDisplayFeedback.Display = this.pScreenDisplay;
                            ((IStretchLineFeedback)this.pDisplayFeedback).Anchor = pPolyline.FromPoint;
                            ((IStretchLineFeedback)this.pDisplayFeedback).Start(pPolyline, pPoint);
                        }
                    }

                }
                else if (e.button == 2)//按右键的就把画面清空
                {
                    if (this.pDisplayFeedback == null)
                    {
                        this.pGraphicContainer.DeleteAllElements();
                        this.axMapControl1.Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #32
0
        /// <summary>
        /// �༭��ǰͼ���������еĵ�ͼ����(��ʼ�༭),
        /// ���Ϊ����󣬿ɽ���λ���ƶ������Ϊ�߶��������󣬿ɽ��нڵ�༭
        /// ������Map.MouseDown�¼��е��ñ�����
        /// </summary>
        /// <param name="x">���X���꣬��Ļ����</param>
        /// <param name="y">���Y���꣬��Ļ����</param>
        /// <returns></returns>
        public void EditFeatureMouseDown(int x, int y)
        {
            IGeometryCollection pGeomColn ;
            IPointCollection pPointColn;
            IObjectClass pObjectClass ;
            IFeature pFeature;
            IGeometry pGeom ;

            IPath pPath ;
            IPoint pHitPoint =null ;
            IPoint pPoint =null;
            Double hitDist =0.0;
            double tol;
            int vertexIndex =0;
            int numVertices;
            int partIndex =0;
            bool vertex = false;

            try
            {

                m_pMap.ClearSelection();

                // ȡ�������еĵ�һ������
                SelectMouseDown(x, y);
                IEnumFeature pSelected =(IEnumFeature) m_pMap.FeatureSelection;
                pFeature = pSelected.Next();
                if (pFeature ==null ) return;

                IActiveView pActiveView =(IActiveView) m_pMap;
                pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

                // �ڵ�ռ��ѯ�ݲ�
                tol = ConvertPixelsToMapUnits(pActiveView, 4.0);

                pGeom = pFeature.Shape;
                pObjectClass = pFeature.Class;
                m_pEditFeature = pFeature;
                object objNull = Missing.Value ;
                object objBefore, objAfter;

                switch (pGeom.GeometryType)
                {
                    case esriGeometryType.esriGeometryPoint:
                        m_pFeedback = new MovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        IMovePointFeedback pPointMove =(IMovePointFeedback) m_pFeedback;
                        pPointMove.Start((IPoint)pGeom, pPoint);
                        break;
                    case esriGeometryType.esriGeometryPolyline:
                        if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist,out partIndex,out vertexIndex,out vertex))
                        {
                            if (!vertex)
                            {
                                pGeomColn =(IGeometryCollection) pGeom;
                                pPath =(IPath) pGeomColn.get_Geometry(partIndex);
                                pPointColn =(IPointCollection) pPath;
                                numVertices = pPointColn.PointCount;

                                if (vertexIndex == 0)
                                {
                                    objBefore = (object) (vertexIndex+1);
                                    pPointColn.AddPoint(pPoint,ref objBefore,ref objNull);
                                }
                                else
                                {
                                    objAfter = (object) vertexIndex;
                                    pPointColn.AddPoint( pPoint,ref objNull , ref objAfter);
                                }

                                TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist,out partIndex,out vertexIndex,out vertex);
                            }
                            m_pFeedback = new LineMovePointFeedbackClass();
                            m_pFeedback.Display = pActiveView.ScreenDisplay;
                            ILineMovePointFeedback pLineMove =(ILineMovePointFeedback) m_pFeedback;
                            pLineMove.Start((IPolyline)pGeom, vertexIndex, pPoint);

            //							m_pSelectionTracker = new LineTrackerClass();
            //							m_pSelectionTracker.Display = pActiveView.ScreenDisplay ;
            //							m_pSelectionTracker.Geometry = pGeom;
            //							m_pSelectionTracker.ShowHandles = true;
            //							m_pSelectionTracker.QueryResizeFeedback(ref m_pFeedback);
            //							m_pSelectionTracker.OnMouseDown(1,0,x,y);
                        }
                        else
                        {
                            return;
                        }
                        break;
                    case esriGeometryType.esriGeometryPolygon:
                        if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist,out partIndex,out vertexIndex,out vertex))
                        {
                            if (!vertex)
                            {
                                pGeomColn =(IGeometryCollection) pGeom;
                                pPath =(IPath) pGeomColn.get_Geometry(partIndex);
                                pPointColn =(IPointCollection) pPath;
                                numVertices = pPointColn.PointCount;

                                if (vertexIndex == 0)
                                {
                                    objBefore = (object) (vertexIndex + 1);
                                    pPointColn.AddPoint(pPoint,ref objBefore,ref objNull);
                                }
                                else
                                {
                                    objAfter = (object) vertexIndex;
                                    pPointColn.AddPoint( pPoint,ref objNull , ref objAfter);
                                }

                                TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist,out partIndex,out vertexIndex,out vertex);
                            }

                            m_pFeedback = new PolygonMovePointFeedbackClass();
                            m_pFeedback.Display = pActiveView.ScreenDisplay;
                            IPolygonMovePointFeedback pPolyMove =(IPolygonMovePointFeedback) m_pFeedback;
                            pPolyMove.Start((IPolygon) pGeom, vertexIndex, pPoint);
                        }
                        else
                        {
                            return ;
                        }
                        break;
                }
                return  ;
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                return ;
            }
        }
Example #33
0
 private void btnNewPolyline_Click(object sender, EventArgs e)
 {
     foreach (ToolStripItem i in this.toolStrip1.Items)
     {
         ((ToolStripButton)i).Checked = false;
     }
     ((ToolStripButton)sender).Checked = true;
     this.pDisplayFeedback = null;
 }
Example #34
0
        /// <summary>
        /// ��ɵ�ͼ�����ƶ���ȡ���ƶ���Ķ��󣬲�������µ�ͼ����
        /// ������Map.MouseUp�¼��е��ñ�����
        /// </summary>
        public void MoveFeatureEnd()
        {
            IGeometry pGeometry;

            try
            {
                if (m_pFeedback ==null) return;

                if (m_pFeedback is IMovePointFeedback)
                {
                    IMovePointFeedback pPointMove =(IMovePointFeedback) m_pFeedback;
                    pGeometry = pPointMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is IMoveLineFeedback)
                {
                    IMoveLineFeedback pLineMove =(IMoveLineFeedback) m_pFeedback;
                    pGeometry = pLineMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is IMovePolygonFeedback)
                {
                    IMovePolygonFeedback pPolyMove =(IMovePolygonFeedback) m_pFeedback;
                    pGeometry = pPolyMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }

                m_pFeedback = null;
                IActiveView pActiveView = (IActiveView) m_pMap;
                pActiveView.Refresh();
            }
            catch( Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
Example #35
0
        private void DrawRectRelative2PMouseDown(IPoint pPoint)
        {
            IPoint tempPoint = new PointClass();

            m_mouseDownCount = m_mouseDownCount + 1;

            if (m_mouseDownCount < 3) //点击鼠标次数小于3时
            {
                //绘制线
                if (m_bInUse == false)
                {
                    m_pFeedback = new NewLineFeedbackClass();
                    m_pLineFeed = (INewLineFeedback)m_pFeedback;
                    m_pLineFeed.Start(pPoint);

                    tempPoint.X = pPoint.X;
                    tempPoint.Y = pPoint.Y;

                    CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, pPoint);
                    m_pUndoArray.Add(tempPoint);//将第一个点保存到变量

                    m_pLastPoint = pPoint;
                    m_bInUse     = true;
                }
                else
                {
                    m_pLineFeed = (INewLineFeedback)m_pFeedback;
                    tempPoint.X = m_pAnchorPoint.X;
                    tempPoint.Y = m_pAnchorPoint.Y;
                    m_pLineFeed.AddPoint(tempPoint);

                    CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, tempPoint);
                    m_pUndoArray.Add(tempPoint); //将第二个点保存到变量
                }

                if (m_pFeedback != null)
                {
                    m_pFeedback.Display = m_pActiveView.ScreenDisplay;
                }

                if ((m_bFixLength == true) && (m_bFixDirection == false))  //可以给定一个长度值
                {
                    m_bFixLength = false;
                }
                else if ((m_bFixLength == false) && (m_bFixDirection == true)) //可以给定一个固定方向值
                {
                    m_bFixDirection = false;
                }
                else if ((m_bFixLength == true) && (m_bFixDirection == true))
                {
                    m_bFixLength    = false;
                    m_bFixDirection = false;
                }
            }//m_mouseDownCount < 3
            else if (m_mouseDownCount == 3) //点击鼠标次数等于3后,停止绘制
            {
                EndDrawRectRelative2P();
            }//m_mouseDownCount = 3

            m_pSegment = null;            //清空捕捉到的片断
        }
Example #36
0
        /// <summary>
        /// ����½�����ȡ�û��ƵĶ��󣬲���ӵ�ͼ����
        /// ������Map.DblClick��Map.MouseDown(Button = 2)�¼��е��ñ�����
        /// </summary>
        public void NewFeatureEnd()
        {
            IGeometry pGeom = null;
            IPointCollection pPointCollection;

            try
            {
                if (m_pFeedback is INewMultiPointFeedback)
                {
                    INewMultiPointFeedback pMPFeed =(INewMultiPointFeedback) m_pFeedback;
                    pMPFeed.Stop();
                    pGeom =(IGeometry) m_pPointCollection;
                }
                else if (m_pFeedback is INewLineFeedback)
                {
                    INewLineFeedback pLineFeed =(INewLineFeedback) m_pFeedback;

                    pLineFeed.AddPoint(m_pPoint);
                    IPolyline pPolyLine = pLineFeed.Stop();

                    pPointCollection =(IPointCollection) pPolyLine;
                    if (pPointCollection.PointCount < 2)
                        MessageBox.Show("�������������ڵ�");
                    else
                        pGeom =(IGeometry) pPointCollection;
                }
                else if (m_pFeedback is INewPolygonFeedback)
                {
                    INewPolygonFeedback pPolyFeed =(INewPolygonFeedback) m_pFeedback;
                    pPolyFeed.AddPoint(m_pPoint);

                    IPolygon pPolygon ;
                    pPolygon = pPolyFeed.Stop();
                    if (pPolygon !=null)
                    {
                        pPointCollection =(IPointCollection) pPolygon;
                        if (pPointCollection.PointCount < 3)
                            MessageBox.Show("�������������ڵ�");
                        else
                            pGeom =(IGeometry) pPointCollection;
                    }
                }

                CreateFeature(pGeom);
                m_pFeedback = null;
                m_bInUse = false;
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
Example #37
0
        public override void OnKeyDown(int keyCode, int shift)
        {
            // TODO:  添加 DrawBeizerCurve.OnKeyDown 实现
            base.OnKeyDown(keyCode, shift);


            if (keyCode == 85 && m_bInUse)            //按U键,回退
            {
                Undo();

                return;
            }

            if (keyCode == 78 && m_pUndoArray.Count >= 2)           //按N键输入折角方向
            {
                frmLeftCorner fromFixLeftCorner = new frmLeftCorner();
                fromFixLeftCorner.ShowDialog();

                return;
            }

            if (keyCode == 79 && m_bInUse)            //按(O)orientation键输入固定方向
            {
                frmFixAzim fromFixAzim = new frmFixAzim();
                fromFixAzim.ShowDialog();

                return;
            }

            if (keyCode == 68 && m_bInUse)            //按D键输入固定长度
            {
                frmFixLength fromFixLength = new frmFixLength();
                fromFixLength.ShowDialog();

                return;
            }

            if (keyCode == 70 && m_bInUse)            //按F键输入长度+方位角
            {
                frmLengthAzim.m_pPoint = m_pLastPoint;
                frmLengthAzim fromLengthDirect = new frmLengthAzim();
                fromLengthDirect.ShowDialog();
                if (m_bInputWindowCancel == false)               //若用户没用取消输入
                {
                    DrawBezierCurveMouseDown(m_pAnchorPoint);
                }

                return;
            }

            if (keyCode == 65)             //按A键输入绝对坐标
            {
                frmAbsXYZ.m_pPoint = m_pAnchorPoint;
                frmAbsXYZ formXYZ = new frmAbsXYZ();
                formXYZ.ShowDialog();
                if (m_bInputWindowCancel == false)               //若用户没用取消输入
                {
                    DrawBezierCurveMouseDown(m_pAnchorPoint);
                }

                return;
            }

            if (keyCode == 82 && m_bInUse)            //按R键输入相对坐标
            {
                frmRelaXYZ.m_pPoint = m_pLastPoint;
                frmRelaXYZ formRelaXYZ = new frmRelaXYZ();
                formRelaXYZ.ShowDialog();
                if (m_bInputWindowCancel == false)               //若用户没用取消输入
                {
                    DrawBezierCurveMouseDown(m_pAnchorPoint);
                }

                return;
            }


            if ((keyCode == 69 || keyCode == 13 || keyCode == 32) && m_bInUse && m_pUndoArray.Count >= 2)          //按E键、ENTER 键、SPACEBAR 键结束绘制
            {
                EndDrawBezierCurve();

                return;
            }

            if (keyCode == 83 && m_pUndoArray.Count >= 2)          //按S键生成直角
            {
                m_bkeyCodeS = true;

                if (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    m_pLastFeedback = new NewLineFeedbackClass();
                    m_pLastLineFeed = (INewLineFeedback)m_pLastFeedback;
                    m_pLastLineFeed.Start((IPoint)m_pUndoArray.get_Element(0));
                }

                return;
            }

            if (keyCode == 80 && m_bInUse)            //按P键平行尺
            {
                m_pSegment  = null;
                m_bKeyCodeP = true;

                return;
            }

            if (keyCode == 67 && m_pUndoArray.Count >= 3)          //按C键封闭结束绘制
            {
                if (m_bInUse)
                {
                    m_pUndoArray.Add((IPoint)m_pUndoArray.get_Element(0));

                    EndDrawBezierCurve();
                }

                return;
            }

            if (keyCode == 27)             //ESC 键,取消所有操作
            {
                Reset();

                this.Stop();
                WSGRI.DigitalFactory.Commands.ICommand command = DFApplication.Application.GetCommand("WSGRI.DigitalFactory.DF2DControl.cmdPan");
                if (command != null)
                {
                    command.Execute();
                }

                return;
            }
        }
Example #38
0
        /// <summary>
        /// �½����󷽷�
        /// ��ǰͼ��Ϊ��ͼ��ʱ��ÿ����һ�ξ��µ�һ�������
        /// ��ǰͼ��Ϊ��ͼ�����ͼ��ʱ����һ�ε��ÿ�ʼ�½����󣬲���ӵ�ǰ�㣬
        /// �Ժ�ÿ����һ�Σ������¶��������һ����,����NewFeatureEnd������ɶ��󴴽�
        /// ��Map.MouseDown�¼��е��ñ�����
        /// </summary>
        /// <param name="x">���X���꣬��Ļ����</param>
        /// <param name="y">���Y���꣬��Ļ����</param>
        public void NewFeatureMouseDown( int x, int y)
        {
            INewPolygonFeedback pPolyFeed ;
            INewLineFeedback pLineFeed;

            try
            {
                if (m_pCurrentLayer == null ) return ;

                if (!(m_pCurrentLayer is IGeoFeatureLayer)) return ;

                IFeatureLayer pFeatureLayer =(IFeatureLayer) m_pCurrentLayer;
                if (pFeatureLayer.FeatureClass ==null ) return ;

                IActiveView pActiveView =(IActiveView) m_pMap;
                IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

                // ������¿�ʼ�����Ķ�������Ӧ�Ĵ���һ���µ�Feedback����
                // �������Ѵ��ڵ�Feedback�����мӵ�
                if (!m_bInUse)
                {
                    m_pMap.ClearSelection();  //�����ͼѡ�ж���

                    switch ( pFeatureLayer.FeatureClass.ShapeType)
                    {
                        case esriGeometryType.esriGeometryPoint:
                            CreateFeature( pPoint);

                            break;
                        case esriGeometryType.esriGeometryMultipoint:
                            m_bInUse = true;
                            m_pFeedback = new NewMultiPointFeedbackClass();
                            INewMultiPointFeedback pMPFeed =(INewMultiPointFeedback) m_pFeedback;
                            m_pPointCollection = new MultipointClass();
                            pMPFeed.Start(m_pPointCollection, pPoint);
                            break;
                        case esriGeometryType.esriGeometryPolyline:
                            m_bInUse = true;
                            m_pFeedback = new  NewLineFeedbackClass();
                            pLineFeed = (INewLineFeedback) m_pFeedback;
                            pLineFeed.Start(pPoint);
                            break;
                        case esriGeometryType.esriGeometryPolygon:
                            m_bInUse = true;
                            m_pFeedback = new NewPolygonFeedbackClass();
                            pPolyFeed = (INewPolygonFeedback) m_pFeedback;
                            pPolyFeed.Start(pPoint);
                            break;
                    }

                    if (m_pFeedback != null)
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                }
                else
                {
                    if (m_pFeedback is INewMultiPointFeedback)
                    {
                        object obj = Missing.Value ;
                        m_pPointCollection.AddPoint(pPoint,ref obj,ref obj);
                    }
                    else if (m_pFeedback is INewLineFeedback)
                    {
                        pLineFeed =(INewLineFeedback) m_pFeedback;
                        pLineFeed.AddPoint(pPoint);
                    }
                    else if (m_pFeedback is INewPolygonFeedback)
                    {
                        pPolyFeed = (INewPolygonFeedback) m_pFeedback;
                        pPolyFeed.AddPoint(pPoint);
                    }
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button == 2) return;

            INewLineFeedback pLineFeed;
            if (m_point_From == null)
            {
                m_point_From = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

                //��קЧ��
                m_pFeedback = new NewLineFeedbackClass();
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.Start(m_point_From);
                if (m_pFeedback != null)
                    m_pFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;
            }
            else if (m_point_To == null)
            {
                m_point_To = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                //�����ק��
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.AddPoint(m_point_To);
            }
            else if (m_point_Center == null)
            {
                m_point_Center = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                //�����ק��
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.AddPoint(m_point_Center);
                pLineFeed.Stop();

                ESRI.ArcGIS.Geometry.ICircularArc circularArc = new ESRI.ArcGIS.Geometry.CircularArcClass();
                circularArc.PutCoords(m_point_Center, m_point_From, m_point_To, ESRI.ArcGIS.Geometry.esriArcOrientation.esriArcClockwise);
                DrawCircleByCenterAndRadius(m_pCurrentLayer, circularArc, m_hookHelper.ActiveView.ScreenDisplay);
                //��������
                m_point_From = null;
                m_point_To = null;
                m_point_Center = null;
            }
        }
Example #40
0
        private void CalculateCornerMouseDown(IPoint pPoint)
        {
            IGeometry pGeom = null;

            if (!m_bInUse) //如果命令没有使用
            {
                m_pPoint1    = pPoint;
                m_pLastPoint = pPoint;
                m_pRecordPointArray.Add(m_pPoint1);
                m_bInUse = true;

                m_pFeedback = new NewLineFeedbackClass();
                m_pLineFeed = (INewLineFeedback)m_pFeedback;
                m_pLineFeed.Start(pPoint);
                if (m_pFeedback != null)
                {
                    m_pFeedback.Display = m_pActiveView.ScreenDisplay;
                }

                CommonFunction.DrawPointSMSSquareSymbol(m_pMapControl, m_pPoint1);
            }
            else //如果命令正在使用
            {
                m_pPoint2 = pPoint;
                m_pRecordPointArray.Add(pPoint);
                m_bInUse = true;

                m_pLineFeed.AddPoint(pPoint);

                CommonFunction.DrawPointSMSSquareSymbol(m_pMapControl, m_pPoint2);
                if (m_pRecordPointArray.Count > 2)
                {
                    IPolyline pPolyline;
                    pPolyline = (IPolyline)CommonFunction.MadeSegmentCollection(ref m_pRecordPointArray);
                    pGeom     = (IGeometry)pPolyline;
                    CommonFunction.AddElement(m_pMapControl, pGeom);

                    double dblZimuth = CommonFunction.GetAngleZuo_P123(m_pPoint1, (IPoint)m_pRecordPointArray.get_Element(1), m_pPoint2);
                    dblZimuth = CommonFunction.RadToDeg(dblZimuth);

                    strResult1 = dblZimuth.ToString(".#####") + "(°)";

                    strResult2 = "X=" + m_pPoint1.X.ToString(".##") + "; " + "Y=" + m_pPoint1.Y.ToString(".##");


                    strResult3 = "X=" + ((IPoint)m_pRecordPointArray.get_Element(1)).X.ToString(".##") + ";  " + "Y=" + ((IPoint)m_pRecordPointArray.get_Element(1)).Y.ToString(".##");

                    strResult4 = "X=" + m_pPoint2.X.ToString(".##") + "; " + "Y=" + m_pPoint2.Y.ToString(".##");


                    if (strResult1 != null && strResult2 != null && strResult3 != null && strResult4 != null)
                    {
                        FrmIncludedAngle frmIncludedAngle = FrmIncludedAngle.Instance();
                        frmIncludedAngle.ShowDialog();
                    }
                    if (m_pRecordPointArray.Count != 0)
                    {
                        m_pRecordPointArray.RemoveAll();
                    }
                    m_bInUse = false;
                }
            }
            /* m_bInUse = false;*/
        }
Example #41
0
        private void DrawCircle3PMouseDown(IPoint pPoint, int shift)
        {
            IGeometry pGeom = null;
            IPolyline pPolyline;
            IPolygon  pPolygon;
            IPoint    pCenterPoint = new PointClass();

            if (!m_bFirst)           //如果命令没有使用
            {
                     m_pPoint1 = pPoint;
                m_bFirst  = true;
                m_bSecond = false;

                m_pFeedback         = new NewLineFeedbackClass();
                m_pLineFeed         = (INewLineFeedback)m_pFeedback;
                m_pLineFeed.Display = m_pActiveView.ScreenDisplay;
                m_pLineFeed.Start(pPoint);

                CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, m_pPoint1);
            }
            else if (!m_bSecond)            //如果命令正在使用
            {
                m_pPoint2 = pPoint;
                m_bSecond = true;
                m_bThree  = false;
                CommonFunction.DrawPointSMSSquareSymbol(m_MapControl, m_pPoint2);

                m_pLineFeed.Stop();
                m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pEnvelope);

                m_pFeedback = new NewCircleFeedbackClass();
            }
            else if (!m_bThree)
            {
                m_pPoint3 = m_pPoint;
                m_bFirst  = false;
                m_bThree  = true;

                m_pCenterPoint = CommonFunction.GetCenter_P123(m_pPoint1, m_pPoint2, pPoint);

                m_pCircleFeed         = (NewCircleFeedbackClass)m_pFeedback;
                m_pCircleFeed.Display = m_pActiveView.ScreenDisplay;

                m_pCircleFeed.Stop();
                m_pCircleFeed.Start(m_pCenterPoint);
                m_pFeedback.MoveTo(pPoint);

                ICircularArc pCircularArc = new CircularArcClass();
                pCircularArc = m_pCircleFeed.Stop();

                pCenterPoint = pCircularArc.CenterPoint;

                if (shift == 1)                //若果按住shift健弹出对话框,让用户修改圆周上的坐标值
                {
                    frmCircle3P formCircle3P = new frmCircle3P();
                    formCircle3P.ShowDialog();

                    if (m_bModify) //修改坐标值了
                    {
                                   //计算圆心坐标
                            pCenterPoint = CommonFunction.GetCenter_P123(m_pPoint1, m_pPoint2, m_pPoint3);
                        m_bModify = false;
                    }
                }

                switch (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType)
                {
                case  esriGeometryType.esriGeometryPolyline:
                    pPolyline = CommonFunction.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise);
                    pGeom     = pPolyline;
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    pPolyline = CommonFunction.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise);
                    pPolygon  = CommonFunction.PolylineToPolygon(pPolyline);
                    pGeom     = pPolygon;
                    break;

                default:
                    break;
                }                //end switch

                m_pEnvelope = pGeom.Envelope;
                if (m_pEnvelope != null && !m_pEnvelope.IsEmpty)
                {
                    m_pEnvelope.Expand(10, 10, false);
                }
                ;
                CommonFunction.CreateFeature(m_App.Workbench, pGeom, m_FocusMap, m_CurrentLayer);

                Reset();
            }            // end if(!m_bThree)

            m_pLastPoint = pPoint;

            m_pSegment = null;
        }
Example #42
0
        public override void OnDblClick()
        {
            if (this.idisplayFeedback_0 == null)
            {
                return;
            }
            this.ipolygon_0         = (this.idisplayFeedback_0 as INewPolygonFeedback).Stop();
            this.idisplayFeedback_0 = null;
            if ((this.ipolygon_0 as IArea).Area == 0.0)
            {
                this.ipolygon_0 = null;
                return;
            }

            (this._context.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
            if ((this.ipolygon_0 as ITopologicalOperator).IsSimple)
            {
                this.ipolygon_0.SpatialReference = this._context.FocusMap.SpatialReference;
                frmClipOutSet frmClipOutSet = new frmClipOutSet();
                if (frmClipOutSet.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    List <IFeatureClass> list = new List <IFeatureClass>();
                    for (int i = 0; i < this._context.FocusMap.LayerCount; i++)
                    {
                        ILayer layer = this._context.FocusMap.get_Layer(i);
                        if (layer.Visible)
                        {
                            if (layer is IFeatureLayer)
                            {
                                list.Add((layer as IFeatureLayer).FeatureClass);
                            }
                            else if (layer is IGroupLayer)
                            {
                                this.method_1(layer as IGroupLayer, list);
                            }
                        }
                    }
                    if (frmClipOutSet.Type == 0)
                    {
                        SDEToShapefile sde1 = new SDEToShapefile();
                        sde1.AddFeatureClasses(list);
                        sde1.ClipGeometry = this.ipolygon_0;
                        sde1.IsClip       = true;
                        sde1.Convert(frmClipOutSet.OutWorspace);
                        ComReleaser.ReleaseCOMObject(frmClipOutSet.OutWorspace);
                    }
                    else if (frmClipOutSet.Type == 1)
                    {
                        new ExportToMiTab
                        {
                            InputFeatureClasses = list,
                            OutPath             = frmClipOutSet.OutPath,
                            ClipGeometry        = this.ipolygon_0,
                            IsClip = true
                        }.Export();
                    }
                    else if (frmClipOutSet.Type == 2)
                    {
                        VCTWrite vCTWrite = new VCTWrite();
                        for (int i = 0; i < list.Count; i++)
                        {
                            vCTWrite.AddDataset(list[i] as IDataset);
                        }
                        vCTWrite.ClipGeometry = this.ipolygon_0;
                        vCTWrite.IsClip       = true;
                        vCTWrite.Write(frmClipOutSet.OutPath);
                    }
                }
            }
            this.ipolygon_0 = null;
            (this._context.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
        }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button == 2)
                return;
            INewLineFeedback pLineFeed;

            if (m_PT1 == null)
            {
                m_PT1 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_PT1 = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_PT1);
                m_pFeedback = new NewLineFeedbackClass();
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.Start(m_PT1);
                if (m_pFeedback != null)
                    m_pFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;

            }
            else if (m_PT2 == null)
            {
                m_PT2 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_PT2 = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_PT2);
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.AddPoint(m_PT2);
            }
            else if (m_PT3 == null)
            {
                m_PT3 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_PT3 = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_PT3);
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.AddPoint(m_PT3);
            }
            else if (m_PT4 == null)
            {
                m_PT4 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_PT4 = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_PT4);
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.AddPoint(m_PT4);

                pLineFeed.Stop();
                IBezierCurveGEN bezier = CreateBazerCurve();
                DrawCircleByCenterAndRadius(m_pCurrentLayer, bezier, m_hookHelper.ActiveView.ScreenDisplay);

                m_PT1 = null;
                m_PT2 = null;
                m_PT3 = null;
                m_PT4 = null;
                m_pFeedback = null;
            }
        }
Example #44
0
 public override void OnKeyDown(int keyCode, int Shift)
 {
     if (keyCode == (int)Keys.Escape)
     {
         m_pFeedback = null;
         m_pEllipticArc = null;
         m_pEnvFeedback = null;
         m_lMouseDownCount = 0;
         m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
     }
 }
        private void EditMouseDown(IPoint pPnt)
        {
            try
            {
                IPolygon  pGeompoly;
                IPolyline pGeomPolyline;
                IHitTest  pHtTest;
                IPoint    pPtHit;
                double    pDblHitDis   = 0;
                int       pLngPrtIdx   = 0;
                int       pLngSegIdx   = 0;
                Boolean   pBoolHitRt   = false;
                Boolean   pBoolHitTest = false;
                double    pDblSrchDis  = 0;
                pPnt.Z      = 0;
                pPtHit      = new PointClass();
                pDblSrchDis = m_activeView.Extent.Width / 200;
                //获取编辑目标图层
                IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer;
                if (pFeatLyr == null)
                {
                    return;
                }
                IFeatureCursor pFeatCur  = MapManager.GetSelectedFeatures(pFeatLyr);
                IFeature       pTFeature = pFeatCur.NextFeature();
                switch (pTFeature.Shape.GeometryType)
                {
                //当为单点、点集时直接返回
                case esriGeometryType.esriGeometryPoint:
                case esriGeometryType.esriGeometryMultipoint:
                    return;

                //线要素
                case esriGeometryType.esriGeometryLine:
                case esriGeometryType.esriGeometryPolyline:
                    m_pHitElem = new LineElementClass();
                    break;

                //面要素
                case esriGeometryType.esriGeometryPolygon:
                case esriGeometryType.esriGeometryEnvelope:
                    m_pHitElem = new PolygonElementClass();
                    break;
                }
                //获取选中要素的几何对象
                m_pHitElem.Geometry = pTFeature.Shape;
                if (m_pHitElem != null)
                {
                    switch (pTFeature.Shape.GeometryType)
                    {
                    case esriGeometryType.esriGeometryLine:
                    case esriGeometryType.esriGeometryPolyline:
                        pGeomPolyline = m_pHitElem.Geometry as IPolyline;
                        pHtTest       = pGeomPolyline as IHitTest;
                        pBoolHitTest  = pHtTest.HitTest(pPnt, pDblSrchDis,
                                                        esriGeometryHitPartType.esriGeometryPartVertex, pPtHit,
                                                        ref pDblHitDis, ref pLngPrtIdx, ref pLngSegIdx, ref pBoolHitRt);
                        if (pBoolHitTest)
                        {
                            EditVertexClass.pHitPnt = pPtHit;
                            m_editDispFeed          = new LineMovePointFeedbackClass();
                            m_editDispFeed.Display  = m_activeView.ScreenDisplay;
                            m_polylineMvPtFeed      = m_editDispFeed as ILineMovePointFeedback;
                            m_polylineMvPtFeed.Start(pGeomPolyline, pLngSegIdx, pPnt);
                        }

                        break;

                    case esriGeometryType.esriGeometryPolygon:
                    case esriGeometryType.esriGeometryEnvelope:
                        pGeompoly    = m_pHitElem.Geometry as IPolygon;
                        pHtTest      = pGeompoly as IHitTest;
                        pBoolHitTest = pHtTest.HitTest(pPnt, pDblSrchDis,
                                                       esriGeometryHitPartType.esriGeometryPartVertex,
                                                       pPtHit, ref pDblHitDis, ref pLngPrtIdx, ref pLngSegIdx, ref pBoolHitRt);
                        EditVertexClass.pHitPnt = pPtHit;
                        if (pBoolHitTest)
                        {
                            //定义获取到的与传入点的最近所选地物
                            IFeature pFeature;
                            //定义测量距离用于捕获离点最近的地物
                            double pTestDist = 0;
                            //用于求点与地物的距离
                            IProximityOperator pProximity;
                            IGeometry          pGeoM;
                            IFeature           pTestFeature;
                            //用于最短距离的比较
                            double               pTempDist = 0;
                            IFeatureCursor       pSelected;
                            ITopologicalOperator pTopoOpt;
                            //捕捉到的要移动的节点
                            IPoint pSnapVertex = default(IPoint);
                            //从所选地物中获得离点最近的那个地物
                            pFeature = null;
                            //用鼠标点进行运算
                            pTopoOpt = pPnt as ITopologicalOperator;
                            pTopoOpt.Simplify();
                            pProximity   = pPnt as IProximityOperator;
                            pSelected    = MapManager.GetSelectedFeatures(pFeatLyr);
                            pTestFeature = pSelected.NextFeature();
                            pGeoM        = pTestFeature.Shape;
                            pTestDist    = pProximity.ReturnDistance(pGeoM);
                            pFeature     = pTestFeature;
                            //从所选地物中获得离点最近的那个地物
                            while (pTestFeature != null)
                            {
                                pTestFeature = pSelected.NextFeature();
                                if (pTestFeature != null)
                                {
                                    pGeoM     = pTestFeature.Shape;
                                    pTempDist = pProximity.ReturnDistance(pGeoM);
                                    if (pTempDist < pTestDist)
                                    {
                                        pTestDist = pTempDist;
                                        pFeature  = pTestFeature;
                                    }
                                }
                            }

                            //检查pSnapPoint是否是所选地物中的某个图斑的一个节点
                            double pDblHDis      = 0;
                            int    pLngVertexIdx = 0;
                            int    pLngSIdx      = 0;
                            bool   pBoolHRt      = false;
                            bool   pBlnGet       = false;
                            double pDblDistMin   = 0;
                            pDblDistMin = pTempDist;
                            if (pDblDistMin == 0)
                            {
                                pDblDistMin = 3;
                            }
                            //两倍可以保证一般一次找的到
                            double   pDblSearchRadius = pDblDistMin * 2;
                            IHitTest pHT = default(IHitTest);
                            pHT = pFeature.Shape as IHitTest;
                            //如果pSnapPoint不是pTempParcel的节点
                            if (EditVertexClass.GetVertexIndex(pPnt, pFeature.Shape) == -2)
                            {
                                pSnapVertex = new Point();
                                while (!pBlnGet)
                                {
                                    pBlnGet = pHT.HitTest(pPnt, pDblSearchRadius,
                                                          esriGeometryHitPartType.esriGeometryPartVertex,
                                                          pSnapVertex, ref pDblHDis, ref pLngVertexIdx, ref pLngSIdx, ref pBoolHRt);
                                    pDblSearchRadius = pDblSearchRadius + pDblDistMin;
                                }
                                EditVertexClass.pHitPnt = pSnapVertex;
                                //如果pSnapVertex仍然不是pTempParcel的节点
                                if (EditVertexClass.GetVertexIndex(pSnapVertex, pFeature.Shape) == -2)
                                {
                                    MessageBox.Show("所想移动的起点不是所选面的节点", "提示",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                                m_fromPoint = pSnapVertex;
                            }
                            else
                            {
                                pSnapVertex = pPnt;
                                m_fromPoint = pSnapVertex;
                            }
                            //找到包含所要移动的节点的图形,在该过程里面对m_FeatArray进行了赋值
                            EditVertexClass.SelectByShapeTop(pFeatLyr, pSnapVertex, esriSpatialRelEnum.esriSpatialRelTouches,
                                                             false, esriSelectionResultEnum.esriSelectionResultNew);
                            m_editDispFeed         = new PolygonMovePointFeedbackClass();
                            m_editDispFeed.Display = m_activeView.ScreenDisplay;
                            m_polyMvPtFeed         = m_editDispFeed as IPolygonMovePointFeedback;
                            m_polyMvPtFeed.Start(pGeompoly, pLngSegIdx, pPnt);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                //SysLogHelper.WriteOperationLog("节点移动错误", ex.Source, "数据编辑");
            }
        }
Example #46
0
        ////////////protected override void OnNotifyMessage(System.Windows.Forms.Message m)
        ////////////{
        ////////////    /*This method of suppressing resize drawing works by examining the windows messages 
        ////////////    sent to the form. When a form starts resizing, windows sends the WM_ENTERSIZEMOVE 
        ////////////    Windows(messge). At this point we suppress drawing to the MapControl and 
        ////////////    PageLayoutControl and draw using a "stretchy bitmap". When windows sends the 
        ////////////    WM_EXITSIZEMOVE the form is released from resizing and we resume with a full 
        ////////////    redraw at the new extent.
        ////////////    Note in DotNet forms we can not simply use the second parameter in a Form_Load 
        ////////////    event to automatically detect when a form is resized as follows:
        ////////////    AxPageLayoutControl1.SuppressResizeDrawing(False, Me.Handle.ToInt32)
        ////////////    This results in a System.NullException when the form closes (after layers have been 
        ////////////    loaded). This is a limitation caused by .Net's particular implementation of its 
        ////////////    windows message pump which conflicts with "windows subclassing" used to watch the
        ////////////    forms window.*/
        ////////////    base.OnNotifyMessage (m);
        ////////////    if (m.Msg == WM_ENTERSIZEMOVE)
        ////////////    {
        ////////////        axMapControl1.SuppressResizeDrawing(true, 0);
        ////////////    }
        ////////////    else if (m.Msg == WM_EXITSIZEMOVE)
        ////////////    {
        ////////////        axMapControl1.SuppressResizeDrawing(false, 0);
        ////////////    }
        ////////////}
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            //On Error GoTo ErrorHandler

            if (MDIApplication.ParentForm.pyBtn == 1)
            {
                if (this.axMapControl1.ActiveView.FocusMap.SelectionCount >= 1)
                {
                    //////////IGeometry pGeometry ;
                    //////////IPoint pPoint ;
                    //////////IEnvelope pEnvelope ;
                    m_pScreenDisplay = this.axMapControl1.ActiveView.ScreenDisplay;
                    //'目前对第一层的要素
                    pMap = this.axMapControl1.ActiveView.FocusMap;
                    pSR = pMap.SpatialReference;
                    // '当前参考系为图层坐标系统WGS84
                    //'Dim name As String
                    //'name = pSR.name
                    //'MsgBox "name is" & name

                    if (this.axMapControl1.ActiveView.FocusMap.LayerCount == 0)
                    {
                        MessageBox.Show("当前工程没有可操作图层");
                        return;
                    }

                    //'得到鼠标点击的起点坐标
                    pPoint = m_pScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                    X_First = pPoint.X;
                    Y_First = pPoint.Y;

                    IEnumFeature pEnumFeat = (IEnumFeature)this.axMapControl1.ActiveView.FocusMap.FeatureSelection;
                    pEnumFeat.Reset();
                    if (pEnumFeat == null)
                    {
                        return;
                    }
                    m_pFeature = pEnumFeat.Next();
                    IPolygon polygon = (IPolygon)m_pFeature.Shape;
                    //'Feature类型为Polygon
                    m_pDisplayFeedback = new MovePolygonFeedback();
                    m_pDisplayFeedback.Display = m_pScreenDisplay;

                    IMovePolygonFeedback pMovePolygonF = (IMovePolygonFeedback)m_pDisplayFeedback;

                    //pMovePolygonF.Start( m_pFeature.Shape, pPoint);

                    pMovePolygonF.Start(polygon, pPoint);

                    this.axMapControl1.ActiveView.Refresh();

                    //    '设置鼠标外观,鼠标形状作为判断标志

                    //    'Dim m_pMouseCursor As esriFramework.MouseCursor
                    //    'Set m_pMouseCursor = New MouseCursor
                    //    'm_pMouseCursor.SetCursor 5
                    //'ErrorHandler:
                    //    'MsgBox Err.Description
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
Example #47
0
        /// <summary>
        /// 创建要素的DoubleClick事件
        /// </summary>
        /// <param name="mapX"></param>
        /// <param name="mapY"></param>
        public void CreateDoubleClick(double mapX, double mapY)
        {
            if (mDisplayFeedback == null)
            {
                return;
            }
            IGeometry pGeometry = null;
            IPoint    pPoint    = new PointClass();

            pPoint.PutCoords(mapX, mapY);

            INewLineFeedback    pNewLineFeedback;
            INewPolygonFeedback pNewPolygonFeedback;
            IPointCollection    pPointCollection;

            //判断编辑状态
            if (mIsEditing)
            {
                if (mDisplayFeedback is INewLineFeedback)
                {
                    pNewLineFeedback = mDisplayFeedback as INewLineFeedback;
                    //添加点击点
                    //pNewLineFeedback.AddPoint(pPoint);
                    //结束Feedback
                    IPolyline pPolyline = pNewLineFeedback.Stop();
                    pPointCollection = pPolyline as IPointCollection;
                    //至少两点时才创建线要素
                    if (pPointCollection == null || pPointCollection.PointCount < 2)
                    {
                        MessageBox.Show("至少需要两点才能建立线要素!", "提示");
                    }
                    else
                    {
                        pGeometry = pPolyline as IGeometry;
                    }
                }
                else if (mDisplayFeedback is INewPolygonFeedback)
                {
                    pNewPolygonFeedback = mDisplayFeedback as INewPolygonFeedback;
                    //添加点击点
                    //pNewPolygonFeedback.AddPoint(pPoint);
                    //结束Feedback
                    IPolygon pPolygon = pNewPolygonFeedback.Stop();
                    pPointCollection = pPolygon as IPointCollection;
                    //至少三点才能创建线要素
                    if (pPointCollection == null || pPointCollection.PointCount < 3)
                    {
                        MessageBox.Show("至少需要三点才能建立多边形要素!", "提示");
                    }
                    else
                    {
                        pGeometry = pPolygon as IGeometry;
                    }
                }
                mDisplayFeedback.Display = ((IActiveView)this.mMap).ScreenDisplay;
                //不为空时添加
                if (pGeometry != null)
                {
                    AddFeature(pGeometry);
                    //创建完成将DisplayFeedback置为空
                    //mDisplayFeedback = null;
                }
                mDisplayFeedback = null;
            }
        }
Example #48
0
        private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
        {
            IGeometry pGeometry;
            try
            {
                if (MDIApplication.ParentForm.pyBtn == 1)
                {
                    MDIApplication.ParentForm.pyBtn = 0;
                    // '检查是否存在一个元素
                    if (m_pFeature != null)
                    {
                        //'针对polygon类型

                        IMovePolygonFeedback pMovePolygonF = (IMovePolygonFeedback)m_pDisplayFeedback;
                        pGeometry = pMovePolygonF.Stop();
                        // '更新元素
                        m_pFeature.Shape = pGeometry;

                        m_pFeature.Store();
                        m_pDisplayFeedback = null;
                        this.axMapControl1.ActiveView.Refresh();
                        //'将鼠标外观还原
                        //'Set m_pMouseCursor = New MouseCursor
                        //'m_pMouseCursor.SetCursor 0
                        this.axMapControl1.ActiveView.FocusMap.FeatureSelection.Cut();
                    }
                    return;
                }
                else
                {
                    return;
                }
            }
            catch
            {
                return;
            }
        }
        /// <summary>
        /// �½�������ӵ�
        /// </summary>
        /// <params name="x"></params>
        /// <params name="y"></params>
        public void NewFeatureMouseDown(IPoint pPoint)
        {
            INewPolygonFeedback pPolyFeed;
            INewLineFeedback pLineFeed;
            try
            {
                IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer;
                if (pFeatureLayer.FeatureClass == null) return;
                IActiveView pActiveView = (IActiveView)m_pMap;
                /// ������¿�ʼ�����Ķ�������Ӧ�Ĵ���һ���µ�Feedback����
                /// �������Ѵ��ڵ�Feedback�����мӵ�
                if (!m_bInUse)
                {
                    m_pMap.ClearSelection();  //�����ͼѡ�ж���
                    m_bInUse = true;
                    m_pFeedback = new NewLineFeedbackClass();
                    pLineFeed = (INewLineFeedback)m_pFeedback;
                    pLineFeed.Start(pPoint);
                    if (m_pFeedback != null)
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                }
                else
                {
                    if (m_pFeedback is INewMultiPointFeedback)
                    {
                        object obj = Missing.Value;
                        m_pPointCollection.AddPoint(pPoint, ref obj, ref obj);
                    }
                    else if (m_pFeedback is INewLineFeedback)
                    {
                        pLineFeed = (INewLineFeedback)m_pFeedback;
                        pLineFeed.AddPoint(pPoint);
                    }
                    else if (m_pFeedback is INewPolygonFeedback)
                    {
                        pPolyFeed = (INewPolygonFeedback)m_pFeedback;
                        pPolyFeed.AddPoint(pPoint);
                    }
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
Example #50
0
        /// <summary>
        /// 新建对象,添加点
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void NewFeatureMouseDown(IPoint pPoint)
        {
            INewPolygonFeedback pPolyFeed;
            INewLineFeedback    pLineFeed;

            try
            {
                /// 如果是新开始创建的对象,则相应的创建一个新的Feedback对象;
                /// 否则,向已存在的Feedback对象中加点
                if (!m_bInUse)
                {
                    m_pCurrentLayer = DataEditCommon.g_pLayer;
                    pFeatureLayer   = (IFeatureLayer)DataEditCommon.g_pLayer;
                    if (pFeatureLayer.FeatureClass == null)
                    {
                        return;
                    }
                    IActiveView pActiveView = (IActiveView)m_pMap;
                    m_pMap.ClearSelection();  //清除地图选中对象
                    m_bInUse = true;
                    //if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)   //创建线要素
                    //{
                    //    m_pFeedback = new NewLineFeedbackClass();
                    //    pLineFeed = (INewLineFeedback)m_pFeedback;
                    //    pLineFeed.Start(pPoint);

                    //}
                    //else
                    //{
                    m_pFeedback = new NewPolygonFeedbackClass();
                    pPolyFeed   = (INewPolygonFeedback)m_pFeedback;
                    pPolyFeed.Start(pPoint);
                    //}
                    if (m_pFeedback != null)
                    {
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                    }
                }
                else
                {
                    if (m_pFeedback is INewMultiPointFeedback)
                    {
                        object obj = Missing.Value;
                        m_pPointCollection.AddPoint(pPoint, ref obj, ref obj);
                    }
                    else if (m_pFeedback is INewLineFeedback)
                    {
                        pLineFeed = (INewLineFeedback)m_pFeedback;
                        pLineFeed.AddPoint(pPoint);
                    }
                    else if (m_pFeedback is INewPolygonFeedback)
                    {
                        pPolyFeed = (INewPolygonFeedback)m_pFeedback;
                        pPolyFeed.AddPoint(pPoint);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
 public override void OnKeyDown(int keyCode, int Shift)
 {
     if (keyCode == (int)Keys.Escape)
     {
         m_pPoint1 = null;
         m_pPoint2 = null;
         m_pFeedback = null;
         m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
     }
 }
Example #52
0
        /// <summary>
        /// 完成新建对象,取得绘制的对象,并添加到图层中
        /// 建议在Map.DblClick或Map.MouseDown(Button = 2)事件中调用本方法
        /// </summary>
        public void NewFeatureEnd()
        {
            IGeometry        pGeom = null;
            IPointCollection pPointCollection;
            object           obj = Type.Missing;

            try
            {
                if (m_pFeedback is INewMultiPointFeedback)
                {
                    INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback;
                    pMPFeed.Stop();
                    pGeom = (IGeometry)m_pPointCollection;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PointClass() as IGeometryCollection;
                    }

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewLineFeedback)
                {
                    INewLineFeedback pLineFeed = (INewLineFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolylineClass() as IGeometryCollection;
                    }

                    IPolyline pPolyLine = pLineFeed.Stop();

                    pPointCollection = (IPointCollection)pPolyLine;
                    if (pPointCollection.PointCount < 2)
                    {
                        MessageBox.Show("至少输入两个节点");
                    }
                    else
                    {
                        pGeom = (IGeometry)pPointCollection;
                    }

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewPolygonFeedback)
                {
                    INewPolygonFeedback pPolyFeed = (INewPolygonFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolygonClass() as IGeometryCollection;
                    }

                    IPolygon pPolygon;
                    pPolygon = pPolyFeed.Stop();
                    if (pPolygon != null)
                    {
                        pPointCollection = (IPointCollection)pPolygon;
                        if (pPointCollection.PointCount < 3)
                        {
                            MessageBox.Show("至少输入三个节点");
                        }
                        else
                        {
                            pGeom = (IGeometry)pPointCollection;
                        }

                        m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                    }
                }
                if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    IPolyline pline = MyMapHelp.PolygonToPolyline(m_GeometryCollection as IPolygon);
                    CreateFeature(pline as IGeometry);
                }
                else
                {
                    CreateFeature(m_GeometryCollection as IGeometry);
                }
                m_pFeedback          = null;
                m_bInUse             = false;
                m_GeometryCollection = null;
            }
            catch (Exception e)
            {
                m_pFeedback          = null;
                m_bInUse             = false;
                m_GeometryCollection = null;
                Console.WriteLine(e.Message.ToString());
            }
        }
Example #53
0
        public bool HandleCommand(string string_0)
        {
            bool flag;

            char[]         chrArray;
            string[]       strArrays;
            double         num;
            double         num1;
            IPoint         pointClass;
            IEnvelope      envelope;
            int            selectionCount;
            double         mapUnits;
            IFeatureLayer  featureLayer;
            IFeature       hitLineFeature;
            IWorkspaceEdit workspace;
            IPolyline      polyline;

            if (!this.bool_0)
            {
                try
                {
                    if (string_0 == "ESC")
                    {
                        this._appContext.ShowCommandString("取消延长线操作", CommandTipsType.CTTActiveEnd);
                        this._appContext.ClearCurrentTool();
                        this.bool_0 = true;
                        flag        = true;
                        return(flag);
                    }
                    else if (this.int_0 == 0)
                    {
                        string_0 = string_0.Trim();
                        if (string_0.Length != 0)
                        {
                            chrArray  = new char[] { ',' };
                            strArrays = string_0.Split(chrArray);
                            if ((int)strArrays.Length < 2)
                            {
                                this._appContext.ShowCommandString("输入不正确", CommandTipsType.CTTLog);
                                this.ShowCommandLine();
                            }
                            else
                            {
                                num        = 0;
                                num1       = 0;
                                pointClass = new ESRI.ArcGIS.Geometry.Point();
                                num        = Convert.ToDouble(strArrays[0]);
                                pointClass.PutCoords(num, Convert.ToDouble(strArrays[1]));
                                if (this.idisplayFeedback_0 == null)
                                {
                                    mapUnits =
                                        CommonHelper.ConvertPixelsToMapUnits(
                                            this._appContext.MapControl.Map as IActiveView, 6);
                                    hitLineFeature = Editor.GetHitLineFeature(this._appContext.MapControl.Map,
                                                                              pointClass, mapUnits, out featureLayer);
                                    if (hitLineFeature == null)
                                    {
                                        this.idisplayFeedback_0 = new NewEnvelopeFeedback()
                                        {
                                            Display = (this._appContext.MapControl.Map as IActiveView).ScreenDisplay
                                        };
                                        (this.idisplayFeedback_0 as INewEnvelopeFeedback).Start(pointClass);
                                        this.double_0 = pointClass.X;
                                        this._appContext.ShowCommandString("指定下一个角点:", CommandTipsType.CTTCommandTip);
                                    }
                                    else
                                    {
                                        this.int_0 = 1;
                                        this._appContext.MapControl.Map.SelectFeature(featureLayer, hitLineFeature);
                                        (this._appContext.MapControl.Map as IActiveView).PartialRefresh(
                                            esriViewDrawPhase.esriViewGeoSelection, null, null);
                                        this.ShowCommandLine();
                                    }
                                }
                                else
                                {
                                    envelope = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
                                    this.idisplayFeedback_0 = null;
                                    this.double_1           = pointClass.X;
                                    this.method_2(envelope);
                                    if (this.method_1())
                                    {
                                        this.int_0 = 1;
                                    }
                                    IAppContext appContext = this._appContext;
                                    selectionCount = this._appContext.MapControl.Map.SelectionCount;
                                    appContext.ShowCommandString(string.Concat("找到", selectionCount.ToString(), "个对象"),
                                                                 CommandTipsType.CTTLog);
                                    this.ShowCommandLine();
                                }
                            }
                        }
                        else
                        {
                            if (this.method_1())
                            {
                                this.int_0 = 1;
                            }
                            this.ShowCommandLine();
                        }
                    }
                    else if (this.int_0 == 1)
                    {
                        if (string_0.Length == 0)
                        {
                            this.int_0 = 2;
                            if (this.int_1 != 1)
                            {
                                this._appContext.ShowCommandString("不产生交点", CommandTipsType.CTTLog);
                            }
                            else
                            {
                                this._appContext.ShowCommandString("产生交点", CommandTipsType.CTTLog);
                            }
                        }
                        else if (string_0.ToUpper() == "Y")
                        {
                            this.int_0 = 2;
                            this.int_1 = 1;
                            this._appContext.ShowCommandString("产生交点", CommandTipsType.CTTLog);
                        }
                        else if (string_0.ToUpper() != "N")
                        {
                            this.int_0 = 2;
                            if (this.int_1 != 1)
                            {
                                this._appContext.ShowCommandString("不产生交点", CommandTipsType.CTTLog);
                            }
                            else
                            {
                                this._appContext.ShowCommandString("产生交点", CommandTipsType.CTTLog);
                            }
                            this.HandleCommand(string_0);
                            flag = true;
                            return(flag);
                        }
                        else
                        {
                            this.int_0 = 2;
                            this.int_1 = 0;
                            this._appContext.ShowCommandString("不产生交点", CommandTipsType.CTTLog);
                        }
                        this.ShowCommandLine();
                    }
                    else if (this.int_0 == 2)
                    {
                        chrArray  = new char[] { ',' };
                        strArrays = string_0.Split(chrArray);
                        if ((int)strArrays.Length >= 2)
                        {
                            num        = 0;
                            num1       = 0;
                            pointClass = new ESRI.ArcGIS.Geometry.Point();
                            num        = Convert.ToDouble(strArrays[0]);
                            pointClass.PutCoords(num, Convert.ToDouble(strArrays[1]));
                            if (this.idisplayFeedback_0 == null)
                            {
                                mapUnits =
                                    CommonHelper.ConvertPixelsToMapUnits(
                                        this._appContext.MapControl.Map as IActiveView, 6);
                                hitLineFeature = Editor.GetHitLineFeature(this._appContext.MapControl.Map, pointClass,
                                                                          mapUnits, out featureLayer);
                                if (hitLineFeature == null)
                                {
                                    this.idisplayFeedback_0 = new NewEnvelopeFeedback()
                                    {
                                        Display = (this._appContext.MapControl.Map as IActiveView).ScreenDisplay
                                    };
                                    (this.idisplayFeedback_0 as INewEnvelopeFeedback).Start(pointClass);
                                    this.double_0 = pointClass.X;
                                    this._appContext.ShowCommandString("指定下一个角点:", CommandTipsType.CTTCommandTip);
                                }
                                else
                                {
                                    polyline = null;
                                    polyline = (this.int_1 != 0
                                        ? Editor.ExtendPolyLineEx(this._appContext.MapControl.Map, hitLineFeature.Shape)
                                        : Editor.ExtendPolyLine(this._appContext.MapControl.Map, hitLineFeature.Shape));
                                    if (polyline != null && !polyline.IsEmpty &&
                                        (polyline as IPointCollection).PointCount > 1)
                                    {
                                        (polyline as ITopologicalOperator).Simplify();
                                        workspace = (hitLineFeature.Class as IDataset).Workspace as IWorkspaceEdit;
                                        workspace.StartEditOperation();
                                        hitLineFeature.Shape = polyline;
                                        hitLineFeature.Store();
                                        workspace.StopEditOperation();
                                        this._appContext.MapControl.ActiveView.Refresh();
                                    }
                                    this.ShowCommandLine();
                                }
                            }
                            else
                            {
                                envelope = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
                                this.idisplayFeedback_0 = null;
                                this.double_1           = pointClass.X;
                                IAppContext application = this._appContext;
                                selectionCount = this._appContext.MapControl.Map.SelectionCount;
                                application.ShowCommandString(string.Concat("找到", selectionCount.ToString(), "个对象"),
                                                              CommandTipsType.CTTLog);
                                mapUnits =
                                    CommonHelper.ConvertPixelsToMapUnits(
                                        this._appContext.MapControl.Map as IActiveView, 6);
                                IList <IFeature> intersectsLineFeatures =
                                    Editor.GetIntersectsLineFeatures(this._appContext.MapControl.Map, envelope);
                                workspace = null;
                                for (int i = 0; i < intersectsLineFeatures.Count; i++)
                                {
                                    IWorkspaceEdit workspaceEdit =
                                        (intersectsLineFeatures[i].Class as IDataset).Workspace as IWorkspaceEdit;
                                    if (workspaceEdit.IsBeingEdited())
                                    {
                                        if (workspace == null)
                                        {
                                            workspace = workspaceEdit;
                                            workspace.StartEditOperation();
                                        }
                                        polyline = null;
                                        polyline = (this.int_1 != 0
                                            ? Editor.ExtendPolyLineEx(this._appContext.MapControl.Map,
                                                                      intersectsLineFeatures[i].Shape)
                                            : Editor.ExtendPolyLine(this._appContext.MapControl.Map,
                                                                    intersectsLineFeatures[i].Shape));
                                        if (polyline != null && !polyline.IsEmpty &&
                                            (polyline as IPointCollection).PointCount > 1)
                                        {
                                            (polyline as ITopologicalOperator).Simplify();
                                            intersectsLineFeatures[i].Shape = polyline;
                                            intersectsLineFeatures[i].Store();
                                        }
                                    }
                                }
                                if (workspace != null)
                                {
                                    workspace.StopEditOperation();
                                    this._appContext.MapControl.ActiveView.Refresh();
                                }
                                this.ShowCommandLine();
                            }
                        }
                    }
                }
                catch
                {
                    this._appContext.ShowCommandString("输入不正确", CommandTipsType.CTTLog);
                    this.ShowCommandLine();
                    flag = true;
                    return(flag);
                }
                flag = true;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Example #54
0
 public override void OnKeyDown(int keyCode, int Shift)
 {
     if (keyCode == (int)Keys.Escape)
     {
         m_IsFirstPoint = true;
         m_pFeedback = null;
         m_bInUse = false;
         m_GeometryCollection = null;
         m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
     }
 }
        public void SketchMouseDown(int x, int y)
        {
            if (MyselectedLayer == null)
            {
                return;
            }
            if ((MyselectedLayer as IGeoFeatureLayer) == null)
            {
                return;
            }

            IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;

            if (featureClass == null)
            {
                return;
            }

            IPoint              point           = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
            INewLineFeedback    lineFeedback    = null;
            INewPolygonFeedback polygonFeedback = null;

            try
            {
                if (!If_isInUse)
                {
                    switch (featureClass.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        break;

                    case esriGeometryType.esriGeometryMultipoint:
                        If_isInUse = true;
                        MyfeedBack = new NewMultiPointFeedbackClass();
                        INewMultiPointFeedback multiPointFeedback = MyfeedBack as INewMultiPointFeedback;
                        MypointCollection = new MultipointClass();
                        multiPointFeedback.Start(MypointCollection, point);
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        If_isInUse   = true;
                        MyfeedBack   = new NewLineFeedbackClass();
                        lineFeedback = MyfeedBack as INewLineFeedback;
                        lineFeedback.Start(point);
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        If_isInUse      = true;
                        MyfeedBack      = new NewPolygonFeedbackClass();
                        polygonFeedback = MyfeedBack as INewPolygonFeedback;
                        polygonFeedback.Start(point);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    if ((MyfeedBack as INewMultiPointFeedback) != null)
                    {
                        object missing = Type.Missing;
                        MypointCollection.AddPoint(point, ref missing, ref missing);
                    }
                    else if ((MyfeedBack as INewLineFeedback) != null)
                    {
                        lineFeedback = MyfeedBack as INewLineFeedback;
                        lineFeedback.AddPoint(point);
                    }
                    else if ((MyfeedBack as INewPolygonFeedback) != null)
                    {
                        polygonFeedback = MyfeedBack as INewPolygonFeedback;
                        polygonFeedback.AddPoint(point);
                    }
                }
            }
            catch { return; }
        }
Example #56
0
        //private void EndDrawCircleCentRadWihtShift()
        //{
        //    frmCentRad formCentRad = new frmCentRad();
        //    formCentRad.ShowDialog();

        //    if( m_bFixRadius )
        //    {
        //        IGeometry pGeom = null;
        //        IPolyline pPolyline;
        //        IPolygon  pPolygon;

        //   IPoint pPoint = new PointClass();
        //        pPoint.X = m_pCenterPoint.X + m_dblRadius;
        //        pPoint.Y = m_pCenterPoint.Y;

        //        pPolyline = CommonFunction.ArcToPolyline(pPoint, m_pCenterPoint, pPoint,esriArcOrientation.esriArcClockwise);

        //        switch (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType)
        //        {
        //            case  esriGeometryType.esriGeometryPolyline:
        //                pGeom = pPolyline;
        //                break;
        //            case esriGeometryType.esriGeometryPolygon:
        //                pPolygon  =  CommonFunction.PolylineToPolygon(pPolyline);
        //                pGeom = pPolygon;                
        //                break;
        //            default:
        //                break;
        //        }//end switch

        //        m_pEnvelope = pGeom.Envelope;
        //        if(m_pEnvelope != null &&!m_pEnvelope.IsEmpty )  m_pEnvelope.Expand(10,10,false);;
        //        CommonFunction.CreateFeature(m_App.Workbench,pGeom, m_FocusMap, m_CurrentLayer);

        //        m_App.Workbench.CommandBarManager.Tools["2dmap.DFEditorTool.Undo"].SharedProps.Enabled = true;

        //    }

        //    Reset();
        //}

        private void DrawCircleCentRadMouseDown(IPoint pPoint, int shift)
        {
            Class.Common.DrawPointSMSSquareSymbol(m_MapControl, pPoint);

            if (!m_bInUse)           //如果命令没有使用
            {
                m_bInUse       = true;
                m_pCenterPoint = pPoint;

                m_pFeedback           = new NewCircleFeedbackClass();
                m_pCircleFeed         = (NewCircleFeedbackClass)m_pFeedback;
                m_pCircleFeed.Display = m_pActiveView.ScreenDisplay;
                m_pCircleFeed.Start(m_pCenterPoint);
            }
            else             //如果命令已经使用使用
            {
                IGeometry    pGeom = null;
                IPolyline    pPolyline;
                IPolygon     pPolygon;
                ICircularArc pCircularArc = new CircularArcClass();

                //if (shift == 1)//若果按住shift健弹出对话框,让用户修改圆周上的坐标值
                //{
                //     EndDrawCircleCentRadWihtShift();
                //}
                //else
                //{
                m_pFeedback.MoveTo(pPoint);
                pCircularArc = m_pCircleFeed.Stop();
                m_dblRadius  = pCircularArc.Radius;

                switch (((IFeatureLayer)m_CurrentLayer).FeatureClass.ShapeType)
                {
                case  esriGeometryType.esriGeometryPolyline:
                    pPolyline = Class.Common.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise);
                    pGeom     = pPolyline;
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    pPolyline = Class.Common.ArcToPolyline(pCircularArc.FromPoint, pCircularArc.CenterPoint, pCircularArc.FromPoint, esriArcOrientation.esriArcClockwise);
                    pPolygon  = Class.Common.PolylineToPolygon(pPolyline);
                    pGeom     = pPolygon;                
                    break;

                default:
                    break;
                }                        //end switch

                m_pEnvelope = pGeom.Envelope;
                if (m_pEnvelope != null && !m_pEnvelope.IsEmpty)
                {
                    m_pEnvelope.Expand(10, 10, false);
                }

                Class.Common.CreateFeature(pGeom, m_FocusMap, m_CurrentLayer);
                m_App.Workbench.UpdateMenu();

                Reset();

                //}
            }

            m_pLastPoint = pPoint;
        }
Example #57
0
File: 1.cs Project: trainsn/LBS
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                //是否为AEditor的编辑状态
                if (TheReferenceInstances.TheAEditer.PrepareEditor() == false)
                    return;

                //初始化IDisplayFeedback和pointColl
                //if (_geometryFeedback == null)
                //{
                    if (_subType == 1)
                    {
                        _geometryFeedback = new NewLineFeedbackClass();
                        _pointColl = new PolylineClass();
                    }
                    else if(_subType == 2)
                    {
                        _geometryFeedback = new NewPolygonFeedbackClass();
                        _pointColl = new PolygonClass();
                    }
                //}

                //初始化对应关联值
                TheReferenceInstances.TheAEditer.SketchEdit.DrawTool = this;
                TheReferenceInstances.TheAEditer.SketchEdit.PntColl = _pointColl;
                TheReferenceInstances.TheAEditer.StructSnapOption.IsHaveSnap = true;
                TheReferenceInstances.TheAEditer.StructSnapOption.Tolerance = 20;
                TheReferenceInstances.CurrentTool = this;
                TheReferenceInstances.TheAEditer.CurTask = _alterType;

                _startPoint = null;
                _endPoint = null;

                //设置当前工具为this
                if (myHook.Hook is IMapControl3)
                {
                    (myHook.Hook as IMapControl3).CurrentTool = this;
                    if (_subType == 1)
                        (_geometryFeedback as INewLineFeedback).Display = myHook.ActiveView.ScreenDisplay;
                    else if(_subType == 2)
                        (_geometryFeedback as INewPolygonFeedback).Display = myHook.ActiveView.ScreenDisplay;
                }
                else if (myHook.Hook is IPageLayoutControl2)
                {
                    (myHook.Hook as IPageLayoutControl2).CurrentTool = this;
                    if (_subType == 1)
                        (_geometryFeedback as INewLineFeedback).Display = (myHook.FocusMap as IActiveView).ScreenDisplay;
                    else if(_subType == 2)
                        (_geometryFeedback as INewPolygonFeedback).Display = (myHook.FocusMap as IActiveView).ScreenDisplay;
                }

                //右键菜单及Cursor
                this.m_cursor = Cursors.Cross;
                InitialRightMenu();
            }
            catch (System.Exception e)
            {
                XtraMessageBox.Show(String.Format("初始化变更工具失败!\n{0}", e.Message), "警告", MessageBoxButtons.OK);
            }
        }
Example #58
0
 /// <summary>
 /// 双击鼠标
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void axMapControl1_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e)
 {
     if (this.pDisplayFeedback != null)
     {
         IGeometry pGeometry = null;
         if (this.btnNewPolyline.Checked)//新建多义线
         {
             pGeometry = ((INewLineFeedback)this.pDisplayFeedback).Stop();
         }
         else if (this.btnNewPolygon.Checked)//新建多边形
         {
             pGeometry = ((INewPolygonFeedback)this.pDisplayFeedback).Stop();
         }
         else if (this.btnNewBezierCurve.Checked)//新建Bezier曲线
         {
             pGeometry = ((INewBezierCurveFeedback)this.pDisplayFeedback).Stop();
         }
         this.pDisplayFeedback = null;
         this.AddElement(pGeometry);
     }
 }
Example #59
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button == 2)
            {
                return;
            }
            INewLineFeedback pLineFeed;

            if (m_pPoint1 == null)
            {
                m_pPoint1   = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_pPoint1   = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_pPoint1);
                m_pFeedback = new NewLineFeedbackClass();
                pLineFeed   = (INewLineFeedback)m_pFeedback;
                pLineFeed.Start(m_pPoint1);
                if (m_pFeedback != null)
                {
                    m_pFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;
                }
            }
            else if (m_pPoint2 == null)
            {
                ///20140216 lyf
                ICursor pCursor = null;
                m_selectionSet.Search(null, false, out pCursor);
                IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
                IFeature       m_pFeature     = pFeatureCursor.NextFeature();

                if (pCursor != null)
                {
                    pCursor = null;
                    ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pCursor);
                }

                if (m_pFeature == null)
                {
                    MessageBox.Show(@"所选要素为空,请重新选择要素。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                m_pPoint2 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                m_pPoint2 = GIS.GraphicEdit.SnapSetting.getSnapPoint(m_pPoint2);
                //线和要素都齐全了,开始复制
                //IFeatureLayer pFeatureLayer = m_pCurrentLayer as IFeatureLayer;
                IFeatureClass pFeatureClass = m_featureLayer.FeatureClass;
                ILine         nLine         = new LineClass();//镜像轴线
                nLine.PutCoords(m_pPoint1, m_pPoint2);
                ITransformation         nTransformation         = new AffineTransformation2DClass();
                IAffineTransformation2D nAffineTransformation2D = nTransformation as IAffineTransformation2D;
                nAffineTransformation2D.DefineReflection(nLine);

                //启动编辑
                IWorkspaceEdit pWorkspaceEdit = DataEditCommon.g_CurWorkspaceEdit; // GetWorkspaceEdit();

                ITransform2D nTransform2D = m_pFeature.Shape as ITransform2D;      //镜像目标

                nTransform2D.Transform(esriTransformDirection.esriTransformForward, nTransformation);

                if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry0Dimension)
                {
                    pWorkspaceEdit.StartEditOperation();
                    IFeature pNewFeature = pFeatureClass.CreateFeature();
                    IPoint   pNewPoint   = nTransform2D as IPoint;
                    pNewFeature.Shape = pNewPoint;
                    pNewFeature.Store();
                    pWorkspaceEdit.StopEditOperation();
                    DataEditCommon.g_pMyMapCtrl.Map.ClearSelection();
                    DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(m_pCurrentLayer, pNewFeature);
                }
                else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry1Dimension)
                {
                    pWorkspaceEdit.StartEditOperation();
                    IFeature  pNewFeature  = pFeatureClass.CreateFeature();
                    IPolyline pNewPolyline = nTransform2D as IPolyline;//镜像所得
                    pNewFeature.Shape = pNewPolyline;
                    pNewFeature.Store();
                    pWorkspaceEdit.StopEditOperation();
                    DataEditCommon.g_pMyMapCtrl.Map.ClearSelection();
                    DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(m_pCurrentLayer, pNewFeature);
                }
                else if (m_pFeature.Shape.Dimension == esriGeometryDimension.esriGeometry2Dimension)
                {
                    pWorkspaceEdit.StartEditOperation();
                    IFeature pNewFeature = pFeatureClass.CreateFeature();
                    IPolygon pNewPolygon = nTransform2D as IPolygon;//镜像所得
                    pNewFeature.Shape = pNewPolygon;
                    pNewFeature.Store();
                    pWorkspaceEdit.StopEditOperation();
                    DataEditCommon.g_pMyMapCtrl.Map.ClearSelection();
                    DataEditCommon.g_pMyMapCtrl.Map.SelectFeature(m_pCurrentLayer, pNewFeature);
                }
                else
                {
                }
                pLineFeed = (INewLineFeedback)m_pFeedback;
                pLineFeed.AddPoint(m_pPoint2);

                pLineFeed.Stop();//拖拽停止
                m_pFeature = null;
                m_pPoint1  = null;
                m_pPoint2  = null;
            }

            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Example #60
0
        private void EndSketch()
        {
            IGeometry m_Geometry = null;
            IPointCollection m_PointCollection = null;

            if (m_Feedback is INewLineFeedback)
            {
                INewLineFeedback m_LineFeed = (INewLineFeedback)m_Feedback;
                m_LineFeed.AddPoint(m_PointStop);
                IPolyline m_PolyLine = m_LineFeed.Stop();
                m_PointCollection = (IPointCollection)m_PolyLine;
                if (m_PointCollection.PointCount < 2)
                {
                    MessageBox.Show("��Ҫ�������������һ���ߣ�", "δ��������", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    m_Geometry = (IGeometry)m_PointCollection;
                }
            }
            else if (m_Feedback is INewPolygonFeedback)
            {
                INewPolygonFeedback m_PolyFeed = (INewPolygonFeedback)m_Feedback;
                m_PolyFeed.AddPoint(m_PointStop);
                IPolygon m_Polygon = m_PolyFeed.Stop();
                if (m_Polygon != null)
                    m_PointCollection = (IPointCollection)m_Polygon;
                if (m_PointCollection.PointCount < 3)
                {
                    MessageBox.Show("��Ҫ�������������һ���棡", "δ��������", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    m_Geometry = (IGeometry)m_PointCollection;
                }
            }

            CreatFeature(m_Geometry);
            m_hookHelper.ActiveView.Refresh();
            m_Feedback = null;
            m_bInUse = false;
        }