using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Runtime.CompilerServices; using System.Windows.Forms; using Rectangle = System.Drawing.Rectangle; namespace HYJig { public class XCurvesJig : XUiJigBase { public XCurvesJig(UIDocument uiDoc, bool bGraphicsDoubleBuffer = false) : base(uiDoc) { this.JigStage = XCurvesJig.EStage.eNoOper; this.bool_1 = bGraphicsDoubleBuffer; } public XYZ DragCurves(List lstCurve, XYZ ptBase, string strPrompt = "请确定插入点:") { try { this.Curves = lstCurve; this.BasePoint = ptBase; this.JigStage = XCurvesJig.EStage.ePickPoint; this.PickPoint = base.UiDoc.Selection.PickPoint(this.BasePoint, base.UiDoc, strPrompt); } catch { if (this.m_prompDlg != null && base.CmdEndType == XUiJigBase.ECmdEndType.eEnter) { base.CmdEndType = XUiJigBase.ECmdEndType.eOther; XYZ xyz = base.Client2Revit(this.m_ptCur); string inputValue = this.m_prompDlg.GetInputValue(); double num = Convert.ToDouble(inputValue) / 304.8; XYZ xyz2 = (xyz - this.BasePoint).Normalize(); this.PickPoint = this.BasePoint + xyz2 * num; } else { this.PickPoint = null; } } this.JigStage = XCurvesJig.EStage.eNoOper; return this.PickPoint; } public override void Draw(PaintEventArgs paintEventArgs) { base.Draw(paintEventArgs); if (this.JigStage == XCurvesJig.EStage.ePickPoint) { base.Revit2Client(this.BasePoint); Point ptCur = this.m_ptCur; JigFuncs.Client2Screen(this.m_hMDIActiveChildClientWnd, ref ptCur); XYZ xyz = base.Screen2Revit(ptCur); XYZ xyz2 = xyz - this.BasePoint; Transform transform = Transform.CreateTranslation(xyz2); List list = new List(); foreach (Curve curve in this.Curves) { if (curve is Line) { Line line = curve as Line; XYZ xyz3 = line.GetEndPoint(0); XYZ xyz4 = line.GetEndPoint(1); xyz3 = transform.OfPoint(xyz3); xyz4 = transform.OfPoint(xyz4); Point point = base.Revit2Client(xyz3); Point point2 = base.Revit2Client(xyz4); XLine2D xline2D = new XLine2D(point, point2); list.Add(xline2D); } else if (curve is Arc) { Arc arc = curve as Arc; if (arc.IsBound) { XYZ xyz5 = arc.GetEndPoint(0); XYZ xyz6 = arc.GetEndPoint(1); XYZ xyz7 = arc.Evaluate(0.5, true); xyz5 = transform.OfPoint(xyz5); xyz6 = transform.OfPoint(xyz6); xyz7 = transform.OfPoint(xyz7); Point point3 = base.Revit2Client(xyz5); Point point4 = base.Revit2Client(xyz6); Point point5 = base.Revit2Client(xyz7); XArc2D xarc2D = new XArc2D(point3, point4, point5); list.Add(xarc2D); } else { XYZ xyz8 = arc.Center; XYZ xyz9 = xyz8 + base.UiDoc.ActiveView.RightDirection * arc.Radius; xyz8 = transform.OfPoint(xyz8); xyz9 = transform.OfPoint(xyz9); Point point6 = base.Revit2Client(xyz8); Point point7 = base.Revit2Client(xyz9); int distance = XDrawable2D.GetDistance(point7, point6); XCircle2D xcircle2D = new XCircle2D(point6, distance); list.Add(xcircle2D); } } } Graphics graphics = paintEventArgs.Graphics; if (this.bool_1) { Class1.Struct1 @struct; Class1.GetClientRect(this.m_hMDIActiveChildClientWnd, out @struct); Rectangle rectangle = new Rectangle(@struct.int_0, @struct.WuApKkPsaL, @struct.int_1 - @struct.int_0, @struct.int_2 - @struct.WuApKkPsaL); BufferedGraphics bufferedGraphics = BufferedGraphicsManager.Current.Allocate(graphics, rectangle); Graphics graphics2 = bufferedGraphics.Graphics; graphics2.SmoothingMode = SmoothingMode.HighQuality; graphics2.PixelOffsetMode = PixelOffsetMode.HighSpeed; XGraphics xgraphics = new XGraphics(graphics2, base.JigPen); foreach (XDrawable2D xdrawable2D in list) { xdrawable2D.Draw(xgraphics); } bufferedGraphics.Render(xgraphics.m_graphics); bufferedGraphics.Dispose(); } else { XGraphics xgraphics2 = new XGraphics(graphics, base.JigPen); foreach (XDrawable2D xdrawable2D2 in list) { xdrawable2D2.Draw(xgraphics2); } } } } public override List CreateCurves() { List list = new List(); try { if (this.PickPoint != null) { Transform transform = Transform.CreateTranslation(this.PickPoint - this.BasePoint); foreach (Curve curve in this.Curves) { Curve curve2 = curve.CreateTransformed(transform); list.Add(curve2); } } } catch { } return list; } public List Curves { get; set; } public XYZ BasePoint { get; set; } public XYZ PickPoint { get; set; } public XCurvesJig.EStage JigStage { get; set; } private bool bool_1 = false; public enum EStage { eNoOper, ePickPoint } } }