- 积分
- 8053
- 明经币
- 个
- 注册时间
- 2013-8-9
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2020-1-10 14:38:04
|
显示全部楼层
本帖最后由 j15tty 于 2020-1-10 14:44 编辑
C:\Users\Administrator\Desktop\GIF动画录制工具20200110141850.gif- public class 坡度标注Jig : DrawJig
- {
- public Autodesk.AutoCAD.DatabaseServices.Polyline m_pl;
- private Point3d m_pt, m_insertPt;
- public static DBText m_text = new DBText();
- private Curve m_c;
- public static double m_bl = 1;
- public static double m_jj = 3;
- public static double m_h = 3;
- private Database m_db;
- public 坡度标注Jig(Autodesk.AutoCAD.DatabaseServices.Polyline pl, DBText text, Curve c, Point3d pt, Database db, double bl, double jj, double h)
- {
- m_pl = pl;
- m_pt = pt;
- m_text = text;
- m_c = c;
- m_db = db;
- m_bl = bl;
- m_jj = jj;
- m_h = h;
- }
- protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
- {
- Point3d p1 = m_c.GetClosestPointTo(m_insertPt, false);
- Vector3d vecCz = m_insertPt - p1;//鼠标点到曲线的垂足点的向量
- Vector3d vec = m_insertPt - m_pt;//得到鼠标与曲线上点取点的向量
- Vector3d vec1 = m_c.GetFirstDerivative(m_pt);//曲线点切向量
- double angFx = vec.GetAngleTo(Vector3d.XAxis, -Vector3d.ZAxis);//鼠标点与曲线上点取点向量与X轴的夹角;
- double angQx = vec1.GetAngleTo(Vector3d.XAxis, -Vector3d.ZAxis);
- double ang = vec.GetAngleTo(vec1);
- Point3d insertPt, pt1, pt2, pt3;
- bool flag = IsLeftOfCurve(m_c, m_insertPt);
- if (flag == true)
- {
- insertPt = m_pt.polarPoint(angQx + Math.PI / 2, m_jj);
- if (ang < Math.PI / 2)
- {
- pt1 = insertPt.polarPoint(angQx + Math.PI, m_bl * 5);
- pt2 = pt1.polarPoint(angQx, m_bl * 10);
- pt3 = pt2.polarPoint(angQx, m_bl * 3.5);
- m_text.Position = insertPt.polarPoint(angQx + Math.PI / 2, m_bl * 0.5 + m_text.Height / 2);
- m_text.Rotation = angQx;
- m_text.Height = m_h;
- m_text.HorizontalMode = TextHorizontalMode.TextMid;
- m_text.VerticalMode = TextVerticalMode.TextBottom;
- m_text.AlignmentPoint = m_text.Position;
- m_text.AdjustAlignment(m_db);
- }
- else
- {
- pt1 = insertPt.polarPoint(angQx, m_bl * 5);
- pt2 = pt1.polarPoint(angQx + Math.PI, m_bl * 10);
- pt3 = pt2.polarPoint(angQx + Math.PI, m_bl * 3.5);
- m_text.Position = insertPt.polarPoint(angQx + Math.PI / 2, m_bl * 0.5 + m_text.Height / 2);
- m_text.Rotation = angQx;
- m_text.Height = m_h;
- m_text.HorizontalMode = TextHorizontalMode.TextMid;
- m_text.VerticalMode = TextVerticalMode.TextBottom;
- m_text.AlignmentPoint = m_text.Position;
- m_text.AdjustAlignment(m_db);
- }
- }
- else
- {
- insertPt = m_pt.polarPoint(angQx - Math.PI / 2, m_jj);
- if (ang < Math.PI / 2)
- {
- pt1 = insertPt.polarPoint(angQx + Math.PI, m_bl * 5);
- pt2 = pt1.polarPoint(angQx, m_bl * 10);
- pt3 = pt2.polarPoint(angQx, m_bl * 3.5);
- m_text.Position = insertPt.polarPoint(angQx - Math.PI / 2, m_bl * 0.5 + m_text.Height / 2);
- m_text.Rotation = angQx + Math.PI;
- m_text.Height = m_h;
- m_text.HorizontalMode = TextHorizontalMode.TextMid;
- m_text.VerticalMode = TextVerticalMode.TextBottom;
- m_text.AlignmentPoint = m_text.Position;
- m_text.AdjustAlignment(m_db);
- }
- else
- {
- pt1 = insertPt.polarPoint(angQx, m_bl * 5);
- pt2 = pt1.polarPoint(angQx + Math.PI, m_bl * 10);
- pt3 = pt2.polarPoint(angQx + Math.PI, m_bl * 3.5);
- m_text.Position = insertPt.polarPoint(angQx - Math.PI / 2, m_bl * 0.5 + m_text.Height / 2);
- m_text.Rotation = angQx + Math.PI;
- m_text.Height = m_h;
- m_text.HorizontalMode = TextHorizontalMode.TextMid;
- m_text.VerticalMode = TextVerticalMode.TextBottom;
- m_text.AlignmentPoint = m_text.Position;
- m_text.AdjustAlignment(m_db);
- }
- }
- m_pl.Normal = Vector3d.ZAxis;
- m_pl.Elevation = 0.0;
- m_pl.SetPointAt(0, new Point2d(pt1.X, pt1.Y));
- m_pl.SetPointAt(1, new Point2d(pt2.X, pt2.Y));
- m_pl.SetPointAt(2, new Point2d(pt3.X, pt3.Y));
- m_pl.SetStartWidthAt(0, 0);
- m_pl.SetEndWidthAt(0, 0);
- m_pl.SetStartWidthAt(1, m_bl);
- m_pl.SetEndWidthAt(1, 0);
- m_pl.SetStartWidthAt(2, 0);
- m_pl.SetEndWidthAt(2, 0);
- draw.Geometry.Draw(m_pl);
- draw.Geometry.Draw(m_text);
- return true;
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- Matrix3d mat = ed.CurrentUserCoordinateSystem;
- JigPromptPointOptions optInsertPt = new JigPromptPointOptions("\n请选择方向或[比例增(A)/比例减(S)/间距增(D)/间距减(F)/坡度设置(Q)]");
- optInsertPt.UserInputControls = (UserInputControls.Accept3dCoordinates |
- UserInputControls.NullResponseAccepted |
- UserInputControls.NoNegativeResponseAccepted |
- UserInputControls.GovernedByOrthoMode);
- optInsertPt.Keywords.Add("A");
- optInsertPt.Keywords.Add("S");
- optInsertPt.Keywords.Add("D");
- optInsertPt.Keywords.Add("F");
- optInsertPt.Keywords.Add("Q");
- optInsertPt.AppendKeywordsToMessage = false;
- //m_pt = m_pt.TransformBy(mat);
- PromptPointResult resJigInsertPt = prompts.AcquirePoint(optInsertPt);
- if (resJigInsertPt.Status == PromptStatus.Cancel)
- return SamplerStatus.Cancel;
- if (resJigInsertPt.Status == PromptStatus.Keyword)
- {
- switch (resJigInsertPt.StringResult)
- {
- case "A":
- {
- m_bl = m_bl * 2;
- m_h = m_h * 2;
- break;
- }
- case "S":
- {
- m_bl = m_bl * 0.5;
- m_h = m_h * 0.5;
- break;
- }
- case "D":
- {
- m_jj = m_jj * 1.1;
- break;
- }
- case "F":
- {
- m_jj = m_jj * 0.9;
- break;
- }
- case "Q":
- {
- PromptStringOptions opt = new PromptStringOptions("\n请输入坡度");
- PromptResult res = ed.GetString(opt);
- if (res.Status != PromptStatus.OK)
- break;
- else
- {
- try
- {
- double value = Convert.ToDouble(res.StringResult);
- if (value >= 10)
- {
- if (MyEntity.IsInteger(res.StringResult))
- {
- m_text.TextString = (value / 10).ToString("0") + "%";
- }
- else
- {
- m_text.TextString = (value / 10).ToString("0.####") + "%";
- }
- }
- else
- m_text.TextString = res.StringResult + "‰";
- }
- catch (System.Exception ex)
- {
- ed.WriteMessage(ex.Message);
- m_text.TextString = "3" + "‰";
- }
- }
- break;
- }
- }
- }
- if (m_insertPt != resJigInsertPt.Value)
- {
- m_insertPt = resJigInsertPt.Value;
- return SamplerStatus.OK;
- }
- else
- {
- return SamplerStatus.NoChange;
- }
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|