//============================================================
#region 其他绘图方法
/// <summary>
/// 创建筒体剖视图
/// </summary>
/// <param name="pt">内侧左上基准点</param>
/// <param name="str">标注尺寸内容</param>
/// <param name="tks">筒体厚度</param>
/// <param name="isdn">true:标注内径;false:标注外径</param>
public static void MakeShellSectionView(Point3d pt, string str, int tks, bool isdn = true)
{
Point2d p1 = new Point2d(pt.X, pt.Y);
Point2d p8 = new Point2d(pt.X + 300, pt.Y - 150);
Point2d p2 = new Point2d(pt.X + 300, pt.Y);
Point2d p3 = new Point2d(pt.X, pt.Y - tks);
Point2d p4 = new Point2d(pt.X + 300, pt.Y - tks);
Point2d p5 = new Point2d(pt.X, p8.Y + tks);
Point2d p6 = new Point2d(pt.X + 300, p8.Y + tks);
Point2d p7 = new Point2d(pt.X, pt.Y - 150);
db.AddRectToModelSpace(p1, p8);
db.AddLineToModelSpace(p3, p4);
db.AddLineToModelSpace(p5, p6);
db.AddLineToModelSpace(new Point2d(p1.X - 10, p1.Y - 75), new Point2d(p8.X + 10, p8.Y + 75), 1, "ACAD_ISO04W100", 3);
MakeHatch(3, 0, p1, p2, p3, p4, p5, p6, p7, p8);
RotatedDim(new Point3d(p7.X + 200, p7.Y, 0), new Point3d(p5.X + 200, p5.Y, 0), new Point3d(p5.X + 200, p5.Y, 0), "<>", false, 5, 1, 0);
if (isdn) RotatedDim(new Point3d(p3.X, p3.Y, 0), new Point3d(p5.X, p5.Y, 0), new Point3d(p1.X - 15, (p3.Y + p5.Y) / 2.0, 0), str, false, 5, 1, 0);
else RotatedDim(new Point3d(p1.X, p1.Y, 0), new Point3d(p8.X, p8.Y, 0), new Point3d(p1.X - 15, (p1.Y + p8.Y) / 2.0, 0), str, false, 5, 1, 0);
}
/// <summary>
/// 创建管道状填充
/// </summary>
/// <param name="sca">填充比例</param>
/// <param name="ang">填充图形角度</param>
/// <param name="p1">图形1左上点</param>
/// <param name="p2">图形1左下点</param>
/// <param name="p3">图形1右上点</param>
/// <param name="p4">图形1右下点</param>
/// <param name="p5">图形2左上点</param>
/// <param name="p6">图形2左下点</param>
/// <param name="p7">图形2右上点</param>
/// <param name="p8">图形2右下点</param>
public static void MakeHatch(double sca, double ang, Point2d p1, Point2d p2, Point2d p3, Point2d p4, Point2d p5, Point2d p6, Point2d p7, Point2d p8)
{
List<HatchLoopTypes> loops = new List<HatchLoopTypes>() { HatchLoopTypes.Outermost, HatchLoopTypes.Outermost };
Polyline pl1 = new Polyline();
pl1.AddVertexAt(0, p1, 0, 0, 0);
pl1.AddVertexAt(1, p2, 0, 0, 0);
pl1.AddVertexAt(2, p4, 0, 0, 0);
pl1.AddVertexAt(3, p3, 0, 0, 0);
pl1.Closed = true;
Polyline pl2 = new Polyline();
pl2.AddVertexAt(0, p5, 0, 0, 0);
pl2.AddVertexAt(1, p6, 0, 0, 0);
pl2.AddVertexAt(2, p8, 0, 0, 0);
pl2.AddVertexAt(3, p7, 0, 0, 0);
pl2.Closed = true;
ObjectId[] delents = db.AddEntityToModelSpace(pl1, pl2);
db.HatchEntity(loops, "ANSI31", sca, ang, delents[0], delents[1]);
foreach (ObjectId id in delents) id.EraseEntity();
}
/// <summary>
/// 创建筒体焊缝排版图
/// </summary>
/// <param name="pt">内侧左上基准点</param>
/// <param name="si">筒体信息对象</param>
/// <param name="scal">标注全局比例</param>
public static void MakeWeldView(Point3d pt, ShellsInfo si, double scal, bool IsIn)
{
string atpy;
int n = 1;
Point3d pts0 = pt, pte0 = new Point3d(pts0.X + si.BarrelDn, pts0.Y, 0);
Point3d pts1 = pts0, pte1 = pte0;
Point3d pts2 = pts0, pte2 = pte0;
db.AddLineToModelSpace(pts0, pte0);
foreach (int hig in si.BarrelNode)
{
if (IsIn)
{
if (n <= 9) atpy = $"A10{n}";
else if (n <= 99) atpy = $"A1{n}";
else atpy = $"A{n}";
}
else
{
if (n <= 9) atpy = $"A20{n}";
else if (n <= 99) atpy = $"A2{n}";
else atpy = $"A{n}";
}
atpy = $"{atpy}-1 ~{atpy}-{si.Weldcout}";
pts2 = new Point3d(pts2.X, pts2.Y - hig, 0);
pte2 = new Point3d(pte2.X, pte2.Y - hig, 0);
db.AddLineToModelSpace(pts2, pte2);
Point3d inpt = new Point3d(pts1.X + (si.BarrelDn * 0.25 * ((2 * ((n - 1) % 2)) + 1)), pts2.Y + (hig / 2.0), 0);
db.AddLineToModelSpace(new Point3d(inpt.X, pts1.Y, 0), new Point3d(inpt.X, pts2.Y, 0));
db.AddTextToModelSpace(inpt, atpy, fonthig, TextHorizontalMode.TextCenter);
db.AddTextToModelSpace(inpt, atpy, fonthig, TextHorizontalMode.TextCenter);
if (n < si.BarrelNode.Count)
{
if (IsIn)
{
if (n <= 9) atpy = $"B10{n}";
else if (n <= 99) atpy = $"B1{n}";
else atpy = $"B{n}";
}
else
{
if (n <= 9) atpy = $"B20{n}";
else if (n <= 99) atpy = $"B2{n}";
else atpy = $"B{n}";
}
db.AddTextToModelSpace(new Point3d(pts2.X - fonthig, pts2.Y, 0), atpy, fonthig, TextHorizontalMode.TextRight, TextVerticalMode.TextVerticalMid);
}
n++;
RotatedDim(pte1, pte2, new Point3d(pte1.X + (2 * fonthig), (pte1.Y + pte2.Y) / 2.0, 0), "<>", false, scal, 1, 0);
pts1 = pts2;
pte1 = pte2;
}
db.AddLineToModelSpace(pts0, pts2);
db.AddLineToModelSpace(pte0, pte2);
db.AddLineToModelSpace(new Point3d(pts0.X + (si.BarrelDn / 2.0), pts0.Y + fonthig / 2.0, 0), new Point3d(pts2.X + (si.BarrelDn / 2.0), pts2.Y - fonthig / 2.0, 0), 1, "ACAD_ISO04W100", 100);
RotatedDim(pte0, pte1, new Point3d(pte0.X + (4 * fonthig), (pte0.Y + pte1.Y) / 2.0, 0), "<>", false, scal, 1, 0);
RotatedDim(pts1, pte1, new Point3d((pts1.X + pte1.X) / 2.0, pts1.Y - (2 * fonthig), 0), "%%C<>(内径)", true, scal, 1, 0);
ptssv = pts1;
}
/// <summary>
/// 创建筒体示意图
/// </summary>
/// <param name="pt">内侧左上基准点</param>
/// <param name="si">筒体信息对象</param>
/// <param name="scal">标注全局比例</param>
public static void MakeShellView(Point3d pt, ShellsInfo si, double scal)
{
Point2d p1 = new Point2d(pt.X, pt.Y), pdimt = new Point2d();
db.AddLineToModelSpace(pt, new Point3d(pt.X, pt.Y - si.BarrelLen, 0));
db.AddLineToModelSpace(new Point2d(pt.X + si.BarrelDn, pt.Y), new Point2d(pt.X + si.BarrelDn, pt.Y - si.BarrelLen));
if (si.Barrel.Count > 1)
{
for (int i = 0; i < si.Barrel.Count; i++)
{
List<int> lst = si.Barrel[i];
int tks = lst[1] * si.BarrelDn / 1000 * 2;
p1 = new Point2d(p1.X - tks, p1.Y);
Point2d p2 = new Point2d(p1.X, p1.Y - lst[0]);
Point2d p3 = new Point2d(p1.X + tks, p1.Y);
Point2d p4 = new Point2d(p3.X, p2.Y);
Point2d p5 = new Point2d(p3.X + si.BarrelDn, p1.Y);
Point2d p6 = new Point2d(p5.X, p5.Y - lst[0]);
Point2d p7 = new Point2d(p5.X + tks, p5.Y);
Point2d p8 = new Point2d(p7.X, p6.Y);
if (i == 0)
{
pdimt = p7;
db.AddLineToModelSpace(p1, p7);
}
db.AddLineToModelSpace(p1, p2);
db.AddLineToModelSpace(p7, p8);
if (i % 2 == 0) MakeHatch(100, 0, p1, p2, p3, p4, p5, p6, p7, p8);
else MakeHatch(100, 90, p1, p2, p3, p4, p5, p6, p7, p8);
if ((i + 1) < si.Barrel.Count && lst[1] < si.Barrel[i + 1][1])
{
tks = si.Barrel[i + 1][1] * si.BarrelDn / 1000 * 2;
p2 = new Point2d(p3.X - tks, p2.Y);
p8 = new Point2d(p5.X + tks, p6.Y);
}
db.AddLineToModelSpace(p2, p8);
if (i == 0)
{
RotatedDim(p1, p3, new Point2d(p3.X, p3.Y + 0.5 * fonthig), "<>", true, scal, 1.0 / (si.BarrelDn / 1000 * 2), 0);
}
else
{
if (i + 1 == si.Barrel.Count)
{
Point2d pdimb = p8;
db.AddLineToModelSpace(new Point2d(p3.X + (si.BarrelDn / 2.0), pdimt.Y + 750), new Point2d(p3.X + (si.BarrelDn / 2.0), pdimb.Y - 750), 1, "ACAD_ISO04W100", 100);
RotatedDim(p2, p4, new Point2d(p4.X, p4.Y - 1.5 * fonthig), "<>", true, scal, 1.0 / (si.BarrelDn / 1000 * 2), 0);
RotatedDim(p4, p6, new Point2d((p4.X + p6.X) / 2.0, p4.Y - 2.5 * fonthig), "%%c<>(内径)", true, scal, 1, 0);
Point2d ptrdim = new Point2d(((pdimt.X + pdimb.X) / 2.0) + 3.5 * fonthig, (pdimt.Y + pdimb.Y) / 2.0);
RotatedDim(pdimt, pdimb, ptrdim, "<>", false, scal, 1.0, 0);
}
else
{
RotatedDim(new Point2d(p1.X, p1.Y - (si.Barrel[i][0] / 2.0)), new Point2d(p3.X, p3.Y - (si.Barrel[i][0] / 2.0)), new Point2d(p3.X, p3.Y - (si.Barrel[i][0] / 2.0)), "<>", true, scal, 1.0 / (si.BarrelDn / 1000 * 2), 0);
}
}
RotatedDim(p7, p8, new Point2d(pdimt.X + 1.8 * fonthig, (p7.Y + p8.Y) / 2.0), "<>", false, scal, 1.0, 0);
p1 = p4;
}
}
else
{
List<int> lst = si.Barrel[0];
int tks = lst[1] * si.BarrelDn / 1000 * 2;
p1 = new Point2d(p1.X - tks, p1.Y);
Point2d p2 = new Point2d(p1.X, p1.Y - lst[0]);
Point2d p3 = new Point2d(p1.X + tks, p1.Y);
Point2d p4 = new Point2d(p3.X, p2.Y);
Point2d p5 = new Point2d(p3.X + si.BarrelDn, p1.Y);
Point2d p6 = new Point2d(p5.X, p5.Y - lst[0]);
Point2d p7 = new Point2d(p5.X + tks, p5.Y);
Point2d p8 = new Point2d(p7.X, p6.Y);
db.AddLineToModelSpace(p1, p7);
db.AddLineToModelSpace(p2, p8);
db.AddLineToModelSpace(p1, p2);
db.AddLineToModelSpace(p7, p8);
MakeHatch(100, 0, p1, p2, p3, p4, p5, p6, p7, p8);
RotatedDim(new Point2d(p1.X, p1.Y - (lst[0] / 2.0)), new Point2d(p3.X, p3.Y - (lst[0] / 2.0)), new Point2d(p3.X, p3.Y - (lst[0] / 2.0)), "<>", true, scal, 1.0 / (si.BarrelDn / 1000 * 2), 0);
db.AddLineToModelSpace(new Point2d(p3.X + (si.BarrelDn / 2.0), p7.Y + 750), new Point2d(p3.X + (si.BarrelDn / 2.0), p8.Y - 750), 1, "ACAD_ISO04W100", 100);
RotatedDim(p4, p6, new Point2d((p4.X + p6.X) / 2.0, p4.Y - (2.5 * fonthig)), "%%c<>(内径)", true, scal, 1, 0);
Point2d ptrdim = new Point2d(p7.X + (2.5 * fonthig), (p7.Y + p8.Y) / 2.0);
RotatedDim(p7, p8, ptrdim, "<>", false, scal, 1.0, 0);
}
}
/// <summary>
/// 承压环、底环板均分函数
/// </summary>
/// <param name="maxr">外圆半径</param>
/// <param name="platewid">排版板宽</param>
/// <param name="totalang">均分总角度</param>
/// <param name="divnum">最优均分数量</param>
/// <param name="divnum2">均分数量</param>
private static void PlateDiv(double maxr, int platewid, double totalang, out int divnum, out int divnum2)
{
double widang = 2 * Math.Atan2(platewid / 2.0, Math.Sqrt(Math.Pow(maxr, 2) - Math.Pow(platewid / 2.0, 2)));
divnum = (int)(totalang / widang);
int divnum1 = divnum;
double divang = totalang / divnum1;
//计算拼接数量
while (maxr * Math.Sin(divang / 2.0) > (platewid / 2.0))
{
divnum1++;
divang = totalang / divnum1;
}
divnum2 = divnum1;
divang = totalang / divnum2;
while (maxr * Math.Sin(divang / 2.0) < (platewid / 2.0))
{
divnum2--;
divang = totalang / divnum2;
}
//确定拼接数量
divnum = divnum1 > divnum ? divnum1 : divnum2;
}
/// <summary>
/// 创建圆环均分及文字
/// </summary>
/// <param name="maxr">圆环最大直径</param>
/// <param name="minr">圆环最小直径</param>
/// <param name="cen">圆环圆心点</param>
/// <param name="divnum">圆环等分数量</param>
/// <param name="divang">圆环等分后,每分角度(弧度)</param>
/// <param name="atpy">焊缝编号,A10X,B20X</param>
private static void MakeRingDivWeldText(double maxr, double minr, Point3d cen, int divnum, double divang, string atpy)
{
for (int i = 0; i < divnum; i++)
{
double lang = (divang / 2.0) + (i * divang);
db.AddLineToModelSpace(cen.PolarPtOfDegree(lang, minr), cen.PolarPtOfDegree(lang, maxr));
string str = $"{atpy}-{i + 1}";
TextHorizontalMode thm;
if (Math.Abs(lang - (Math.PI * 0.5)) < (0.5 * divang) || Math.Abs(lang - (Math.PI * 1.5)) < (0.5 * divang) || lang == Math.PI * 0.5 || lang == Math.PI * 1.5)
thm = TextHorizontalMode.TextCenter;
else if (lang > (Math.PI * 0.5) && lang < (Math.PI * 1.5)) thm = TextHorizontalMode.TextRight;
else thm = TextHorizontalMode.TextLeft;
Point3d tpt = cen.PolarPtOfDegree(lang, maxr + fonthig);
bool angpart = (lang > 0 && lang <= (Math.PI * 0.5)) || (lang > Math.PI && lang <= (Math.PI * 1.5));
double tang = (divang / 2.0) + (i * divang), bigang, smlang;
if (lang <= Math.PI * 0.5)
{
smlang = 0;
bigang = Math.PI * 0.5;
}
else if (lang <= Math.PI)
{
smlang = Math.PI * 0.5;
bigang = Math.PI;
}
else if (lang <= Math.PI * 1.5)
{
smlang = Math.PI;
bigang = Math.PI * 1.5;
}
else
{
smlang = Math.PI * 1.5;
bigang = Math.PI * 2;
}
Point3d prpt1 = tpt;
int n = angpart ? -1 : 1;
Point3d prpt2 = cen.PolarPtOfDegree((divang / 2.0) + ((i + n) * divang), maxr + fonthig);
while (Math.Abs(prpt1.Y - prpt2.Y) <= (1.1 * fonthig) && ((divang / 2.0) + ((i + n) * divang)) > smlang && ((divang / 2.0) + ((i + n) * divang)) <= bigang)
{
if (lang > 0 && lang < Math.PI)
{
tpt = tpt.PolarPtOfDegree(lang, Math.Abs((prpt2.Y + (1.1 * fonthig) - prpt1.Y) / Math.Sin(tang)));
}
else
{
tpt = tpt.PolarPtOfDegree(lang, Math.Abs((prpt2.Y - prpt1.Y - (1.1 * fonthig)) / Math.Sin(tang)));
}
prpt1 = prpt2;
if (angpart) n--;
else n++;
prpt2 = cen.PolarPtOfDegree((divang / 2.0) + ((i + n) * divang), maxr + fonthig);
}
if (pted2.Y > tpt.Y) pte0 = pted2 = new Point3d(pted2.X, tpt.Y - (0.5 * fonthig), 0);
db.AddTextToModelSpace(tpt, str, fonthig, thm, TextVerticalMode.TextVerticalMid);
}
}
#endregion
//============================================================