明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: epwt

[JIG] DrawJig闪烁

[复制链接]
发表于 2020-9-30 08:51 | 显示全部楼层
    /// <summary>
    /// 模拟AutoCAD移动命令Move
    /// </summary>
    public void sMoveJig()
    {
      try
      {

        PromptSelectionResult psres = ac.ed.GetSelection();
        if (psres.Status != PromptStatus.OK)
          return;
        ents = new Entity[psres.Value.Count];
        using (Transaction ctrans = ac.db.TransactionManager.StartTransaction())
        {
          for (int i = 0; i < psres.Value.Count; i++)
          {
            Entity ent = (Entity)ctrans.GetObject(psres.Value[i].ObjectId, OpenMode.ForRead);
            ents[i] = (Entity)ent.Clone();
          }
          ctrans.Commit();
        }
        PromptPointResult ppRes = ac.ed.GetPoint("\n基准点");
        if (ppRes.Status != PromptStatus.OK)
          return;
        Point3d startPoint = ppRes.Value;
        _PrePosition = startPoint;
        PromptResult pres = ac.ed.Drag(this);
        if (pres.Status == PromptStatus.OK)
        {
          Vector3d displacementVector = _CurPosition - startPoint;
          using (Transaction ctrans = ac.db.TransactionManager.StartTransaction())
          {
            for (int i = 0; i < psres.Value.Count; i++)
            {
              Entity ent = (Entity)ctrans.GetObject(psres.Value[i].ObjectId, OpenMode.ForWrite);
              ent.TransformBy(Matrix3d.Displacement(displacementVector));
            }
            ctrans.Commit();
          }
        }
      }
      catch (System.Exception ex)
      {
        ae.WriteMessage(ex);
      }
      finally
      {
        for (int i = 0; i < ents.Length; i++)
        {
          ents[i].Dispose();
        }
      }
    }
发表于 2020-9-30 08:53 | 显示全部楼层
  public class aModifyJig : DrawJig

    /// <summary>
    /// 模拟AutoCAD移动命令Move
    /// </summary>
    [CommandMethod("sMove")]
    static public void sCmd_Move()
    {
      aModifyJig tJig = new aModifyJig();
      tJig.sMoveJig();
    }
发表于 2020-9-30 08:55 | 显示全部楼层
    protected override SamplerStatus Sampler(JigPrompts prompts)
    {
      try
      {
        JigPromptPointOptions jpOpt = new JigPromptPointOptions(_Note);
        jpOpt.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.InitialBlankTerminatesInput | UserInputControls.NullResponseAccepted);
        PromptPointResult userFeedback = prompts.AcquirePoint(jpOpt);
        if (userFeedback.Status == PromptStatus.Error) return SamplerStatus.Cancel;
        _CurPosition = userFeedback.Value;
        if (CursorHasMoved())
        {
          Vector3d displacementVector = _CurPosition - _PrePosition;
          for (int i = 0; i < ents.Length; i++)
          {
            ents[i].TransformBy(Matrix3d.Displacement(displacementVector));
          }
          _PrePosition = _CurPosition;
          return SamplerStatus.OK;
        }
        else
        {
          return SamplerStatus.NoChange;
        }
      }
      catch (System.Exception ex)
      {
        ae.WriteMessage(ex);
        return SamplerStatus.NoChange;
      }
    }
发表于 2020-9-30 08:56 | 显示全部楼层
    protected override bool WorldDraw(WorldDraw draw)
    {
      try
      {
        for (int i = 0; i < ents.Length; i++)
        {
          draw.Geometry.Draw(ents[i]);
        }
      }
      catch (System.Exception ex)
      {
        ae.WriteMessage(ex);
      }
      return true;
    }
    private bool CursorHasMoved()
    {
      return !(_CurPosition == _PrePosition);
    }
