- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2012-7-18 10:43:58
|
显示全部楼层
本帖最后由 雪山飞狐_lzh 于 2012-7-19 12:18 编辑
- /// <summary>
- /// 单行文字曲线分布+拖动
- /// </summary>
- [CommandMethod("Tls:TBC")]
- public static void TextByCurve()
- {
- var ed = SystemManager.Editor;
- var opts = new PromptEntityOptions("\n请选择文本:");
- opts.SetRejectMessage("你选择的不是文本,请重新选择!");
- opts.AddAllowedClass(typeof(DBText), true);
- var res1 = ed.GetEntity(opts);
- if (res1.Status != PromptStatus.OK) return;
- opts = new PromptEntityOptions("\n请选择曲线:");
- opts.SetRejectMessage("你选择的不是曲线,请重新选择!");
- opts.AddAllowedClass(typeof(Curve), false);
- var res2 = ed.GetEntity(opts);
- if (res1.Status != PromptStatus.OK) return;
- using (var tr = new DBTransaction())
- {
- var txt = tr.GetObject<DBText>(res1.ObjectId);
- var curve = tr.GetObject<Curve>(res2.ObjectId);
- double w = 0;
- var txts = new List<DBText>();
- var dists = new List<double>();
- foreach (char c in txt.TextString)
- {
- var s = c.ToString();
- var txtx =
- new DBText
- {
- Height = txt.Height,
- TextStyleId = txt.TextStyleId,
- TextString = s,
- };
- txtx.SetDatabaseDefaults();
- var width = AcUtils.GetTextExtents(txt.TextStyleId, s, txt.Height).X;
- txts.Add(txtx);
- dists.Add(w);
- w += width;
- }
- TextJig jig = new TextJig(txts, dists, curve);
- var resdrag = ed.Drag(jig);
- if (resdrag.Status == PromptStatus.OK)
- tr.AddEntity(tr.OpenCurrentSpace(), txts);
- }
- }
- class TextJig : DrawJig
- {
- List<DBText> _txts;
- List<double> _dists;
- Curve3d _curve;
- double _len;
- Point3d _pos;
- public TextJig(List<DBText> txts, List<double> dists, Curve curve)
- {
- _txts = txts;
- _dists = dists;
- _curve = curve.ToCurve3d();
- var interval = _curve.GetInterval();
- _len = _curve.GetLength(0, interval.UpperBound, 0);
- }
- protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
- {
- try
- {
- var poc = _curve.GetClosestPointTo(_pos, Tolerance.Global);
- Point3d pnt = poc.Point;
- double w = _curve.GetLength(0, poc.Parameter, 0);
- double n = 1;
- var vec = poc.GetDerivative(1);
- if ((_pos - pnt).GetAngleTo(vec, Vector3d.ZAxis) < Math.PI)
- n = -1;
- for(int i = 0; i< _txts.Count; i++)
- {
- var txtx = _txts;
- double dist = w + n * _dists;
- if (dist < 0 || dist > _len)
- {
- break;
- }
- else
- {
- poc.Parameter = _curve.GetParameterAtLength(0, dist, true, Tolerance.Global.EqualPoint);
- txtx.Position = poc.Point;
- vec = poc.GetDerivative(1) * n;
- txtx.Rotation = vec.GetAngleTo(Vector3d.XAxis, -Vector3d.ZAxis);
- draw.Geometry.Draw(txtx);
- }
- }
- return true;
- }
- catch
- {
- return false;
- }
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- JigPromptPointOptions jigOpts = new JigPromptPointOptions("\n请输入起点:");
- jigOpts.UserInputControls =
- UserInputControls.Accept3dCoordinates |
- UserInputControls.NoZeroResponseAccepted |
- UserInputControls.NoNegativeResponseAccepted;
- PromptPointResult res = prompts.AcquirePoint(jigOpts);
- Point3d pnt = res.Value;
- if (pnt != _pos)
- {
- _pos = pnt;
- }
- else
- return SamplerStatus.NoChange;
- if (res.Status == PromptStatus.Cancel)
- return SamplerStatus.Cancel;
- else
- return SamplerStatus.OK;
- }
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|