- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2015-1-29 08:03 编辑
API 中这个函数仅考虑了 AttachmentPoint kTopLeft = 1 情况,未考虑其他 8 种情况,当对齐方式不为 1 时,求出的 Box 的左下角点是在 MText 的 AcDbMText::location 而非实际位置,下面是用 C# 写的 MText 真实 BOX
注意: 仅适用于 WCS 平行平面的 MText
- public static Point3d [] GetMtextBox(MText mText)
- {
- var pt = mText.Location;
- var angle = mText.Rotation;
- var width = mText.ActualWidth;
- var height = mText.ActualHeight;
- var result=new Point3d[4];
- var axis = new Vector3d(0, 0, 1);
- switch (mText.Attachment)
- {
- case AttachmentPoint.TopLeft:
- result [0] = pt + new Vector3d(0, -height, 0).RotateBy( angle,axis);
- result[1] = pt + new Vector3d(width, -height, 0).RotateBy( angle,axis);
- result[2] = pt + new Vector3d(width, 0, 0).RotateBy(angle, axis);
- result[3] = pt;
- break;
- case AttachmentPoint.TopCenter:
- result[0] = pt + new Vector3d(-width/2, -height, 0).RotateBy(angle, axis);
- result[1] = pt + new Vector3d(width/2, -height, 0).RotateBy(angle, axis);
- result[2] = pt + new Vector3d(width/2, 0, 0).RotateBy(angle, axis);
- result[3] = pt + new Vector3d(-width/2, 0, 0).RotateBy(angle, axis);
- break;
- case AttachmentPoint.TopRight:
- result[0] = pt + new Vector3d(-width, -height, 0.0).RotateBy(angle, axis);
- result[1] = pt + new Vector3d(0, -height, 0).RotateBy(angle, axis);
- result[2] = pt;
- result[3] = pt + new Vector3d(-width, 0, 0).RotateBy(angle, axis);
- break;
- case AttachmentPoint.MiddleLeft:
- result[0] = pt + new Vector3d(0, -height/2, 0).RotateBy(angle, axis);
- result[1] = pt + new Vector3d(width, -height/2, 0).RotateBy(angle, axis);
- result[2] = pt + new Vector3d(width, height/2, 0).RotateBy(angle, axis);
- result[3] = pt + new Vector3d(0, height/2, 0).RotateBy(angle, axis);
- break;
- case AttachmentPoint.MiddleCenter:
- result[0] = pt + new Vector3d(-width/2, -height/2, 0).RotateBy(angle, axis);
- result[1] = pt + new Vector3d(width/2, -height/2, 0).RotateBy(angle, axis);
- result[2] = pt + new Vector3d(width/2, height/2, 0).RotateBy(angle, axis);
- result[3] = pt + new Vector3d(-width/2, height/2, 0).RotateBy(angle, axis);
- break;
- case AttachmentPoint.MiddleRight:
- result[0] = pt + new Vector3d(-width, -height/2, 0).RotateBy(angle, axis);
- result[1] = pt + new Vector3d(0, -height/2, 0).RotateBy(angle, axis);
- result[2] = pt + new Vector3d(0, height/2, 0).RotateBy(angle, axis);
- result[3] = pt + new Vector3d(-width, height/2, 0).RotateBy(angle, axis);
- break;
- case AttachmentPoint.BottomLeft:
- result[0] = pt;
- result[1] = pt + new Vector3d(width, 0, 0).RotateBy(angle, axis);
- result[2] = pt + new Vector3d(width, height, 0).RotateBy(angle, axis);
- result[3] = pt + new Vector3d(0, height, 0).RotateBy(angle, axis);
- break;
- case AttachmentPoint.BottomCenter:
- result[0] = pt + new Vector3d(-width/2, 0, 0).RotateBy(angle, axis);
- result[1] = pt + new Vector3d(width/2, 0, 0).RotateBy(angle, axis);
- result[2] = pt + new Vector3d(width/2, height, 0).RotateBy(angle, axis);
- result[3] = pt + new Vector3d(-width/2, height, 0).RotateBy(angle, axis);
- break;
- case AttachmentPoint.BottomRight:
- result[0] = pt + new Vector3d(-width, 0, 0).RotateBy(angle, axis);
- result[1] = pt;
- result[2] = pt + new Vector3d(0, height, 0).RotateBy(angle, axis);
- result[3] = pt + new Vector3d(-width, height, 0).RotateBy(angle, axis);
- break;
- default:
- break;
- }
- return result;
- }
复制代码 |
|