如何打断曲线?
C#开发|黄洪辉|2018-06-14 11:02
-
回答:
主要用到函数说明:
IMxDrawCurve::SplitCurves
打断曲线,详细说明如下:
参数 说明 [in] IMxDrawResbuf* aryParam
打断位置参数数组,或打断的点数组,是个MxDrawResbuf对象
[out] IMxDrawResbuf** aryNewId
返回打断后生成的新曲线id,是个MxDrawResbuf对象
c#代码实现如下:
private void DoSplitCurves() { MxDrawUtility mxUtility = new MxDrawUtility(); object getPt; MxDrawEntity ent = mxUtility.GetEntity(out getPt, "选择打断的曲线:"); if (ent == null) return; MxDrawCurve curve; if (ent is MxDrawCurve) { curve = (MxDrawCurve)ent; } else { MessageBox.Show("实体类型不对"); return; } MxDrawPoint getPt1 = (MxDrawPoint)(mxUtility.GetPoint(null, "点取打断位置:")); if (getPt1 == null) { MessageBox.Show("用户取消.."); return; } MxDrawResbuf param = new MxDrawResbuf(); param.AddPoint(getPt1, -10); object objId; if (curve.SplitCurves(param,out objId)) { MxDrawResbuf rbId = (MxDrawResbuf)objId; MessageBox.Show("打断成功,生成的曲线个数:" + rbId.Count); // 把以前的删除掉。 ent.Erase(); } else { MessageBox.Show("打断失败"); } }
选择曲线,把曲线从中间1/4 到 3/ 4处断开:
MxDrawUtility mxUtility = new MxDrawUtility(); object getPt; MxDrawEntity ent = mxUtility.GetEntity(out getPt, "选择打断的曲线:"); if (ent == null) return; MxDrawCurve curve; if (ent is MxDrawCurve) { curve = (MxDrawCurve)ent; } else { MessageBox.Show("实体类型不对"); return; } double dLen = 0.0; curve.GetDistAtParam(curve.GetEndParam(),out dLen); object pt1; if (!curve.GetPointAtDist(dLen / 4.0, out pt1)) return; object pt2; if (!curve.GetPointAtDist(dLen * 3.0 / 4.0, out pt2)) return; MxDrawPoint breakPt1 = (MxDrawPoint)pt1; MxDrawPoint breakPt2 = (MxDrawPoint)pt2; if (breakPt1 == null || breakPt2 == null) return; MxDrawResbuf param = new MxDrawResbuf(); param.AddPoint(breakPt1, -10); param.AddPoint(breakPt2, -10); object objIds; if (curve.SplitCurves(param, out objIds)) { MxDrawResbuf rbId = (MxDrawResbuf)objIds; if(rbId.Count == 3) { axMxDrawX1.Erase(rbId.AtLong(1)); } // 把以前的删除掉。 ent.Erase(); }