发表于 2020-9-30 08:57 | 显示全部楼层
    /// <summary>
    /// 移动并即时显示多个实体
    /// Version : 2008.12.12
    /// </summary>
    /// <param name="objClt">实体集合</param>
    /// <param name="basePoint">初始点</param>
    /// <param name="showOnly">只是显示,true : 只是显示图形并不把图形画出来;false : 最后会把图形画出来</param>
    /// <param name="note"></param>
    /// <returns>确认式的结束返回true,放弃或出错返回false</returns>
    public bool MoveJig(DBObjectCollection objClt, Point3d basePoint, bool showOnly, string note)
    {
      try
      {
        //_Note = note;
        ents = new Entity[objClt.Count];
        for (int i = 0; i < objClt.Count; i++)
        {
          ents[i] = (Entity)objClt[i].Clone();
        }
        _PrePosition = basePoint;
        PromptResult pRes = ac.ed.Drag(this);
        if (pRes.Status == PromptStatus.OK)
        {
          Vector3d displacementVector = _CurPosition - basePoint;
          for (int i = 0; i < objClt.Count; i++)
          {
            Entity ent = (Entity)objClt[i];
            ent.TransformBy(Matrix3d.Displacement(displacementVector));
          }
          if (showOnly)
            return true;
          else
          {
            an.DrawEntity(objClt, aEntclls.Null, false);
            return true;
          }
        }
        else
          return false;
      }
      catch (System.Exception ex)
      {
        ae.WriteMessage(ex);
      }
      finally
      {
        for (int i = 0; i < ents.Length; i++)
        {
          ents[i].Dispose();
        }
      }
      return false;
    }
发表于 2020-9-30 08:58 | 显示全部楼层
    /// <summary>
    /// 模拟AutoCAD复制命令Copy
    /// </summary>
    [CommandMethod("sCOPY")]
    static public void sCmd_Copy()
    {
      aModifyJig tJig = new aModifyJig();
      tJig.sCopyJig();
    }
    /// <summary>
    /// 模拟AutoCAD复制命令Copy
    /// </summary>
    public void sCopyJig()
    {
      try
      {
        PromptSelectionResult psRes = ac.ed.GetSelection();
        if (psRes.Status != PromptStatus.OK) return;
        ents = new Entity[psRes.Value.Count];
        using (Transaction ctrans = ac.db.TransactionManager.StartTransaction())
        {
          for (int i = 0; i < psRes.Value.Count; i++)
          {
            Entity ent = (Entity)ctrans.GetObject(psRes.Value[i].ObjectId, OpenMode.ForRead);
            ents[i] = (Entity)ent.Clone();
          }
          ctrans.Commit();
        }
        aApp.SetSystemVariable("OSMODE", 16383);
        _PrePosition = ac.ed.GetPoint("\nBase Point").Value;
        PromptResult pres = ac.ed.Drag(this);
        if (pres.Status == PromptStatus.OK)
        {
          DBObjectCollection dbClt = new DBObjectCollection();
          for (int i = 0; i < ents.Length; i++)
          {
            dbClt.Add(ents[i]);
          }
          an.DrawEntity(dbClt, aEntclls.Null, false);
        }
        else
        {
          for (int i = 0; i < ents.Length; i++)
          {
            ents[i].Dispose();
          }
        }
      }
      catch (System.Exception ex)
      {
        ae.WriteMessage(ex);
        for (int i = 0; i < ents.Length; i++)
        {
          ents[i].Dispose();
        }
      }
    }
发表于 2020-9-30 20:47 来自手机 | 显示全部楼层
本帖最后由 carrot1983 于 2020-9-30 21:28 编辑

移动的时候不要显示原对象的原位置。看样子是DRAWJIG闪烁的问题。是真无解。
发表于 2020-10-7 10:55 | 显示全部楼层
2020.10.07
记录一下,这一刻,
DrawJig不闪烁的解决办法:硬件加速要打勾。
发表于 2020-10-11 10:16 | 显示全部楼层
2020.10.11
在硬件加速的前提下。发现有两个系统变量。DRAGP1和DRAGP2
发表于 2020-10-12 18:53 来自手机 | 显示全部楼层
确实值得纪念 按楼主方法 我的也不闪烁了 原来命令行一直提示重生成已终止
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-3 03:06 , Processed in 0.234549 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表