034集——JIG效果实现(橡皮筋效果)(CAD—C#二次开发入门)

可实现效果如下(对象捕捉F3需打开,否则效果不好):

   public class CircleJig : EntityJig
   {
       public static void DraCJig()
       {
           PromptPointResult ppr = Z.ed.GetPoint("a");
           if (ppr.Value == null) return;
           Point3d pt = ppr.Value;
           CircleJig circle = new CircleJig(pt);
           Polyjig poly = new Polyjig(pt);
           for (; ; )
           {
               PromptResult resJig = Z.ed.Drag(circle);//拖动圆
               if (resJig.Status == PromptStatus.Cancel)
               {
                   return;
               }
              
               if (resJig.Status == PromptStatus.OK) //确定, 则将圆添加到数据库
               // if (resJigpl.Status == PromptStatus.OK)
               {
                   Z.db.AddEntityToModeSpace(circle.GetEntity());//画圆
                   break;
               }
               return;
           }
           for (; ; )//画完圆继续jig线,不需要可注释
           {
               PromptResult resJigpl = Z.ed.Drag(poly);//拖动线
               
               if (resJigpl.Status == PromptStatus.Cancel)// 放弃, 则退出.
               {
                   return;
               }
             
               if (resJigpl.Status == PromptStatus.OK)  //确定, 则将线添加到数据库
               {
                   Z.db.AddEntityToModeSpace(poly.Updata());//画多段线
                   break;
               }
               return;
           }
       }
       // private Point3d jCenter; // 圆心
       private double jRadius;  // 半径
       public CircleJig(Point3d center)
           : base(new Circle())  // 继承父类Circle的属性
       {
           ((Circle)Entity).Center = center;  // Entity 转化为Cirecle 对象 复制center
       }
       // 用于更新图像对象 这里更新属性时无需使用事务处理
       protected override bool Update()
       {
           if (jRadius > 0)
           {
               ((Circle)Entity).Radius = jRadius;
           }

           return true;
       }
       // 这个函数的作用是当鼠标在屏幕上移动时 就会被调用 实现这个函数时 一般是用它改变图形的属性 我们在这个类定义的属性
       protected override SamplerStatus Sampler(JigPrompts prompts)
       {
           // 声明拖拽类jig提示信息
           JigPromptPointOptions jppo = new JigPromptPointOptions("\n 请指定圆上的一个点");
           char space = (char)32;
           jppo.Keywords.Add("U");
           jppo.Keywords.Add(space.ToString());
           jppo.UserInputControls = UserInputControls.Accept3dCoordinates;
           jppo.Cursor = CursorType.RubberBand;
           jppo.BasePoint = ((Circle)Entity).Center;
           jppo.UseBasePoint = true;

           // 获取拖拽时鼠标的位置状态
           PromptPointResult ppr = prompts.AcquirePoint(jppo);

           jRadius = ppr.Value.GetDistanceBetweenTwoPoint(((Circle)Entity).Center);
           return SamplerStatus.NoChange; // 继续移动 循环检测
       }


       public Entity GetEntity()
       {
           return Entity;
       }
   }
   public class Polyjig : Autodesk.AutoCAD.EditorInput.DrawJig
   {
       public Point3d location;
       public Point3d basePoint;
       public Polyline polyine = new Polyline();
       public Plane plane = new Plane();
       public int index;
       public static void DrawPLJig()
       {
           PromptPointResult ppr = Z.ed.GetPoint("a");
           if (ppr.Value == null) return;
           Point3d pt = ppr.Value;
           Polyjig poly = new Polyjig(pt);
           for (; ; )
           {
               PromptResult resJigpl = Z.ed.Drag(poly);//拖动线       
               if (resJigpl.Status == PromptStatus.Cancel) // 放弃, 则退出.
               {
                   return;
               }
              
               if (resJigpl.Status == PromptStatus.OK) //确定, 则将线添加到数据库
               {
                   Z.db.AddEntityToModeSpace(poly.Updata());//画多段线
                   break;
               }
               return;
           }
       }
       public Polyjig(Point3d basept)
       {
           location = basept;
           basePoint = basept;
           polyine.AddVertexAt(0, basePoint.Convert2d(plane), 0, 0, 0);
           polyine.AddVertexAt(1, location.Convert2d(plane), 0, 0, 0);
       }

       protected override SamplerStatus Sampler(JigPrompts prompts)
       {
           var opts = new JigPromptPointOptions("\n 输入下一个点");
           opts.UserInputControls = (UserInputControls.Accept3dCoordinates |
               UserInputControls.NoZeroResponseAccepted
               | UserInputControls.NoNegativeResponseAccepted);

           var res = prompts.AcquirePoint(opts);
           if (res.Value != location)
           {
               location = res.Value;
           }
           else
           {
               return SamplerStatus.NoChange;
           }
           if (res.Status == PromptStatus.Cancel)
           {
               return SamplerStatus.Cancel;
           }
           else
           {
               return SamplerStatus.OK;
           }
       }

       protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
       {
           Updata();
           draw.Geometry.Draw(polyine);
           return true;
       }
       public Polyline Updata()
       {
           index = polyine.NumberOfVertices - 1;
          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山水CAD插件定制

你的鼓励是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值