using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System; using System.Collections.Generic; using System.Drawing; using System.Runtime.CompilerServices; using System.Windows.Forms; namespace HYJig { public class XRectJigPtP : XUiJigBase { public XRectJigPtP(UIDocument uiDoc) : base(uiDoc) { this.JigStage = XRectJigPtP.EStage.eNoOper; } public XYZ PickStartPoint(string strPrompt = "请确定矩形第一个角点:") { try { this.JigStage = XRectJigPtP.EStage.eStartPt; this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt); } catch { this.StartPoint = null; } this.JigStage = XRectJigPtP.EStage.eNoOper; return this.StartPoint; } public XYZ PickStartPointN(string strPrompt = "请确定矩形第一个角点:") { try { this.JigStage = XRectJigPtP.EStage.eStartPt; this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt); } catch { } this.JigStage = XRectJigPtP.EStage.eNoOper; return this.StartPoint; } public XYZ PickRectAngle(XYZ ptStart, string strPrompt = "请确定矩形方向:") { try { this.JigStage = XRectJigPtP.EStage.eAnglePt; this.StartPoint = ptStart; XYZ xyz = base.UiDoc.Selection.PickPoint(strPrompt); this.RectAngle = (xyz - this.StartPoint).Normalize(); } catch { } this.JigStage = XRectJigPtP.EStage.eNoOper; return this.RectAngle; } public XYZ PickEndPoint(XYZ ptStart, XYZ vtAngle, string strPrompt = "请确定矩形另一对角点:") { try { this.JigStage = XRectJigPtP.EStage.eEndPt; this.StartPoint = ptStart; this.RectAngle = vtAngle; this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt); } catch { this.EndPoint = null; } this.JigStage = XRectJigPtP.EStage.eNoOper; return this.EndPoint; } public XYZ PickEndPoint(XYZ ptStart, string strPrompt = "请确定矩形另一对角点:") { try { this.JigStage = XRectJigPtP.EStage.eEndPt; this.StartPoint = ptStart; this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt); } catch { } this.JigStage = XRectJigPtP.EStage.eNoOper; return this.EndPoint; } public override void Draw(PaintEventArgs paintEventArgs) { base.Draw(paintEventArgs); if (!this.m_ptCur.IsEmpty && paintEventArgs != null && this.JigStage == XRectJigPtP.EStage.eEndPt) { try { XYZ xyz = base.Client2Revit(this.m_ptCur); XYZ xyz2 = new XYZ(xyz.X, this.StartPoint.Y, this.StartPoint.Z); XYZ xyz3 = new XYZ(this.StartPoint.X, xyz.Y, this.StartPoint.Z); Point point = base.Revit2Client(this.StartPoint); Point point2 = base.Revit2Client(xyz2); Point point3 = base.Revit2Client(xyz3); Graphics graphics = paintEventArgs.Graphics; XGraphics xgraphics = new XGraphics(graphics, base.JigPen); XLine2D xline2D = new XLine2D(point, point2); xline2D.Draw(xgraphics); XLine2D xline2D2 = new XLine2D(point2, this.m_ptCur); xline2D2.Draw(xgraphics); XLine2D xline2D3 = new XLine2D(this.m_ptCur, point3); xline2D3.Draw(xgraphics); XLine2D xline2D4 = new XLine2D(point3, point); xline2D4.Draw(xgraphics); } catch { } } } public override List CreateCurves() { List list = new List(); try { XYZ xyz = new XYZ(this.EndPoint.X, this.StartPoint.Y, this.StartPoint.Z); XYZ xyz2 = new XYZ(this.StartPoint.X, this.EndPoint.Y, this.StartPoint.Z); Line line = Line.CreateBound(this.StartPoint, xyz); list.Add(line); Line line2 = Line.CreateBound(xyz, this.EndPoint); list.Add(line2); Line line3 = Line.CreateBound(this.EndPoint, xyz2); list.Add(line3); Line line4 = Line.CreateBound(xyz2, this.StartPoint); list.Add(line4); } catch { } return list; } public XYZ StartPoint { get; set; } public XYZ RectAngle { get; set; } public XYZ EndPoint { get; set; } public XRectJigPtP.EStage JigStage { get; set; } public enum EStage { eNoOper, eStartPt, eAnglePt, eEndPt } } }