- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2009-6-27 22:59:00
|
显示全部楼层
试着改写成PolyLine的,:)
没有考虑Ucs的- class PolyLineJig : DrawJig
- {
- ObjectId m_PolyLine = ObjectId.Null;
- Point3d m_FirstPoint;
- Polyline m_CurrPolyLine;
- Point3d m_StartPoint = Point3d.Origin;
- Vector3d m_StartVector = Vector3d.XAxis;
- Point3d m_EndPoint;
- bool m_IsLine = true;
- int m_Count = -1;
- PolyLineJigStatus m_Status = PolyLineJigStatus.Add;
- public enum PolyLineJigStatus
- {
- Add,
- Keyword,
- Undo,
- Finish,
- Close,
- }
- public PolyLineJig()
- {
- m_CurrPolyLine = new Polyline();
- m_CurrPolyLine.AddVertexAt(0, m_StartPoint.Convert2d(new Plane()), 0, 0, 0);
- m_CurrPolyLine.AddVertexAt(0, m_StartPoint.Convert2d(new Plane()), 0, 0, 0);
- }
- public PolyLineJigStatus JigStatus
- {
- get { return m_Status; }
- set { m_Status = value; }
- }
- public Point3d StartPoint
- {
- get { return m_StartPoint; }
- }
- public Point3d EndPoint
- {
- get { return m_EndPoint; }
- }
- protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
- {
- if (m_Count > -1)
- {
- double bugle = GetBugle();
- if (bugle != 0)
- {
- m_CurrPolyLine.SetBulgeAt(0, GetBugle());
- m_CurrPolyLine.SetPointAt(1, m_EndPoint.Convert2d(new Plane()));
- return draw.Geometry.Draw(m_CurrPolyLine);
- }
- }
- return true;
- }
- private double GetBugle()
- {
- if (m_IsLine)
- {
- return 0;
- }
- else
- {
- Plane plane = new Plane();
- double ang = (m_EndPoint - m_StartPoint).AngleOnPlane(plane);
- ang -= m_StartVector.AngleOnPlane(plane);
- return Math.Tan(ang * 0.5);
- }
- }
- public Polyline Update()
- {
- Polyline pl;
- switch (m_Status)
- {
- case PolyLineJigStatus.Add:
- case PolyLineJigStatus.Close:
- if (m_Count > -1)
- {
- pl = (Polyline)m_PolyLine.GetObject(OpenMode.ForWrite);
- pl.SetBulgeAt(m_Count, GetBugle());
- }
- else
- {
- pl = new Polyline();
- m_FirstPoint = m_EndPoint;
- }
- m_Count++;
- pl.AddVertexAt(m_Count, m_EndPoint.Convert2d(new Plane()), GetBugle(), 0, 0);
- m_StartPoint = m_EndPoint;
- m_CurrPolyLine.SetPointAt(0, m_StartPoint.Convert2d(new Plane()));
- try
- {
- m_StartVector = pl.GetFirstDerivative(pl.EndParam);
- }
- catch
- {
- m_StartVector = Vector3d.XAxis;
- }
- return pl;
- case PolyLineJigStatus.Undo:
- pl = (Polyline)m_PolyLine.GetObject(OpenMode.ForWrite);
- if (m_Count == 0)
- {
- pl.Erase(true);
- m_PolyLine = ObjectId.Null;
- }
- else
- {
- pl.RemoveVertexAt(m_Count);
- m_StartPoint = pl.EndPoint;
- m_CurrPolyLine.SetPointAt(0, m_StartPoint.Convert2d(new Plane()));
- }
- m_Count--;
- if (m_Count > -1)
- {
- m_StartPoint = pl.GetPoint3dAt(m_Count);
- }
- try
- {
- m_StartVector = pl.GetFirstDerivative(pl.EndParam);
- }
- catch
- {
- m_StartVector = Vector3d.XAxis;
- }
- break;
- }
-
- return null;
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- JigPromptPointOptions jigOpts = new JigPromptPointOptions();
- jigOpts.UserInputControls =
- UserInputControls.Accept3dCoordinates |
- UserInputControls.NoZeroResponseAccepted |
- UserInputControls.NoNegativeResponseAccepted |
- UserInputControls.NullResponseAccepted;
- switch (m_Count)
- {
- case -1:
- jigOpts.Message = "\n指定第一点:";
- break;
- case 0:
- case 1:
- jigOpts.Cursor = CursorType.RubberBand;
- jigOpts.Message = "\n指定下一个点:";
- if (m_IsLine)
- {
- jigOpts.Keywords.Add("Arc", "Arc", "圆弧(A)");
- }
- else
- {
- jigOpts.Keywords.Add("Line", "Line", "直线(L)");
- }
- jigOpts.Keywords.Add("Undo", "Undo", "放弃(U)");
- jigOpts.UseBasePoint = true;
- jigOpts.BasePoint = m_StartPoint;
- break;
- default:
- jigOpts.Cursor = CursorType.RubberBand;
- jigOpts.Message = "\n指定下一个点:";
- if (m_IsLine)
- {
- jigOpts.Keywords.Add("Arc", "Arc", "圆弧(A)");
- }
- else
- {
- jigOpts.Keywords.Add("Line", "Line", "直线(L)");
- }
- jigOpts.Keywords.Add("Close", "Close", "闭合(C)");
- jigOpts.Keywords.Add("Undo", "Undo", "放弃(U)");
- jigOpts.UseBasePoint = true;
- jigOpts.BasePoint = m_StartPoint;
- break;
- }
- PromptPointResult res = prompts.AcquirePoint(jigOpts);
- m_Status = PolyLineJigStatus.Add;
- switch (res.Status)
- {
- case PromptStatus.Cancel:
- case PromptStatus.None:
- m_Status = PolyLineJigStatus.Finish;
- return SamplerStatus.Cancel;
- case PromptStatus.Keyword:
- switch (res.StringResult)
- {
- case "Arc":
- case "Line":
- m_IsLine = !m_IsLine;
- m_Status = PolyLineJigStatus.Keyword;
- return SamplerStatus.OK;
- case "Add":
- m_Status = PolyLineJigStatus.Add;
- return SamplerStatus.OK;
- case "Undo":
- m_Status = PolyLineJigStatus.Undo;
- return SamplerStatus.OK;
- case "Close":
- m_EndPoint = m_FirstPoint;
- m_Status = PolyLineJigStatus.Close;
- return SamplerStatus.Cancel;
- }
- break;
- default:
- Point3d positionTemp = res.Value;
- if (positionTemp != m_EndPoint)
- {
- m_EndPoint = positionTemp;
- }
- else
- {
- return SamplerStatus.NoChange;
- }
- break;
- }
- return SamplerStatus.OK;
- }
- [CommandMethod("plj")]
- public static void DoIt()
- {
- PolyLineJig ljig = new PolyLineJig();
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- while (ljig.JigStatus != PolyLineJigStatus.Finish)
- {
- ed.Drag(ljig);
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- Polyline pl = ljig.Update();
- if (ljig.m_PolyLine == ObjectId.Null && pl != null)
- {
- BlockTableRecord btr = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
- ljig.m_PolyLine = btr.AppendEntity(pl);
- tr.AddNewlyCreatedDBObject(pl, true);
- }
- tr.Commit();
- }
- if (ljig.JigStatus == PolyLineJigStatus.Close)
- ljig.JigStatus = PolyLineJigStatus.Finish;
- }
- }
- }
|
评分
-
参与人数 2 | 威望 +1 |
明经币 +3 |
金钱 +70 |
贡献 +5 |
激情 +5 |
收起
理由
|
xgr
| |
+ 1 |
+ 50 |
|
|
jigOpts.Cursor = CursorType.RubberBand找. |
ahlzl
| + 1 |
+ 2 |
+ 20 |
+ 5 |
+ 5 |
【精华】好程序 |
查看全部评分
|