137 lines
4.3 KiB
C#
137 lines
4.3 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 XArc3PtJig : XUiJigBase
|
|||
|
|
{
|
|||
|
|
public XArc3PtJig(UIDocument uiDoc)
|
|||
|
|
: base(uiDoc)
|
|||
|
|
{
|
|||
|
|
this.JigStage = XArc3PtJig.EStage.eNoOper;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XYZ PickStartPoint(string strPrompt = "请确定圆弧起点:")
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.JigStage = XArc3PtJig.EStage.eStartPt;
|
|||
|
|
this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
this.StartPoint = null;
|
|||
|
|
}
|
|||
|
|
this.JigStage = XArc3PtJig.EStage.eNoOper;
|
|||
|
|
return this.StartPoint;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XYZ PickEndPoint(XYZ ptStart, string strPrompt = "请确定圆弧终点:")
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.JigStage = XArc3PtJig.EStage.eEndPt;
|
|||
|
|
this.StartPoint = ptStart;
|
|||
|
|
this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|||
|
|
XYZ axisPoint = JigFuncs.GetAxisPoint(base.UiDoc, this.EndPoint, this.StartPoint);
|
|||
|
|
if (axisPoint != null)
|
|||
|
|
{
|
|||
|
|
this.EndPoint = axisPoint;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
this.EndPoint = null;
|
|||
|
|
}
|
|||
|
|
this.JigStage = XArc3PtJig.EStage.eNoOper;
|
|||
|
|
return this.EndPoint;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XYZ PickOnCurvePoint(XYZ ptStart, XYZ ptEnd, string strPrompt = "请确定圆弧上的点:")
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.JigStage = XArc3PtJig.EStage.eOnCurvePt;
|
|||
|
|
this.StartPoint = ptStart;
|
|||
|
|
this.EndPoint = ptEnd;
|
|||
|
|
this.OnCurvePoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
this.OnCurvePoint = null;
|
|||
|
|
}
|
|||
|
|
this.JigStage = XArc3PtJig.EStage.eNoOper;
|
|||
|
|
return this.OnCurvePoint;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void Draw(PaintEventArgs paintEventArgs)
|
|||
|
|
{
|
|||
|
|
base.Draw(paintEventArgs);
|
|||
|
|
if (this.JigStage == XArc3PtJig.EStage.eEndPt)
|
|||
|
|
{
|
|||
|
|
Point point = base.Revit2Client(this.StartPoint);
|
|||
|
|
Graphics graphics = paintEventArgs.Graphics;
|
|||
|
|
XYZ xyz = base.Client2Revit(this.m_ptCur);
|
|||
|
|
XYZ axisPoint = JigFuncs.GetAxisPoint(base.UiDoc, xyz, this.StartPoint);
|
|||
|
|
if (axisPoint != null)
|
|||
|
|
{
|
|||
|
|
this.m_ptCur = base.Revit2Client(axisPoint);
|
|||
|
|
base.DrawAxisLine(graphics, this.StartPoint, axisPoint);
|
|||
|
|
}
|
|||
|
|
XLine2D xline2D = new XLine2D(point, this.m_ptCur);
|
|||
|
|
XGraphics xgraphics = new XGraphics(graphics, base.JigPen);
|
|||
|
|
xline2D.Draw(xgraphics);
|
|||
|
|
}
|
|||
|
|
else if (this.JigStage == XArc3PtJig.EStage.eOnCurvePt)
|
|||
|
|
{
|
|||
|
|
Point point2 = base.Revit2Client(this.StartPoint);
|
|||
|
|
Point point3 = base.Revit2Client(this.EndPoint);
|
|||
|
|
Point ptCur = this.m_ptCur;
|
|||
|
|
Graphics graphics2 = paintEventArgs.Graphics;
|
|||
|
|
XArc2D xarc2D = new XArc2D(point2, point3, ptCur);
|
|||
|
|
XGraphics xgraphics2 = new XGraphics(graphics2, base.JigPen);
|
|||
|
|
xarc2D.Draw(xgraphics2);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override List<Curve> CreateCurves()
|
|||
|
|
{
|
|||
|
|
List<Curve> list = new List<Curve>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (this.StartPoint != null && this.EndPoint != null && this.OnCurvePoint != null)
|
|||
|
|
{
|
|||
|
|
Arc arc = Arc.Create(this.StartPoint, this.EndPoint, this.OnCurvePoint);
|
|||
|
|
list.Add(arc);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
return list;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XYZ StartPoint { get; set; }
|
|||
|
|
|
|||
|
|
public XYZ EndPoint { get; set; }
|
|||
|
|
|
|||
|
|
public XYZ OnCurvePoint { get; set; }
|
|||
|
|
|
|||
|
|
public XArc3PtJig.EStage JigStage { get; set; }
|
|||
|
|
|
|||
|
|
public enum EStage
|
|||
|
|
{
|
|||
|
|
eNoOper,
|
|||
|
|
eStartPt,
|
|||
|
|
eEndPt,
|
|||
|
|
eOnCurvePt
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|