AutoCAD.Net——浅谈JIG之EntityJig和DrawJig
转载自:http://www.cnblogs.com/wangyong/archive/2010/01/20/1652412.html,根据自己的理解加了注释及其他的一些东西。
在CAD的二次开发中,有时会使用JIG技术来实现操作的动态性、交互,最常见的比如说是在CAD中定制自己的移动和复制,当然要保持CAD中原有的动态显示效果。
在JIG中我们可以继承EntityJig和DrawJig,对于这两个类,那这两个类有什么区别呢?他们的使用场合又有什么区别呢?
其实,他们之间在操作一些简单的实体的时候是没有多大区别的,硬要说区别的话,那就是在实现一个相同功能时DrawJig比EntityJig的代码简单一些。(注意:是指在操作简单的实体的时候,比如实体的数量就一个)。
EntityJig:一般用于图元实体的拖动,要求先生成实体Entity
1 2 3 4 5 6 7 8 9 |
protected override bool Update() { throw new NotImplementedException(); } protected override SamplerStatus Sampler(JigPrompts prompts) { throw new NotImplementedException(); } |
DrawJig:一般用于复杂图形的拖动
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<p> protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw) { throw new NotImplementedException(); } </p> <p> protected override SamplerStatus Sampler(JigPrompts prompts) { throw new NotImplementedException(); } </p> |
在拖动一个实体的时候,不管是用EntityJig还是DrawJig效果都一样,但是当我们在处理多个实体的移动,我们要求鼠标可以实时动态显示要拖动的多个实体,这点,EntityJig却无法实现了,但如果是DrawJig却很容易实现。(下图是用DrawJig实现)
而且对于动态生成实体(比如指定一个圆心,动态生成一个圆),用DrawJig中的WorlDraw可以灵活控制实现生成。
相比之下,是不是发现DrawJig优胜于EntityJig(个人理解).
下面贴出上图实现的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
<p> #region DrawJig动态拖动多个实体 public class DrawJigEnt : DrawJig { //变量 Point3d oldPt;//实体移动之前的位置 Point3d newPt;//实体移动之后的位置 Vector3d v;//实体移动的向量 List<Entity> ents = new List<Entity>(); List<Point3d> oldPts = new List<Point3d>(); public DrawJigEnt(List<Entity> ents) { oldPt = Point3d.Origin; newPt = Point3d.Origin; v = new Vector3d(); this.ents = ents; Autodesk.AutoCAD.DatabaseServices.Entity ent = ents[0]; if (ent is BlockReference) { BlockReference br = ent as BlockReference; oldPt = br.Position; } for (int i = 1; i < ents.Count; i++) { if (ents[i] is BlockReference) { BlockReference br = ents[i] as BlockReference; oldPts.Add(br.Position); } } } //更新 protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw) { Entity ent = ents[0]; ent.UpgradeOpen(); if (ent is BlockReference) { BlockReference br = ent as BlockReference; br.Position = newPt; draw.Geometry.Draw(br); } v = newPt.GetVectorTo(oldPt); for(int i =1;i<ents.Count;i++) { Entity entity = ents[i]; entity.UpgradeOpen(); if (entity is BlockReference) { BlockReference br = entity as BlockReference; br.Position = oldPts[i - 1] + v; draw.Geometry.Draw(entity); } } return true; } //取样函数 protected override SamplerStatus Sampler(JigPrompts prompts) { JigPromptOptions opt = new JigPromptOptions(); opt.UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.NoNegativeResponseAccepted | UserInputControls.NullResponseAccepted; opt.UseBasePoint = true; opt.Cursor = CursorType.RubberBand; opt.BasePoint = oldPt; opt.Message = "选择移动到的终点"; PromptPointResult res = prompts.AcquirePoint(opt); if (PromptStatus.OK == res.Status) { if (res.Value == newPt) { return SamplerStatus.NoChange; } newPt = res.Value; } else { return SamplerStatus.Cancel; } return SamplerStatus.OK; } } #endregion<span style="font-family:'sans serif', tahoma, verdana, helvetica;font-size:12px;line-height:1.5;"> </span> </p> |
原创文章,文章首发于:Riley Ge (@rileyge) — Steemit
原创文章,转载请注明: 转载自TsonTec:测量解决方案提供者
感谢分享 祝您开心快乐每一天!
图片失效了,并没有找到,自己也没有对代码进行调试。