415 lines
18 KiB
C#
415 lines
18 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
|
|
using HYJig;
|
|
|
|
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;
|
|
using Form = System.Windows.Forms.Form;
|
|
using Point = System.Drawing.Point;
|
|
|
|
namespace HongYe.HVAC
|
|
{
|
|
public class PELineJig : XUiJigBase, IDisposable
|
|
{
|
|
public PELineJig(UIDocument uiDoc)
|
|
: base(uiDoc)
|
|
{
|
|
this.JigStage = PELineJig.EStage.eNoOper;
|
|
this.ResetPoint = XUiJigBase.EResetPoint.eNoOper;
|
|
this.DragLineColor = Color.FromArgb(175, 222, 239);
|
|
this.PointAlignType = PELineJig.AlignType.eMiddle;
|
|
this.MutilLineDist = new List<double>();
|
|
this.DrawEndLine = false;
|
|
this.DrawSize = false;
|
|
int height = Screen.PrimaryScreen.Bounds.Height;
|
|
PELineJig.SizeOffset = (int)(0.006 * (double)height);
|
|
PELineJig.BorderLength = (int)(0.04 * (double)height);
|
|
PELineJig.SizeFont = new Font("Arial", 2.5f * (float)PELineJig.SizeOffset, GraphicsUnit.Pixel);
|
|
PELineJig.TextFormat = new StringFormat(StringFormatFlags.NoClip);
|
|
PELineJig.TextFormat.Alignment = StringAlignment.Center;
|
|
PELineJig.TextFormat.LineAlignment = StringAlignment.Center;
|
|
PELineJig.SizeLineColor = Color.FromArgb(126, 163, 255);
|
|
PELineJig.SizeTextBrush = new SolidBrush(base.JigPen.Color);
|
|
this.OnMouseLeaveFormClientEvent += (this.OnMouseLeaveFormClientEvent);
|
|
this.OnMouseMoveIntoFormClientEvent += (this.OnMouseMoveIntoFormClientEvent);
|
|
}
|
|
|
|
public PELineJig(UIDocument uiDoc, Form userForm)
|
|
: base(uiDoc)
|
|
{
|
|
this.JigStage = PELineJig.EStage.eNoOper;
|
|
this.ResetPoint = XUiJigBase.EResetPoint.eNoOper;
|
|
this.DragLineColor = Color.FromArgb(175, 222, 239);
|
|
this.PointAlignType = PELineJig.AlignType.eMiddle;
|
|
this.MutilLineDist = new List<double>();
|
|
this.DrawEndLine = false;
|
|
this.DrawSize = false;
|
|
int height = Screen.PrimaryScreen.Bounds.Height;
|
|
PELineJig.SizeOffset = (int)(0.006 * (double)height);
|
|
PELineJig.BorderLength = (int)(0.04 * (double)height);
|
|
PELineJig.SizeFont = new Font("Arial", 2.5f * (float)PELineJig.SizeOffset, GraphicsUnit.Pixel);
|
|
PELineJig.TextFormat = new StringFormat(StringFormatFlags.NoClip);
|
|
PELineJig.TextFormat.Alignment = StringAlignment.Center;
|
|
PELineJig.TextFormat.LineAlignment = StringAlignment.Center;
|
|
PELineJig.SizeLineColor = Color.FromArgb(126, 163, 255);
|
|
PELineJig.SizeTextBrush = new SolidBrush(base.JigPen.Color);
|
|
this.OnMouseLeaveFormClientEvent +=(this.OnMouseLeaveFormClientEvent);
|
|
this.OnMouseMoveIntoFormClientEvent += (this.OnMouseMoveIntoFormClientEvent);
|
|
this.m_UserForm = userForm;
|
|
}
|
|
|
|
public new void Dispose()
|
|
{
|
|
base.Dispose();
|
|
PELineJig.SizeFont.Dispose();
|
|
PELineJig.TextFormat.Dispose();
|
|
PELineJig.SizeTextBrush.Dispose();
|
|
this.OnMouseLeaveFormClientEvent -=(this.OnMouseLeaveFormClientEvent);
|
|
this.OnMouseMoveIntoFormClientEvent -= (this.OnMouseMoveIntoFormClientEvent);
|
|
}
|
|
|
|
public XYZ PickStartPoint(string strPrompt = "请确定直线起点:")
|
|
{
|
|
try
|
|
{
|
|
this.JigStage = PELineJig.EStage.eStartPt;
|
|
this.StartPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|
}
|
|
catch
|
|
{
|
|
this.StartPoint = null;
|
|
}
|
|
this.JigStage = PELineJig.EStage.eNoOper;
|
|
return this.StartPoint;
|
|
}
|
|
|
|
public XYZ PickEndPoint(XYZ ptStart, string strPrompt = "请确定直线终点:")
|
|
{
|
|
try
|
|
{
|
|
this.JigStage = PELineJig.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);
|
|
xyz = Line.CreateUnbound(xyz, base.UiDoc.ActiveView.ViewDirection).Project(this.StartPoint).XYZPoint;
|
|
xyz = this.GetResetPoint(this.StartPoint, xyz);
|
|
double num = Convert.ToDouble(this.m_prompDlg.GetInputValue()) / 304.8;
|
|
XYZ xyz2 = (xyz - this.StartPoint).Normalize();
|
|
this.EndPoint = this.StartPoint + xyz2 * num;
|
|
}
|
|
else
|
|
{
|
|
this.EndPoint = null;
|
|
}
|
|
}
|
|
this.JigStage = PELineJig.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)
|
|
{
|
|
if (this.JigStage == PELineJig.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)
|
|
{
|
|
new XLine2D(base.Revit2Client(this.StartPoint), this.m_ptCur).Draw(xgraphics);
|
|
if (this.DrawSize)
|
|
{
|
|
double num = this.StartPoint.DistanceTo(xyz);
|
|
string text = string.Format("{0:F1}", num * 304.8);
|
|
PELineJig.DrawLineSize(base.Revit2Client(this.StartPoint), base.Revit2Client(xyz), text, xgraphics);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.DrawMutilLine(this.StartPoint, xyz, xgraphics);
|
|
}
|
|
xgraphics.m_pen.Color = color;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
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();
|
|
XYZ xyz4 = Transform.CreateRotation(base.UiDoc.ActiveView.ViewDirection, -1.5707963267948966).OfVector(xyz3);
|
|
double num = 0.0;
|
|
foreach (double num2 in this.MutilLineDist)
|
|
{
|
|
num += num2;
|
|
}
|
|
double num3 = 0.0;
|
|
if (this.PointAlignType == PELineJig.AlignType.eRight)
|
|
{
|
|
num3 = num;
|
|
}
|
|
else if (this.PointAlignType == PELineJig.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 PELineJig.EStage JigStage { get; set; }
|
|
|
|
public XUiJigBase.EResetPoint ResetPoint { get; set; }
|
|
|
|
public Color DragLineColor { get; set; }
|
|
|
|
public PELineJig.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 == PELineJig.AlignType.eRight)
|
|
{
|
|
num3 = num;
|
|
}
|
|
else if (this.PointAlignType == PELineJig.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));
|
|
XDrawable2D xdrawable2D = new XLine2D(base.Revit2Client(ptBaseE), base.Revit2Client(xyz4));
|
|
xline2D.Draw(graphics);
|
|
xdrawable2D.Draw(graphics);
|
|
}
|
|
new XLine2D(base.Revit2Client(ptBaseS), base.Revit2Client(ptBaseE)).Draw(graphics);
|
|
foreach (double num4 in this.MutilLineDist)
|
|
{
|
|
ptBaseS += xyz2 * num4;
|
|
ptBaseE += xyz2 * num4;
|
|
new XLine2D(base.Revit2Client(ptBaseS), base.Revit2Client(ptBaseE)).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)
|
|
{
|
|
return;
|
|
}
|
|
double num = XUiJigBase.TwoPointAngle(ptStart, ptEnd);
|
|
double num2 = num + 1.5707963267948966;
|
|
Color color = graphics.m_pen.Color;
|
|
graphics.m_pen.Color = PELineJig.SizeLineColor;
|
|
Point point = XUiJigBase.OffsetPoint(ptStart, num2, PELineJig.int_0);
|
|
Point point2 = XUiJigBase.OffsetPoint(ptEnd, num2, PELineJig.int_0);
|
|
Point point3 = XUiJigBase.OffsetPoint(point, num2, PELineJig.int_1 - PELineJig.int_0);
|
|
Point point4 = XUiJigBase.OffsetPoint(point2, num2, PELineJig.int_1 - PELineJig.int_0);
|
|
new XLine2D(XUiJigBase.OffsetPoint(point3, num, -PELineJig.int_0), XUiJigBase.OffsetPoint(point4, num, PELineJig.int_0)).Draw(graphics);
|
|
new XLine2D(XUiJigBase.OffsetPoint(point3, num + 45.0, PELineJig.int_0), XUiJigBase.OffsetPoint(point3, num + 45.0, -PELineJig.int_0)).Draw(graphics);
|
|
new XLine2D(XUiJigBase.OffsetPoint(point4, num + 45.0, PELineJig.int_0), XUiJigBase.OffsetPoint(point4, num + 45.0, -PELineJig.int_0)).Draw(graphics);
|
|
Point point5 = XUiJigBase.OffsetPoint(XUiJigBase.OffsetPoint(point, num, XUiJigBase.TwoPointDist(ptStart, ptEnd) / 2), num2, (int)((double)PELineJig.int_1 + (double)PELineJig.SizeFont.Height / 2.0));
|
|
PointF pointF = new PointF((float)point5.X, (float)point5.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, PELineJig.SizeFont, PELineJig.SizeTextBrush, pointF, PELineJig.TextFormat);
|
|
graphics.m_graphics.Transform = transform;
|
|
graphics.m_pen.Color = color;
|
|
}
|
|
|
|
public static void DrawLinesSize(Point ptStart, Point ptEnd, string strSizeText, XGraphics graphics)
|
|
{
|
|
XUiJigBase.SortTwoPoint(ref ptStart, ref ptEnd);
|
|
if (XUiJigBase.TwoPointDist(ptStart, ptEnd) < 10)
|
|
{
|
|
return;
|
|
}
|
|
double num = XUiJigBase.TwoPointAngle(ptStart, ptEnd);
|
|
double num2 = num + 1.5707963267948966;
|
|
Color color = graphics.m_pen.Color;
|
|
graphics.m_pen.Color = PELineJig.SizeLineColor;
|
|
Point point = XUiJigBase.OffsetPoint(ptStart, num2, PELineJig.int_0);
|
|
Point point2 = XUiJigBase.OffsetPoint(ptEnd, num2, PELineJig.int_0);
|
|
Point point3 = XUiJigBase.OffsetPoint(point, num2, PELineJig.int_1);
|
|
new XLine2D(point, point3).Draw(graphics);
|
|
Point point4 = XUiJigBase.OffsetPoint(point2, num2, PELineJig.int_1);
|
|
new XLine2D(point2, point4).Draw(graphics);
|
|
Point point5 = XUiJigBase.OffsetPoint(point, num2, PELineJig.int_1 - PELineJig.int_0);
|
|
Point point6 = XUiJigBase.OffsetPoint(point2, num2, PELineJig.int_1 - PELineJig.int_0);
|
|
new XLine2D(XUiJigBase.OffsetPoint(point5, num, -PELineJig.int_0), XUiJigBase.OffsetPoint(point6, num, PELineJig.int_0)).Draw(graphics);
|
|
new XLine2D(XUiJigBase.OffsetPoint(point5, num + 45.0, PELineJig.int_0), XUiJigBase.OffsetPoint(point5, num + 45.0, -PELineJig.int_0)).Draw(graphics);
|
|
new XLine2D(XUiJigBase.OffsetPoint(point6, num + 45.0, PELineJig.int_0), XUiJigBase.OffsetPoint(point6, num + 45.0, -PELineJig.int_0)).Draw(graphics);
|
|
Point point7 = XUiJigBase.OffsetPoint(XUiJigBase.OffsetPoint(point, num, XUiJigBase.TwoPointDist(ptStart, ptEnd) / 2), num2, (int)((double)PELineJig.int_1 + (double)PELineJig.SizeFont.Height / 2.0));
|
|
PointF pointF = new PointF((float)point7.X, (float)point7.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, PELineJig.SizeFont, PELineJig.SizeTextBrush, pointF, PELineJig.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
|
|
}
|
|
}
|
|
}
|