码迷,mamicode.com
首页 > 其他好文 > 详细

Kean专题 内容Jig 在绘图界面动态显示坐标

时间:2015-10-16 23:12:51      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

二、在绘图界面动态显示坐标

原文转载自http://through-the-interface.typepad.com/through_the_interface/jigs/(该口已无法访问)

可访问转载入口http://bbs.mjtd.com/thread-75618-1-1.html(转载自明镜通道by雪山飞狐_lzh

原kean博客已经无法看到,故转载明经通道 雪山飞狐_lzh 老师整理内容

1.kean博客原文翻译

December 12, 2008
Drawing text planar to the screen inside AutoCAD‘s drawing window using .NET

在AutoCAD的绘图窗口中利用.net绘制平面文本到屏幕上
I‘ve often seen the question, over the years, of how to draw text in the plane of the screen, even when the

多年以来,我时常看到这样的问题,如何在屏幕平面上绘制文本,甚至当当前视图对于当前用户坐标系并不是平

current view is not planar to the current UCS. This ability to "screen fix" text has been there, but has required

的时候                                                               这种屏幕定位文本的能力是存在的,但是需要一系列的变化技巧

a number of sometimes tricky transformations to get the right behaviour. Well, during a recent internal

才能得到正确的结果                                                                                   好在,经过最近的内部讨论,

discussion I became aware of a really handy facility inside AutoCAD which allows you to dependably draw screen-fixed text without jumping through hoops.

我开始意识到在cad内容真的存在方便的方法,它允许我们不必屈从于变换,便可获得可靠的被固定的屏幕文本
In this simple example, we‘re implementing a DrawJig - a jig that doesn‘t host an entity but allows us to

implement a WorldDraw() callback for something to be drawn - which draws text at a fixed screen location, with a fixed size and orientation.

在这个简单的例子中,我们将实现一个Drawjig的子类(一个拖拽类型可以宿主一个实体,并且允许我们去实现一个WorldDraw方法,来回调我们需要绘制的一些东西),他可以以固定的尺寸和坐标原点在固定的位置上绘制文本

Our code takes the simple task of asking the user to select a point, and shows the current cursor location during the drag at an offset of 30, 30 from the bottom left corner of the drawing window.

我们的代码执行一个简单的任务,应答用户选择的一个点,并且在当前绘图窗口的左下角距离(30,30)坐标点的偏移量的位置显示在拖拽过程中光标所在位置坐标
Here‘s the C# code:

