109 lines
3.5 KiB
C#
109 lines
3.5 KiB
C#
|
|
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 XCircleJig : XUiJigBase
|
|||
|
|
{
|
|||
|
|
public XCircleJig(UIDocument uiDoc)
|
|||
|
|
: base(uiDoc)
|
|||
|
|
{
|
|||
|
|
this.JigStage = XCircleJig.EStage.eNoOper;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XYZ PickCenterPoint(string strPrompt = "请确定圆中心点:")
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.JigStage = XCircleJig.EStage.eCenterPt;
|
|||
|
|
this.CenterPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
this.CenterPoint = null;
|
|||
|
|
}
|
|||
|
|
this.JigStage = XCircleJig.EStage.eNoOper;
|
|||
|
|
return this.CenterPoint;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public double PickCircleRadius(XYZ ptCenter, string strPrompt = "请确定圆上一点:")
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.JigStage = XCircleJig.EStage.eOnCurve;
|
|||
|
|
this.CenterPoint = ptCenter;
|
|||
|
|
this.OnCurvePoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
if (this.m_prompDlg == null || base.CmdEndType != XUiJigBase.ECmdEndType.eEnter)
|
|||
|
|
{
|
|||
|
|
this.OnCurvePoint = null;
|
|||
|
|
return 0.0;
|
|||
|
|
}
|
|||
|
|
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.CenterPoint).Normalize();
|
|||
|
|
this.OnCurvePoint = this.CenterPoint + xyz2 * num;
|
|||
|
|
}
|
|||
|
|
this.JigStage = XCircleJig.EStage.eNoOper;
|
|||
|
|
return this.CenterPoint.DistanceTo(this.OnCurvePoint);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void Draw(PaintEventArgs paintEventArgs)
|
|||
|
|
{
|
|||
|
|
base.Draw(paintEventArgs);
|
|||
|
|
if (this.JigStage == XCircleJig.EStage.eOnCurve)
|
|||
|
|
{
|
|||
|
|
Graphics graphics = paintEventArgs.Graphics;
|
|||
|
|
Point point = base.Revit2Client(this.CenterPoint);
|
|||
|
|
int distance = XDrawable2D.GetDistance(point, this.m_ptCur);
|
|||
|
|
XCircle2D xcircle2D = new XCircle2D(point, distance);
|
|||
|
|
XGraphics xgraphics = new XGraphics(graphics, base.JigPen);
|
|||
|
|
xcircle2D.Draw(xgraphics);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override List<Curve> CreateCurves()
|
|||
|
|
{
|
|||
|
|
List<Curve> list = new List<Curve>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (this.CenterPoint != null && this.OnCurvePoint != null)
|
|||
|
|
{
|
|||
|
|
double num = this.CenterPoint.DistanceTo(this.OnCurvePoint);
|
|||
|
|
Plane plane = Plane.CreateByNormalAndOrigin(base.SketchPlane.GetPlane().Normal, this.CenterPoint);
|
|||
|
|
Arc arc = Arc.Create(plane, num, 0.0, Math.PI);
|
|||
|
|
arc.MakeUnbound();
|
|||
|
|
list.Add(arc);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
return list;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XYZ CenterPoint { get; set; }
|
|||
|
|
|
|||
|
|
public XYZ OnCurvePoint { get; set; }
|
|||
|
|
|
|||
|
|
public XCircleJig.EStage JigStage { get; set; }
|
|||
|
|
|
|||
|
|
public enum EStage
|
|||
|
|
{
|
|||
|
|
eNoOper,
|
|||
|
|
eCenterPt,
|
|||
|
|
eOnCurve
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|