173 lines
6.2 KiB
C#
173 lines
6.2 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.Runtime.CompilerServices;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace HYJig
|
|||
|
|
{
|
|||
|
|
public class XTextsJig : XUiJigBase
|
|||
|
|
{
|
|||
|
|
public XTextsJig(UIDocument uiDoc)
|
|||
|
|
: base(uiDoc)
|
|||
|
|
{
|
|||
|
|
this.JigStage = XTextsJig.EStage.eNoOper;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public XYZ DragTexts(List<TextNote> lstText, List<XYZ> lstTextCenterPt, XYZ ptBase, string strPrompt = "请确定位置:")
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.TextNotes = lstText;
|
|||
|
|
this.TextNoteCenter = lstTextCenterPt;
|
|||
|
|
this.BasePoint = ptBase;
|
|||
|
|
this.JigStage = XTextsJig.EStage.ePickPoint;
|
|||
|
|
this.PickPoint = base.UiDoc.Selection.PickPoint(strPrompt);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
this.PickPoint = null;
|
|||
|
|
}
|
|||
|
|
this.JigStage = XTextsJig.EStage.eNoOper;
|
|||
|
|
return this.PickPoint;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void Draw(PaintEventArgs paintEventArgs)
|
|||
|
|
{
|
|||
|
|
base.Draw(paintEventArgs);
|
|||
|
|
if (!this.m_ptCur.IsEmpty && this.JigStage == XTextsJig.EStage.ePickPoint && this.TextNotes.Count == this.TextNoteCenter.Count)
|
|||
|
|
{
|
|||
|
|
XYZ xyz = base.Client2Revit(this.m_ptCur);
|
|||
|
|
XYZ xyz2 = xyz - this.BasePoint;
|
|||
|
|
Transform transform = Transform.CreateTranslation(xyz2);
|
|||
|
|
Graphics graphics = paintEventArgs.Graphics;
|
|||
|
|
Brush black = Brushes.Black;
|
|||
|
|
StringFormat stringFormat = new StringFormat();
|
|||
|
|
stringFormat.Alignment = StringAlignment.Center;
|
|||
|
|
stringFormat.LineAlignment = StringAlignment.Center;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Point point = base.Revit2Client(this.BasePoint);
|
|||
|
|
XGraphics xgraphics = new XGraphics(graphics, base.JigPen);
|
|||
|
|
XLine2D xline2D = new XLine2D(point, this.m_ptCur);
|
|||
|
|
xline2D.Draw(xgraphics);
|
|||
|
|
for (int i = 0; i < this.TextNotes.Count; i++)
|
|||
|
|
{
|
|||
|
|
TextNote textNote = this.TextNotes[i];
|
|||
|
|
XYZ xyz3 = this.TextNoteCenter[i];
|
|||
|
|
xyz3 = transform.OfPoint(xyz3);
|
|||
|
|
Point point2 = base.Revit2Client(xyz3);
|
|||
|
|
PointF pointF = new PointF((float)point2.X, (float)point2.Y);
|
|||
|
|
float num = this.method_14(textNote, xyz3);
|
|||
|
|
string text = this.method_13(textNote);
|
|||
|
|
Font font = new Font(text, num, GraphicsUnit.Pixel);
|
|||
|
|
Matrix transform2 = graphics.Transform;
|
|||
|
|
Matrix transform3 = graphics.Transform;
|
|||
|
|
float num2 = this.method_15(textNote);
|
|||
|
|
transform3.RotateAt(num2, pointF);
|
|||
|
|
float num3 = (float)textNote.TextNoteType.get_Parameter((BuiltInParameter)(-1006327)).AsDouble();
|
|||
|
|
transform3.Scale(num3, 1f);
|
|||
|
|
graphics.Transform = transform3;
|
|||
|
|
pointF.X /= num3;
|
|||
|
|
graphics.DrawString(textNote.Text, font, black, pointF, stringFormat);
|
|||
|
|
graphics.Transform = transform2;
|
|||
|
|
font.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string method_13(TextNote textNote_0)
|
|||
|
|
{
|
|||
|
|
string name = textNote_0.TextNoteType.Name;
|
|||
|
|
string text;
|
|||
|
|
if (name.IndexOf("仿宋") >= 0)
|
|||
|
|
{
|
|||
|
|
text = "仿宋";
|
|||
|
|
}
|
|||
|
|
else if (name.IndexOf("宋体") >= 0)
|
|||
|
|
{
|
|||
|
|
text = "宋体";
|
|||
|
|
}
|
|||
|
|
else if (name.IndexOf("黑体") >= 0)
|
|||
|
|
{
|
|||
|
|
text = "黑体";
|
|||
|
|
}
|
|||
|
|
else if (name.IndexOf("Arial") >= 0)
|
|||
|
|
{
|
|||
|
|
text = "Arial";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
text = "宋体";
|
|||
|
|
}
|
|||
|
|
return text;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private float method_14(TextNote textNote_0, XYZ xyz_2)
|
|||
|
|
{
|
|||
|
|
double num = textNote_0.TextNoteType.get_Parameter((BuiltInParameter)(-1006301)).AsDouble();
|
|||
|
|
double height = textNote_0.Height;
|
|||
|
|
double num2 = 0.5 * (num + height) * (double)base.UiDoc.Document.ActiveView.Scale;
|
|||
|
|
XYZ xyz = xyz_2 + base.UiDoc.Document.ActiveView.UpDirection * 0.5 * num2;
|
|||
|
|
Point point = base.Revit2Client(xyz_2);
|
|||
|
|
Point point2 = base.Revit2Client(xyz);
|
|||
|
|
double num3 = Math.Abs(point.X - point2.X);
|
|||
|
|
double num4 = Math.Abs(point.Y - point2.Y);
|
|||
|
|
double num5 = Math.Sqrt(num3 * num3 + num4 * num4);
|
|||
|
|
return (float)(2.0 * num5);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private float method_15(TextNote textNote_0)
|
|||
|
|
{
|
|||
|
|
Autodesk.Revit.DB.View activeView = base.UiDoc.Document.ActiveView;
|
|||
|
|
double num = activeView.RightDirection.AngleOnPlaneTo(textNote_0.BaseDirection, activeView.ViewDirection);
|
|||
|
|
if (num > 1.5707963267948966)
|
|||
|
|
{
|
|||
|
|
if (num <= 4.71238898038469)
|
|||
|
|
{
|
|||
|
|
num -= Math.PI;
|
|||
|
|
}
|
|||
|
|
else if (num <= 6.2831853071795862)
|
|||
|
|
{
|
|||
|
|
num -= 6.2831853071795862;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
float num2 = (float)(num / Math.PI * 180.0);
|
|||
|
|
return -num2;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private XYZ method_16(TextNote textNote_0)
|
|||
|
|
{
|
|||
|
|
BoundingBoxXYZ boundingBoxXYZ = textNote_0.get_BoundingBox(base.UiDoc.ActiveView);
|
|||
|
|
XYZ min = boundingBoxXYZ.Min;
|
|||
|
|
XYZ max = boundingBoxXYZ.Max;
|
|||
|
|
return min + (max - min) / 2.0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<TextNote> TextNotes { get; set; }
|
|||
|
|
|
|||
|
|
public List<XYZ> TextNoteCenter { get; set; }
|
|||
|
|
|
|||
|
|
public XYZ BasePoint { get; set; }
|
|||
|
|
|
|||
|
|
public XYZ PickPoint { get; set; }
|
|||
|
|
|
|||
|
|
public XTextsJig.EStage JigStage { get; set; }
|
|||
|
|
|
|||
|
|
public enum EStage
|
|||
|
|
{
|
|||
|
|
eNoOper,
|
|||
|
|
ePickPoint
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|