下面是C#代码

  1. using Autodesk.AutoCAD.ApplicationServices;

  2. 技术分享using Autodesk.AutoCAD.Runtime;

  3. 技术分享using Autodesk.AutoCAD.EditorInput;

  4. 技术分享using Autodesk.AutoCAD.Geometry;

  5. 技术分享using Autodesk.AutoCAD.GraphicsInterface;

  6. 技术分享namespace JigTextPlanarToScreen

  7. 技术分享{

  8. 技术分享 public class TextJig : DrawJig

  9. 技术分享  {

  10. 技术分享 private Point3d _position;

  11. 技术分享 public Point3d Position

  12. 技术分享    {

  13. 技术分享      get { return _position; }

  14. 技术分享    }

  15. 技术分享 // We‘ll keep our style alive rather than recreating it

  16. 技术分享 private TextStyle _style;

  17. 技术分享 public TextJig()

  18. 技术分享    {

  19. 技术分享      _style = new TextStyle();

  20. 技术分享      _style.Font =

  21. 技术分享 new FontDescriptor("Calibri", false, true, 0, 0);

  22. 技术分享      _style.TextSize = 10;

  23. 技术分享    }

  24. 技术分享 protected override SamplerStatus Sampler(JigPrompts prompts)

  25. 技术分享    {

  26. 技术分享      JigPromptPointOptions opts = new JigPromptPointOptions();

  27. 技术分享      opts.UserInputControls =

  28. 技术分享          UserInputControls.Accept3dCoordinates;

  29. 技术分享      opts.Message = "\nSelect point: ";

  30. 技术分享      PromptPointResult res = prompts.AcquirePoint(opts);

  31. 技术分享 if (res.Status == PromptStatus.OK)

  32. 技术分享      {

  33. 技术分享 if (_position == res.Value)

  34. 技术分享        {

  35. 技术分享 return SamplerStatus.NoChange;

  36. 技术分享        }

  37. 技术分享 else

  38. 技术分享        {

  39. 技术分享          _position = res.Value;

  40. 技术分享 return SamplerStatus.OK;

  41. 技术分享        }

  42. 技术分享      }

  43. 技术分享 return SamplerStatus.Cancel;

  44. 技术分享    }

  45. 技术分享 protected override bool WorldDraw(WorldDraw draw)

  46. 技术分享    {

  47. 技术分享 // We make use of another interface to push our transforms

  48. 技术分享      WorldGeometry2 wg2 = draw.Geometry as WorldGeometry2;

  49. 技术分享 if (wg2 != null)

  50. 技术分享      {

  51. 技术分享 // Push our transforms onto the stack

  52. 技术分享        wg2.PushOrientationTransform(

  53. 技术分享          OrientationBehavior.Screen

  54. 技术分享 );

  55. 技术分享        wg2.PushPositionTransform(

  56. 技术分享          PositionBehavior.Screen,

  57. 技术分享 new Point2d(30, 30)

  58. 技术分享 );

  59. 技术分享 // Draw our screen-fixed text

  60. 技术分享        wg2.Text(

  61. 技术分享 new Point3d(0, 0, 0),  // Position

  62. 技术分享 new Vector3d(0, 0, 1), // Normal

  63. 技术分享 new Vector3d(1, 0, 0), // Direction

  64. 技术分享          _position.ToString(), // Text

  65. 技术分享 true,                  // Rawness

  66. 技术分享          _style                // TextStyle

  67. 技术分享 );

  68. 技术分享 // Remember to pop our transforms off the stack

  69. 技术分享        wg2.PopModelTransform();

  70. 技术分享        wg2.PopModelTransform();

  71. 技术分享      }

  72. 技术分享 return true;

  73. 技术分享    }

  74. 技术分享 [CommandMethod("SELPT")]

  75. 技术分享 static public void SelectPointWithJig()

  76. 技术分享    {

  77. 技术分享 Document doc =

  78. 技术分享 Application.DocumentManager.MdiActiveDocument;

  79. 技术分享 Editor ed = doc.Editor;

  80. 技术分享      TextJig jig = new TextJig();

  81. 技术分享      PromptResult res = ed.Drag(jig);

  82. 技术分享 if (res.Status == PromptStatus.OK)

  83. 技术分享      {

  84. 技术分享        ed.WriteMessage(

  85. 技术分享 "\nPoint selected: {0}",

  86. 技术分享          jig.Position

  87. 技术分享 );

  88. 技术分享      }

  89. 技术分享    }

  90. 技术分享  }

  91. 技术分享}

Now let‘s see our SELPT command in action.
First in a fairly standard view:           And now in an arbitrary 3D view:
OK, that‘s it for today. Right now I‘m at our Developer Day event in Paris, and after this I‘m taking a four-week break over the holiday season. Which means my blog output is likely to slow down (to a trickle, perhaps even stop completely) over the coming weeks. So - just in case - I‘d like to wish all the readers of "Through the Interface" all the very best for the holiday season. Thank you for your continued support and readership over the last year, here‘s looking forward to a fun and productive 2009! :-)

 

 

2.Kean代码实现的图形展示:

技术分享                               技术分享

Kean专题 内容Jig 在绘图界面动态显示坐标

标签:

原文地址:http://www.cnblogs.com/sinper/p/4886618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!