通用jig类,用到委托
代码
/// 通用jig类,用到委托,by houlinbo QQ420021327
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
namespace ArxHlb
{
//委托类
public delegate void DelegateJig(Entity ent, Point3d ptBase, Point3d ptTo);
//jig的入口类
public class CADJigDelegate
{
/// <summary>
/// 入口函数
/// </summary>
/// <param name="ed">ed</param>
/// <param name="lstEnt">实体列表</param>
/// <param name="promp">提示</param>
/// <returns></returns>
public static bool Jig(Editor ed, List<Entity> lstEnt, string promp, DelegateJig op)
{
JigDelegate jig = new JigDelegate();
jig.lstEnt = lstEnt;
jig.promp = promp;
jig.op = op;
PromptResult prJig = ed.Drag(jig);
if (prJig.Status != PromptStatus.OK)
{
return false;
}
else
{
return true;
}
}
}
//本类是Jig,单独的实体或实体列表均可调用
public class JigDelegate : DrawJig
{
private List<Entity> _lstEnt; //移动的实体
private string _promp; //提示
private DelegateJig _op;//委拖
private Point3d ptBase = new Point3d();//基点
private Point3d ptTo; //插入点
/// <summary>
/// 移动的实体
/// </summary>
public List<Entity> lstEnt
{
set { _lstEnt = value; }
}
/// <summary>
/// /提示
/// </summary>
public string promp
{
set { _promp = value; }
}
/// <summary>
/// /委托
/// </summary>
public DelegateJig op
{
set { _op = value; }
get { return _op; }
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions optJigPoint = new JigPromptPointOptions(_promp);
optJigPoint.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted |
UserInputControls.NullResponseAccepted;
optJigPoint.Keywords.Add("Undo", "Undo", "放弃(U)");
PromptPointResult resJigPoint = prompts.AcquirePoint(optJigPoint);
Point3d curPt = resJigPoint.Value;
ptBase = ptTo;
if (ptTo != curPt)
{
ptTo = curPt;
return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}
protected override bool WorldDraw(WorldDraw draw)
{
try
{
foreach (Entity ent in _lstEnt)
{
op(ent, ptBase, ptTo); //委托函数,返回去调用具体对每个实体所执行的操作
ent.RecordGraphicsModified(true);
draw.Geometry.Draw(ent);
}
}
catch (System.Exception)
{
return false;
}
return true;
}
}
}
/// 通用jig类,用到委托,by houlinbo QQ420021327
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
namespace ArxHlb
{
//委托类
public delegate void DelegateJig(Entity ent, Point3d ptBase, Point3d ptTo);
//jig的入口类
public class CADJigDelegate
{
/// <summary>
/// 入口函数
/// </summary>
/// <param name="ed">ed</param>
/// <param name="lstEnt">实体列表</param>
/// <param name="promp">提示</param>
/// <returns></returns>
public static bool Jig(Editor ed, List<Entity> lstEnt, string promp, DelegateJig op)
{
JigDelegate jig = new JigDelegate();
jig.lstEnt = lstEnt;
jig.promp = promp;
jig.op = op;
PromptResult prJig = ed.Drag(jig);
if (prJig.Status != PromptStatus.OK)
{
return false;
}
else
{
return true;
}
}
}
//本类是Jig,单独的实体或实体列表均可调用
public class JigDelegate : DrawJig
{
private List<Entity> _lstEnt; //移动的实体
private string _promp; //提示
private DelegateJig _op;//委拖
private Point3d ptBase = new Point3d();//基点
private Point3d ptTo; //插入点
/// <summary>
/// 移动的实体
/// </summary>
public List<Entity> lstEnt
{
set { _lstEnt = value; }
}
/// <summary>
/// /提示
/// </summary>
public string promp
{
set { _promp = value; }
}
/// <summary>
/// /委托
/// </summary>
public DelegateJig op
{
set { _op = value; }
get { return _op; }
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions optJigPoint = new JigPromptPointOptions(_promp);
optJigPoint.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.NoZeroResponseAccepted |
UserInputControls.NoNegativeResponseAccepted |
UserInputControls.NullResponseAccepted;
optJigPoint.Keywords.Add("Undo", "Undo", "放弃(U)");
PromptPointResult resJigPoint = prompts.AcquirePoint(optJigPoint);
Point3d curPt = resJigPoint.Value;
ptBase = ptTo;
if (ptTo != curPt)
{
ptTo = curPt;
return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}
protected override bool WorldDraw(WorldDraw draw)
{
try
{
foreach (Entity ent in _lstEnt)
{
op(ent, ptBase, ptTo); //委托函数,返回去调用具体对每个实体所执行的操作
ent.RecordGraphicsModified(true);
draw.Geometry.Draw(ent);
}
}
catch (System.Exception)
{
return false;
}
return true;
}
}
}