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

438 lines
20 KiB
C#

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using Color = System.Drawing.Color;
namespace HYJig
{
public class XLineJig : XUiJigBase, IDisposable
{
public XLineJig(UIDocument uiDoc)
: base(uiDoc)
{
this.JigStage = XLineJig.EStage.eNoOper;
this.ResetPoint = XUiJigBase.EResetPoint.eNoOper;
this.DragLineColor = Color.FromArgb(175, 222, 239);
this.PointAlignType = XLineJig.AlignType.eMiddle;
this.MutilLineDist = new List<double>();
this.DrawEndLine = false;
this.DrawSize = false;
int height = Screen.PrimaryScreen.Bounds.Height;
XLineJig.SizeOffset = (int)(0.006 * (double)height);
XLineJig.BorderLength = (int)(0.04 * (double)height);
XLineJig.SizeFont = new Font("Arial", 2.5f * (float)XLineJig.SizeOffset, GraphicsUnit.Pixel);
XLineJig.TextFormat = new StringFormat(StringFormatFlags.NoClip);
XLineJig.TextFormat.Alignment = StringAlignment.Center;
XLineJig.TextFormat.LineAlignment = StringAlignment.Center;
XLineJig.SizeLineColor = Color.FromArgb(126, 163, 255);
XLineJig.SizeTextBrush = new SolidBrush(base.JigPen.Color);
this.OnMouseLeaveFormClientEvent = (WndMsgManager.MouseLeaveFormClientEvnetHandler)Delegate.Combine(this.OnMouseLeaveFormClientEvent, new WndMsgManager.MouseLeaveFormClientEvnetHandler(this.method_13));
this.OnMouseMoveIntoFormClientEvent = (WndMsgManager.MouseMoveIntoFormClientEvnetHandler)Delegate.Combine(this.OnMouseMoveIntoFormClientEvent, new WndMsgManager.MouseMoveIntoFormClientEvnetHandler(this.method_14));
}
public XLineJig(UIDocument uiDoc, System.Windows.Forms.Form userForm)
: base(uiDoc)
{
this.JigStage = XLineJig.EStage.eNoOper;
this.ResetPoint = XUiJigBase.EResetPoint.eNoOper;
this.DragLineColor = Color.FromArgb(175, 222, 239);
this.PointAlignType = XLineJig.AlignType.eMiddle;
this.MutilLineDist = new List<double>();
this.DrawEndLine = false;
this.DrawSize = false;
int height = Screen.PrimaryScreen.Bounds.Height;
XLineJig.SizeOffset = (int)(0.006 * (double)height);
XLineJig.BorderLength = (int)(0.04 * (double)height);
XLineJig.SizeFont = new Font("Arial", 2.5f * (float)XLineJig.SizeOffset, GraphicsUnit.Pixel);
XLineJig.TextFormat = new StringFormat(StringFormatFlags.NoClip);
XLineJig.TextFormat.Alignment = StringAlignment.Center;
XLineJig.TextFormat.LineAlignment = StringAlignment.Center;
XLineJig.SizeLineColor = Color.FromArgb(126, 163, 255);
XLineJig.SizeTextBrush = new SolidBrush(base.JigPen.Color);
this.OnMouseLeaveFormClientEvent = (WndMsgManager.MouseLeaveFormClientEvnetHandler)Delegate.Combine(this.OnMouseLeaveFormClientEvent, new WndMsgManager.MouseLeaveFormClientEvnetHandler(this.method_13));
this.OnMouseMoveIntoFormClientEvent = (WndMsgManager.MouseMoveIntoFormClientEvnetHandler)Delegate.Combine(this.OnMouseMoveIntoFormClientEvent, new WndMsgManager.MouseMoveIntoFormClientEvnetHandler(this.method_14));
this.m_UserForm = userForm;
}
public new void Dispose()
{
base.Dispose();
XLineJig.SizeFont.Dispose();
XLineJig.TextFormat.Dispose();
XLineJig.SizeTextBrush.Dispose();
this.OnMouseLeaveFormClientEvent = (WndMsgManager.MouseLeaveFormClientEvnetHandler)Delegate.Remove(this.OnMouseLeaveFormClientEvent, new WndMsgManager.MouseLeaveFormClientEvnetHandler(this.method_13));
this.OnMouseMoveIntoFormClientEvent = (WndMsgManager.MouseMoveIntoFormClientEvnetHandler)Delegate.Remove(this.OnMouseMoveIntoFormClientEvent, new WndMsgManager.MouseMoveIntoFormClientEvnetHandler(this.method_14));
}
private void method_13(object sender, EventArgs e)
{
if (this.m_UserForm == null)
{
}
}
private void method_14(object sender, EventArgs e)
{
if (this.m_UserForm == null)
{
}
}
public XYZ PickStartPoint(string strPrompt = "请确定直线起点:")
{
try
{
this.JigStage = XLineJig.EStage.eStartPt;
this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt);
}
catch
{
this.StartPoint = null;
}
this.JigStage = XLineJig.EStage.eNoOper;
return this.StartPoint;
}
public XYZ PickEndPoint(XYZ ptStart, string strPrompt = "请确定直线终点:")
{
try
{
this.JigStage = XLineJig.EStage.eEndPt;
this.StartPoint = ptStart;
this.EndPoint = base.UiDoc.Selection.PickPoint(strPrompt);
this.EndPoint = this.GetResetPoint(this.StartPoint, this.EndPoint);
}
catch
{
if (this.m_prompDlg != null && base.CmdEndType == XUiJigBase.ECmdEndType.eEnter)
{
base.CmdEndType = XUiJigBase.ECmdEndType.eOther;
XYZ xyz = base.Client2Revit(this.m_ptCur);
Line line = Line.CreateUnbound(xyz, base.UiDoc.ActiveView.ViewDirection);
xyz = line.Project(this.StartPoint).XYZPoint;
xyz = this.GetResetPoint(this.StartPoint, xyz);
string inputValue = this.m_prompDlg.GetInputValue();
double num = Convert.ToDouble(inputValue) / 304.8;
XYZ xyz2 = (xyz - this.StartPoint).Normalize();
this.EndPoint = this.StartPoint + xyz2 * num;
}
else
{
this.EndPoint = null;
}
}
this.JigStage = XLineJig.EStage.eNoOper;
return this.EndPoint;
}
public XYZ GetResetPoint(XYZ ptBase, XYZ ptUser)
{
XYZ xyz = ptUser;
if (this.ResetPoint == XUiJigBase.EResetPoint.eByAngle)
{
xyz = JigFuncs.GetProjectPoint(base.UiDoc, ptUser, ptBase, this.LineAngle);
}
else if (this.ResetPoint == XUiJigBase.EResetPoint.eByOrtho)
{
xyz = JigFuncs.GetOrthoPoint(base.UiDoc, ptUser, ptBase);
}
else if (this.ResetPoint == XUiJigBase.EResetPoint.eByAxis)
{
XYZ axisPoint = JigFuncs.GetAxisPoint(base.UiDoc, ptUser, ptBase);
if (axisPoint != null)
{
xyz = axisPoint;
}
}
return xyz;
}
public override void Draw(PaintEventArgs paintEventArgs)
{
base.Draw(paintEventArgs);
if (!this.m_ptCur.IsEmpty && this.JigStage == XLineJig.EStage.eEndPt)
{
XYZ xyz = base.Client2Revit(this.m_ptCur);
if (this.ResetPoint == XUiJigBase.EResetPoint.eByAngle)
{
xyz = JigFuncs.GetProjectPoint(base.UiDoc, xyz, this.StartPoint, this.LineAngle);
this.m_ptCur = base.Revit2Client(xyz);
}
else if (this.ResetPoint == XUiJigBase.EResetPoint.eByOrtho)
{
xyz = JigFuncs.GetOrthoPoint(base.UiDoc, xyz, this.StartPoint);
this.m_ptCur = base.Revit2Client(xyz);
}
else if (this.ResetPoint == XUiJigBase.EResetPoint.eByAxis)
{
XYZ axisPoint = JigFuncs.GetAxisPoint(base.UiDoc, xyz, this.StartPoint);
if (axisPoint != null)
{
xyz = axisPoint;
this.m_ptCur = base.Revit2Client(xyz);
base.DrawAxisLine(paintEventArgs.Graphics, this.StartPoint, xyz);
}
}
XGraphics xgraphics = new XGraphics(paintEventArgs.Graphics, base.JigPen);
Color color = xgraphics.m_pen.Color;
xgraphics.m_pen.Color = this.DragLineColor;
if (this.MutilLineDist.Count < 1)
{
XLine2D xline2D = new XLine2D(base.Revit2Client(this.StartPoint), this.m_ptCur);
xline2D.Draw(xgraphics);
if (this.DrawSize)
{
double num = this.StartPoint.DistanceTo(xyz);
string text = string.Format("{0:F1}", num * 304.8);
XLineJig.DrawLineSize(base.Revit2Client(this.StartPoint), base.Revit2Client(xyz), text, xgraphics);
}
}
else
{
this.DrawMutilLine(this.StartPoint, xyz, xgraphics);
}
xgraphics.m_pen.Color = color;
}
}
public override List<Curve> CreateCurves()
{
List<Curve> list = new List<Curve>();
try
{
if (this.StartPoint != null && this.EndPoint != null)
{
if (this.MutilLineDist.Count < 1)
{
list.Add(Line.CreateBound(this.StartPoint, this.EndPoint));
}
else
{
XYZ xyz = this.StartPoint;
XYZ xyz2 = this.EndPoint;
XYZ xyz3 = (xyz2 - xyz).Normalize();
Transform transform = Transform.CreateRotation(base.UiDoc.ActiveView.ViewDirection, -1.5707963267948966);
XYZ xyz4 = transform.OfVector(xyz3);
double num = 0.0;
foreach (double num2 in this.MutilLineDist)
{
num += num2;
}
double num3 = 0.0;
if (this.PointAlignType == XLineJig.AlignType.eRight)
{
num3 = num;
}
else if (this.PointAlignType == XLineJig.AlignType.eMiddle)
{
num3 = num / 2.0;
}
xyz -= xyz4 * num3;
xyz2 -= xyz4 * num3;
if (this.DrawEndLine)
{
XYZ xyz5 = xyz + xyz4 * num;
XYZ xyz6 = xyz2 + xyz4 * num;
list.Add(Line.CreateBound(xyz, xyz5));
list.Add(Line.CreateBound(xyz2, xyz6));
}
list.Add(Line.CreateBound(xyz, xyz2));
foreach (double num4 in this.MutilLineDist)
{
xyz += xyz4 * num4;
xyz2 += xyz4 * num4;
list.Add(Line.CreateBound(xyz, xyz2));
}
}
}
}
catch
{
}
return list;
}
public double LineAngle { get; set; }
public XYZ StartPoint { get; set; }
public XYZ EndPoint { get; set; }
public XLineJig.EStage JigStage { get; set; }
public XUiJigBase.EResetPoint ResetPoint { get; set; }
public Color DragLineColor { get; set; }
public XLineJig.AlignType PointAlignType { get; set; }
public List<double> MutilLineDist { get; set; }
public void DrawMutilLine(XYZ ptBaseS, XYZ ptBaseE, XGraphics graphics)
{
Transform transform = Transform.CreateRotation(base.UiDoc.ActiveView.ViewDirection, -1.5707963267948966);
XYZ xyz = (ptBaseE - ptBaseS).Normalize();
XYZ xyz2 = transform.OfVector(xyz);
double num = 0.0;
foreach (double num2 in this.MutilLineDist)
{
num += num2;
}
double num3 = 0.0;
if (this.PointAlignType == XLineJig.AlignType.eRight)
{
num3 = num;
}
else if (this.PointAlignType == XLineJig.AlignType.eMiddle)
{
num3 = num / 2.0;
}
ptBaseS -= xyz2 * num3;
ptBaseE -= xyz2 * num3;
if (this.DrawEndLine)
{
XYZ xyz3 = ptBaseS + xyz2 * num;
XYZ xyz4 = ptBaseE + xyz2 * num;
XLine2D xline2D = new XLine2D(base.Revit2Client(ptBaseS), base.Revit2Client(xyz3));
XLine2D xline2D2 = new XLine2D(base.Revit2Client(ptBaseE), base.Revit2Client(xyz4));
xline2D.Draw(graphics);
xline2D2.Draw(graphics);
}
XLine2D xline2D3 = new XLine2D(base.Revit2Client(ptBaseS), base.Revit2Client(ptBaseE));
xline2D3.Draw(graphics);
foreach (double num4 in this.MutilLineDist)
{
ptBaseS += xyz2 * num4;
ptBaseE += xyz2 * num4;
xline2D3 = new XLine2D(base.Revit2Client(ptBaseS), base.Revit2Client(ptBaseE));
xline2D3.Draw(graphics);
}
}
public bool DrawEndLine { get; set; }
public bool DrawSize { get; set; }
public static int SizeOffset { get; set; }
public static int BorderLength { get; set; }
public static Font SizeFont { get; set; }
public static StringFormat TextFormat { get; set; }
public static SolidBrush SizeTextBrush { get; set; }
public static Color SizeLineColor { get; set; }
public static void DrawLineSize(Point ptStart, Point ptEnd, string strSizeText, XGraphics graphics)
{
XUiJigBase.SortTwoPoint(ref ptStart, ref ptEnd);
if (XUiJigBase.TwoPointDist(ptStart, ptEnd) >= 10)
{
double num = XUiJigBase.TwoPointAngle(ptStart, ptEnd);
double num2 = num + 1.5707963267948966;
Color color = graphics.m_pen.Color;
graphics.m_pen.Color = XLineJig.SizeLineColor;
Point point = XUiJigBase.OffsetPoint(ptStart, num2, XLineJig.int_0);
Point point2 = XUiJigBase.OffsetPoint(ptEnd, num2, XLineJig.int_0);
Point point3 = XUiJigBase.OffsetPoint(point, num2, XLineJig.int_1);
XLine2D xline2D = new XLine2D(point, point3);
xline2D.Draw(graphics);
Point point4 = XUiJigBase.OffsetPoint(point2, num2, XLineJig.int_1);
XLine2D xline2D2 = new XLine2D(point2, point4);
xline2D2.Draw(graphics);
Point point5 = XUiJigBase.OffsetPoint(point, num2, XLineJig.int_1 - XLineJig.int_0);
Point point6 = XUiJigBase.OffsetPoint(point2, num2, XLineJig.int_1 - XLineJig.int_0);
XLine2D xline2D3 = new XLine2D(XUiJigBase.OffsetPoint(point5, num, -XLineJig.int_0), XUiJigBase.OffsetPoint(point6, num, XLineJig.int_0));
xline2D3.Draw(graphics);
XLine2D xline2D4 = new XLine2D(XUiJigBase.OffsetPoint(point5, num + 45.0, XLineJig.int_0), XUiJigBase.OffsetPoint(point5, num + 45.0, -XLineJig.int_0));
xline2D4.Draw(graphics);
XLine2D xline2D5 = new XLine2D(XUiJigBase.OffsetPoint(point6, num + 45.0, XLineJig.int_0), XUiJigBase.OffsetPoint(point6, num + 45.0, -XLineJig.int_0));
xline2D5.Draw(graphics);
Point point7 = XUiJigBase.OffsetPoint(point, num, XUiJigBase.TwoPointDist(ptStart, ptEnd) / 2);
Point point8 = XUiJigBase.OffsetPoint(point7, num2, (int)((double)XLineJig.int_1 + (double)XLineJig.SizeFont.Height / 2.0));
PointF pointF = new PointF((float)point8.X, (float)point8.Y);
float num3 = -(float)(num / Math.PI * 180.0);
graphics.m_graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
Matrix transform = graphics.m_graphics.Transform;
Matrix transform2 = graphics.m_graphics.Transform;
transform2.RotateAt(num3, pointF);
graphics.m_graphics.Transform = transform2;
graphics.m_graphics.DrawString(strSizeText, XLineJig.SizeFont, XLineJig.SizeTextBrush, pointF, XLineJig.TextFormat);
graphics.m_graphics.Transform = transform;
graphics.m_pen.Color = color;
}
}
public static void DrawLinesSize(Point ptStart, Point ptEnd, string strSizeText, XGraphics graphics, XYZ pt, XYZ ptCur)
{
XUiJigBase.SortTwoPoint(ref ptStart, ref ptEnd);
if (XUiJigBase.TwoPointDist(ptStart, ptEnd) >= 10)
{
double num = XUiJigBase.TwoPointAngle(ptStart, ptEnd);
double num2 = num + 1.5707963267948966;
Color color = graphics.m_pen.Color;
graphics.m_pen.Color = XLineJig.SizeLineColor;
Point point = XUiJigBase.OffsetPoint(ptStart, num2, XLineJig.int_0);
Point point2 = XUiJigBase.OffsetPoint(ptEnd, num2, XLineJig.int_0);
Point point3 = XUiJigBase.OffsetPoint(point, num2, XLineJig.int_1);
XLine2D xline2D = new XLine2D(point, point3);
xline2D.Draw(graphics);
Point point4 = XUiJigBase.OffsetPoint(point2, num2, XLineJig.int_1);
XLine2D xline2D2 = new XLine2D(point2, point4);
xline2D2.Draw(graphics);
Point point5 = XUiJigBase.OffsetPoint(point, num2, XLineJig.int_1 - XLineJig.int_0);
Point point6 = XUiJigBase.OffsetPoint(point2, num2, XLineJig.int_1 - XLineJig.int_0);
XLine2D xline2D3 = new XLine2D(XUiJigBase.OffsetPoint(point5, num, -XLineJig.int_0), XUiJigBase.OffsetPoint(point6, num, XLineJig.int_0));
xline2D3.Draw(graphics);
XLine2D xline2D4 = new XLine2D(XUiJigBase.OffsetPoint(point5, num + 45.0, XLineJig.int_0), XUiJigBase.OffsetPoint(point5, num + 45.0, -XLineJig.int_0));
xline2D4.Draw(graphics);
XLine2D xline2D5 = new XLine2D(XUiJigBase.OffsetPoint(point6, num + 45.0, XLineJig.int_0), XUiJigBase.OffsetPoint(point6, num + 45.0, -XLineJig.int_0));
xline2D5.Draw(graphics);
Point point7 = XUiJigBase.OffsetPoint(point, num, XUiJigBase.TwoPointDist(ptStart, ptEnd) / 2);
Point point8 = XUiJigBase.OffsetPoint(point7, num2, (int)((double)XLineJig.int_1 + (double)XLineJig.SizeFont.Height / 2.0));
PointF pointF = new PointF((float)point8.X, (float)point8.Y);
float num3 = -(float)(num / Math.PI * 180.0);
graphics.m_graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
Matrix transform = graphics.m_graphics.Transform;
Matrix transform2 = graphics.m_graphics.Transform;
transform2.RotateAt(num3, pointF);
graphics.m_graphics.Transform = transform2;
graphics.m_graphics.DrawString(strSizeText, XLineJig.SizeFont, XLineJig.SizeTextBrush, pointF, XLineJig.TextFormat);
graphics.m_graphics.Transform = transform;
graphics.m_pen.Color = color;
}
}
[CompilerGenerated]
private static int int_0;
[CompilerGenerated]
private static int int_1;
public enum EStage
{
eNoOper,
eStartPt,
eEndPt
}
public enum AlignType
{
eMiddle,
eLeft,
eRight
}
}
}