Files
RevitArchive/HYJigPro/XRectJig.cs
2026-02-23 14:58:05 +08:00

147 lines
4.9 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 XRectJig : XUiJigBase
{
public XRectJig(UIDocument uiDoc)
: base(uiDoc)
{
this.JigStage = XRectJig.EStage.eNoOper;
}
public XYZ PickStartPoint(string strPrompt = "请确定矩形第一个角点:")
{
try
{
this.JigStage = XRectJig.EStage.eStartPt;
this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt);
}
catch
{
this.StartPoint = null;
}
this.JigStage = XRectJig.EStage.eNoOper;
return this.StartPoint;
}
public XYZ PickRectAngle(XYZ ptStart, string strPrompt = "请确定矩形方向:")
{
try
{
this.JigStage = XRectJig.EStage.eAnglePt;
this.StartPoint = ptStart;
XYZ xyz = base.UiDoc.Selection.PickPoint(strPrompt);
this.RectAngle = (xyz - this.StartPoint).Normalize();
}
catch
{
}
this.JigStage = XRectJig.EStage.eNoOper;
return this.RectAngle;
}
public XYZ PickEndPoint(XYZ ptStart, XYZ vtAngle, string strPrompt = "请确定矩形另一对角点:")
{
try
{
this.JigStage = XRectJig.EStage.eEndPt;
this.StartPoint = ptStart;
this.RectAngle = vtAngle;
this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt);
}
catch
{
this.EndPoint = null;
}
this.JigStage = XRectJig.EStage.eNoOper;
return this.EndPoint;
}
public override void Draw(PaintEventArgs paintEventArgs)
{
base.Draw(paintEventArgs);
if (this.JigStage == XRectJig.EStage.eAnglePt)
{
Point point = base.Revit2Client(this.StartPoint);
Graphics graphics = paintEventArgs.Graphics;
XLine2D xline2D = new XLine2D(point, this.m_ptCur);
XGraphics xgraphics = new XGraphics(graphics, base.JigPen);
xline2D.Draw(xgraphics);
}
else if (this.JigStage == XRectJig.EStage.eEndPt)
{
try
{
XYZ xyz = base.Client2Revit(this.m_ptCur);
Line line = Line.CreateUnbound(this.StartPoint, this.RectAngle);
XYZ xyzpoint = line.Project(xyz).XYZPoint;
XYZ xyz2 = xyz + (this.StartPoint - xyzpoint);
Point point2 = base.Revit2Client(this.StartPoint);
Point point3 = base.Revit2Client(xyzpoint);
Point point4 = base.Revit2Client(xyz2);
Graphics graphics2 = paintEventArgs.Graphics;
XGraphics xgraphics2 = new XGraphics(graphics2, base.JigPen);
XLine2D xline2D2 = new XLine2D(point2, point3);
xline2D2.Draw(xgraphics2);
XLine2D xline2D3 = new XLine2D(point3, this.m_ptCur);
xline2D3.Draw(xgraphics2);
XLine2D xline2D4 = new XLine2D(this.m_ptCur, point4);
xline2D4.Draw(xgraphics2);
XLine2D xline2D5 = new XLine2D(point4, point2);
xline2D5.Draw(xgraphics2);
}
catch
{
}
}
}
public override List<Curve> CreateCurves()
{
List<Curve> list = new List<Curve>();
try
{
Line line = Line.CreateUnbound(this.StartPoint, this.RectAngle);
XYZ xyzpoint = line.Project(this.EndPoint).XYZPoint;
XYZ xyz = this.EndPoint + (this.StartPoint - xyzpoint);
Line line2 = Line.CreateBound(this.StartPoint, xyzpoint);
list.Add(line2);
Line line3 = Line.CreateBound(xyzpoint, this.EndPoint);
list.Add(line3);
Line line4 = Line.CreateBound(this.EndPoint, xyz);
list.Add(line4);
Line line5 = Line.CreateBound(xyz, this.StartPoint);
list.Add(line5);
}
catch
{
}
return list;
}
public XYZ StartPoint { get; set; }
public XYZ RectAngle { get; set; }
public XYZ EndPoint { get; set; }
public XRectJig.EStage JigStage { get; set; }
public enum EStage
{
eNoOper,
eStartPt,
eAnglePt,
eEndPt
}
}
}