public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (Button != 1 || m_pFeature == null || m_pVertexFeed == null || m_HitSegmentIndex == -1) { return; } IPoint pPnt = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //如果开启捕捉则以捕捉到的点为准 if (MoData.v_bSnapStart && m_pSnapPoint != null) { pPnt = m_pSnapPoint; } ISegmentCollection pSegmentCollection = m_pFeature.Shape as ISegmentCollection; //检查是否点击第一点 if (m_HitSegmentIndex == 0) { //如果是第一点且是Polygon,更新最后一段 if (m_pFeature.Shape is IPolygon) { pPnt.Z = pSegmentCollection.get_Segment(pSegmentCollection.SegmentCount - 1).ToPoint.Z; pSegmentCollection.get_Segment(pSegmentCollection.SegmentCount - 1).ToPoint = pPnt; } } else { //如果不是第一点,更新上一段(FromPoint as anchor) pPnt.Z = pSegmentCollection.get_Segment(m_HitSegmentIndex - 1).ToPoint.Z; pSegmentCollection.get_Segment(m_HitSegmentIndex - 1).ToPoint = pPnt; } //检查是否点击最后一个节点 if (m_HitSegmentIndex == pSegmentCollection.SegmentCount) { //如果是点击最后一个节点,并且是polygon,更新第一段 if (m_pFeature.Shape is IPolygon) { pPnt.Z = pSegmentCollection.get_Segment(0).FromPoint.Z; pSegmentCollection.get_Segment(0).FromPoint = pPnt; } } else { //如果不是最后一个节点,更新下一段(ToPoint as anchor) pPnt.Z = pSegmentCollection.get_Segment(m_HitSegmentIndex).FromPoint.Z; pSegmentCollection.get_Segment(m_HitSegmentIndex).FromPoint = pPnt; } StoreFeature(m_pFeature, pSegmentCollection, MoData.v_CurWorkspaceEdit); m_MapControl.ActiveView.Refresh(); m_pVertexFeed = null; m_bMouseDown = false; m_HitSegmentIndex = 0; }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != 1 || m_pFeature == null) { return; } IPoint pPnt = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //获取选中的节点 IHitTest pHitTest = m_pFeature.Shape as IHitTest; IPoint pHitPoint = new PointClass(); double dblHitDistance = 0; int lPart = 0; bool bRight = false; bool bHitTest = pHitTest.HitTest(pPnt, m_dblTolearance, esriGeometryHitPartType.esriGeometryPartVertex, pHitPoint, ref dblHitDistance, ref lPart, ref m_HitSegmentIndex, ref bRight); if (bHitTest == false) { return; } if (m_HitSegmentIndex == -1) { return; //未选中节点 } ISegmentCollection pSegmentCollection = m_pFeature.Shape as ISegmentCollection; m_pVertexFeed = new VertexFeedbackClass(); m_pVertexFeed.Display = m_MapControl.ActiveView.ScreenDisplay; //检查是否点击第一点 if (m_HitSegmentIndex == 0) { //如果是第一点且是Polygon,加最后一段 (FromPoint as anchor) if (m_pFeature.Shape is IPolygon) { m_pVertexFeed.AddSegment(pSegmentCollection.get_Segment(pSegmentCollection.SegmentCount - 1), true); } } else { //如果不是第一点,并加上一段(FromPoint as anchor) m_pVertexFeed.AddSegment(pSegmentCollection.get_Segment(m_HitSegmentIndex - 1), true); } //检查是否点击最后一个节点 if (m_HitSegmentIndex == pSegmentCollection.SegmentCount) { //如果是点击最后一个节点,并且是polygon,加第一段 if (m_pFeature.Shape is IPolygon) { m_pVertexFeed.AddSegment(pSegmentCollection.get_Segment(0), false); } } else { //如果不是最后一个节点,就加下一段(ToPoint as anchor) m_pVertexFeed.AddSegment(pSegmentCollection.get_Segment(m_HitSegmentIndex), false); } m_bMouseDown = true; }