using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Windows.Forms; namespace HYJig { public class GClass0 : XUiJigBase { [DllImport("User32.dll")] private static extern int SetCursorPos(int int_0, int int_1); public GClass0.EStage JigStage { get; set; } public GClass0(UIDocument uiDoc) : base(uiDoc) { this.JigStage = GClass0.EStage.eLeftDownPt; } public XYZ PickAuxiliaryFramePoint(string strPrompt = "请确定立管:") { XYZ xyz = null; try { xyz = base.UiDoc.Selection.PickPoint(strPrompt); } catch (Exception ex) { throw ex; } return xyz; } public override void Key(KeyEventArgs keyEventArgs) { base.Key(keyEventArgs); if (keyEventArgs.KeyData == Keys.Space) { this.method_13(); } } public override void Draw(PaintEventArgs paintEventArgs) { try { base.Draw(paintEventArgs); if (!this.m_ptCur.IsEmpty) { this.xVector = new XYZ(1.0, Math.Tan(this.angle * Math.PI / 180.0), 0.0).Normalize(); this.yVector = new XYZ(-Math.Tan(this.angle * Math.PI / 180.0), 1.0, 0.0).Normalize(); XGraphics xgraphics = new XGraphics(paintEventArgs.Graphics, base.JigPen); XYZ xyz = this.method_14(base.Client2Revit(this.m_ptCur), this.length / 304.8); XCircle2D xcircle2D = new XCircle2D(base.Revit2Client(xyz), XDrawable2D.GetDistance(base.Revit2Client(xyz), base.Revit2Client(xyz + this.diameter / 304.8 * new XYZ(1.0, 0.0, 0.0))) / 2); xcircle2D.Draw(xgraphics); if (this.isAuxiliaryFrame) { if (this.length != 0.0) { XYZ xyz2 = xyz.Add(-this.length / 304.8 / 2.0 * this.xVector).Add(this.length / 304.8 / 2.0 * this.yVector); XYZ xyz3 = xyz.Add(-this.length / 304.8 / 2.0 * this.xVector).Add(-this.length / 304.8 / 2.0 * this.yVector); XYZ xyz4 = xyz.Add(this.length / 304.8 / 2.0 * this.xVector).Add(this.length / 304.8 / 2.0 * this.yVector); XYZ xyz5 = xyz.Add(this.length / 304.8 / 2.0 * this.xVector).Add(-this.length / 304.8 / 2.0 * this.yVector); XLine2D xline2D = new XLine2D(base.Revit2Client(xyz2), base.Revit2Client(xyz3)); xline2D.Draw(xgraphics); xline2D = new XLine2D(base.Revit2Client(xyz3), base.Revit2Client(xyz5)); xline2D.Draw(xgraphics); xline2D = new XLine2D(base.Revit2Client(xyz5), base.Revit2Client(xyz4)); xline2D.Draw(xgraphics); xline2D = new XLine2D(base.Revit2Client(xyz4), base.Revit2Client(xyz2)); xline2D.Draw(xgraphics); if (this.bool_1) { this.bool_1 = false; GClass0.SetCursorPos(GClass0.ScreenCursorPosition.X - 1, GClass0.ScreenCursorPosition.Y); } } } } } catch (Exception ex) { throw ex; } } [DllImport("User32.dll")] public static extern int GetCursorPos(out Point point); public static Point ScreenCursorPosition { get { Point point = default(Point); GClass0.GetCursorPos(out point); return point; } } private void method_13() { if (this.JigStage == GClass0.EStage.eCenterPt) { this.JigStage = GClass0.EStage.eLeftUpPt; } else if (this.JigStage == GClass0.EStage.eLeftUpPt) { this.JigStage = GClass0.EStage.eLeftDownPt; } else if (this.JigStage == GClass0.EStage.eLeftDownPt) { this.JigStage = GClass0.EStage.eRightDownOper; } else if (this.JigStage == GClass0.EStage.eRightDownOper) { this.JigStage = GClass0.EStage.eRightUpOper; } else if (this.JigStage == GClass0.EStage.eRightUpOper) { this.JigStage = GClass0.EStage.eCenterPt; } GClass0.SetCursorPos(GClass0.ScreenCursorPosition.X + 1, GClass0.ScreenCursorPosition.Y); this.bool_1 = true; } private XYZ method_14(XYZ xyz_0, double double_0) { if (this.isAuxiliaryFrame) { if (this.JigStage == GClass0.EStage.eLeftUpPt) { xyz_0 = xyz_0.Add(double_0 / 2.0 * this.xVector).Add(-double_0 / 2.0 * this.yVector); } else if (this.JigStage == GClass0.EStage.eLeftDownPt) { xyz_0 = xyz_0.Add(double_0 / 2.0 * this.xVector).Add(double_0 / 2.0 * this.yVector); } else if (this.JigStage == GClass0.EStage.eRightDownOper) { xyz_0 = xyz_0.Add(-double_0 / 2.0 * this.xVector).Add(double_0 / 2.0 * this.yVector); } else if (this.JigStage == GClass0.EStage.eRightUpOper) { xyz_0 = xyz_0.Add(-double_0 / 2.0 * this.xVector).Add(-double_0 / 2.0 * this.yVector); } } return xyz_0; } public double length = 0.0; public double diameter = 0.0; public bool isAuxiliaryFrame = false; public double angle = 0.0; public XYZ xVector = new XYZ(1.0, 0.0, 0.0); public XYZ yVector = new XYZ(0.0, 1.0, 0.0); private bool bool_1 = false; public enum EStage { eCenterPt, eLeftUpPt, eLeftDownPt, eRightDownOper, eRightUpOper } } }