当需要区别特定区域的图形时,有时需要识别与某曲线首尾相连的所有曲线,下属代码通过递归实现搜索,已进行封装
#region 获取与Curve相连的其它Curve-递归
/// <summary>
/// 获取与Curve相连的其它Curve-递归
/// </summary>
/// <param name="baseCurve"></param>
/// <param name="curveDicAll"></param>
/// <returns></returns>
public static Dictionary<Curve, ObjectId> anotherCurveDicDiGui(this Curve baseCurve, Dictionary<Curve, ObjectId> curveDicAll)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
//获取与曲线的起点相交的曲线图形
Point3d pipeiDian = baseCurve.StartPoint;
PromptSelectionResult res = ed.SelectCrossingWindow(pipeiDian, pipeiDian);
List<Entity> entList = res.GetMulitEntityBySelect();
//获取与曲线的终点相交的曲线图形
pipeiDian = baseCurve.EndPoint;
res = ed.SelectCrossingWindow(pipeiDian, pipeiDian);
List<Entity> entList2 = res.GetMulitEntityBySelect();
//把两个列表合并起来
entList = entList.Concat(entList2).ToList<Entity>();
Boolean isNew = false;
foreach (Entity ent in entList)
{
if (curveDicAll.ContainsKey((Curve)ent) == false)
{
isNew = true;
}
}
//递归方法获取次级曲线
if (isNew == true)
{
foreach (Entity ent in entList)
{
if (curveDicAll.ContainsKey((Curve)ent) == false)
{
curveDicAll[ent as Curve] = ent.ObjectId;
return anotherCurveDicDiGui(ent as Curve, curveDicAll);
}
}
return null;
}
else
{
return curveDicAll;
}
}
#endregion