144 lines
4.5 KiB
C#
144 lines
4.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 XArcJig : XUiJigBase
|
|
{
|
|
public XArcJig(UIDocument uiDoc)
|
|
: base(uiDoc)
|
|
{
|
|
this.JigStage = XArcJig.EStage.eNoOper;
|
|
}
|
|
|
|
public XYZ PickCenterPoint(string strPrompt = "请确定圆弧中心点:")
|
|
{
|
|
try
|
|
{
|
|
this.JigStage = XArcJig.EStage.ePtCenter;
|
|
this.CenterPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|
}
|
|
catch
|
|
{
|
|
this.CenterPoint = null;
|
|
}
|
|
this.JigStage = XArcJig.EStage.eNoOper;
|
|
return this.CenterPoint;
|
|
}
|
|
|
|
public XYZ PickStartPoint(XYZ ptCenter, string strPrompt = "请确定圆弧起点:")
|
|
{
|
|
try
|
|
{
|
|
this.JigStage = XArcJig.EStage.ePtStart;
|
|
this.CenterPoint = ptCenter;
|
|
this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|
}
|
|
catch
|
|
{
|
|
this.StartPoint = null;
|
|
}
|
|
this.JigStage = XArcJig.EStage.eNoOper;
|
|
return this.StartPoint;
|
|
}
|
|
|
|
public XYZ PickEndPoint(XYZ ptCenter, XYZ ptStart, string strPrompt = "请确定圆弧终点:")
|
|
{
|
|
try
|
|
{
|
|
this.JigStage = XArcJig.EStage.ePtEnd;
|
|
this.CenterPoint = ptCenter;
|
|
this.StartPoint = ptStart;
|
|
this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|
this.EndPoint = this.method_13(this.EndPoint);
|
|
}
|
|
catch
|
|
{
|
|
this.EndPoint = null;
|
|
}
|
|
this.JigStage = XArcJig.EStage.eNoOper;
|
|
return this.EndPoint;
|
|
}
|
|
|
|
public override void Draw(PaintEventArgs paintEventArgs)
|
|
{
|
|
base.Draw(paintEventArgs);
|
|
if (this.JigStage == XArcJig.EStage.ePtStart)
|
|
{
|
|
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);
|
|
}
|
|
else if (this.JigStage == XArcJig.EStage.ePtEnd)
|
|
{
|
|
try
|
|
{
|
|
XYZ xyz = base.Client2Revit(this.m_ptCur);
|
|
xyz = this.method_13(xyz);
|
|
XYZ xyz2 = this.StartPoint + 0.5 * (xyz - this.StartPoint);
|
|
XYZ xyz3 = this.method_13(xyz2);
|
|
XArc2D xarc2D = new XArc2D(base.Revit2Client(this.StartPoint), base.Revit2Client(xyz), base.Revit2Client(xyz3));
|
|
XGraphics xgraphics2 = new XGraphics(paintEventArgs.Graphics, base.JigPen);
|
|
xarc2D.Draw(xgraphics2);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
public override List<Curve> CreateCurves()
|
|
{
|
|
List<Curve> list = new List<Curve>();
|
|
try
|
|
{
|
|
if (this.CenterPoint != null && this.StartPoint != null && this.EndPoint != null)
|
|
{
|
|
XYZ xyz = this.StartPoint + 0.5 * (this.EndPoint - this.StartPoint);
|
|
XYZ xyz2 = this.method_13(xyz);
|
|
Arc arc = Arc.Create(this.StartPoint, this.EndPoint, xyz2);
|
|
list.Add(arc);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private XYZ method_13(XYZ xyz_3)
|
|
{
|
|
double num = this.CenterPoint.DistanceTo(this.StartPoint);
|
|
Plane plane = Plane.CreateByNormalAndOrigin(base.UiDoc.ActiveView.ViewDirection, this.CenterPoint);
|
|
Arc arc = Arc.Create(plane, num, 0.0, Math.PI);
|
|
arc.MakeUnbound();
|
|
return arc.Project(xyz_3).XYZPoint;
|
|
}
|
|
|
|
public XYZ CenterPoint { get; set; }
|
|
|
|
public XYZ StartPoint { get; set; }
|
|
|
|
public XYZ EndPoint { get; set; }
|
|
|
|
public XArcJig.EStage JigStage { get; set; }
|
|
|
|
public enum EStage
|
|
{
|
|
eNoOper,
|
|
ePtCenter,
|
|
ePtStart,
|
|
ePtEnd
|
|
}
|
|
}
|
|
}
|