From bef27c05fb4940b8995ea5ca49a04b0d6a72bf94 Mon Sep 17 00:00:00 2001 From: sladro Date: Wed, 21 Jan 2026 13:44:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BA=86=E6=AF=9B=E6=96=99?= =?UTF-8?q?=E6=80=81/=E8=BD=A7=E5=88=B6/=E7=8E=AF=E5=BD=A2=E7=9A=84?= =?UTF-8?q?=E7=A1=AC=E5=BA=A6=E6=A0=87=E6=B3=A8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cad/FeatureDrivenDrawer.cs | 145 ++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 4 deletions(-) diff --git a/Cad/FeatureDrivenDrawer.cs b/Cad/FeatureDrivenDrawer.cs index dcd12cb..d26ce22 100644 --- a/Cad/FeatureDrivenDrawer.cs +++ b/Cad/FeatureDrivenDrawer.cs @@ -70,6 +70,9 @@ namespace CadParamPluging.Cad public const string KeyBoxSize1Prime = "BoxSize1Prime"; // 方体零件尺寸1 public const string KeyBoxSize2Prime = "BoxSize2Prime"; // 方体零件尺寸2 public const string KeyBoxSize3Prime = "BoxSize3Prime"; // 方体零件尺寸3 + + // 其他参数 + public const string KeyHardness = "Hardness"; // 硬度 #endregion @@ -632,7 +635,8 @@ namespace CadParamPluging.Cad DrawHeightDimensionHalf(ctx, ox, oy, visualOuterR, H, heightTolPlus, heightTolMinus, heightPrime, heightDimIndentX); // === 特征6: 未注圆角 === - if (unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0) + // 针对“毛料态-轧制-环形”模板(applyUnspecifiedFillet=true),不显示此文字 + if (!applyUnspecifiedFillet && unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0) { DrawUnspecifiedFilletNote(ctx, ox, oy, H, visualOuterR, unspecifiedFillet.Value); } @@ -677,12 +681,40 @@ namespace CadParamPluging.Cad // 需满足: 车加工 + 轧制(本方法即为轧制) + 有内孔 if (ctx.IsMachined && innerDia.HasValue && innerDia.Value > 0) { - // 指向锻件内孔右上角(白色线框) - var scaledInnerDia = visualInnerR * 2.0; - DrawSpecialInnerHoleLeader(ctx, ox, oy, H, scaledInnerDia); + if (applyUnspecifiedFillet) + { + // [修改] 针对“毛料态-轧制-环形”模板 + // 指向锻件顶部白色边框的中间位置 + // 顶部中间 X = (xInnerRight + xOuterRight) / 2 + // Y = Top = oy + H + var xLoopInner = ox + visualInnerR; + var xLoopOuter = ox + visualOuterR; + var xTarget = (xLoopInner + xLoopOuter) / 2.0; + var yTarget = oy + H; + + DrawSpecialHBLeaderToTop(ctx, xTarget, yTarget); + } + else + { + // 原有逻辑:指向锻件内孔右上角 + var scaledInnerDia = visualInnerR * 2.0; + DrawSpecialInnerHoleLeader(ctx, ox, oy, H, scaledInnerDia); + } } + + // === 特征9: 硬度符号 === + var hardnessVal = bag.GetString(KeyHardness); + if (!string.IsNullOrWhiteSpace(hardnessVal)) + { + // 指向锻件剖面图的右下角 (白色边框) + // 坐标: xOuterRight, yBottom + double xCorner = ox + visualOuterR; + double yCorner = oy; + + DrawHardnessSymbol(ctx, xCorner, yCorner); + } } @@ -2701,5 +2733,110 @@ namespace CadParamPluging.Cad // ignore } } + + private static void DrawSpecialHBLeaderToTop(DrawingContext ctx, double xTarget, double yTarget) + { + try + { + // 箭头起点:顶部中间 + var p1 = new Point3d(xTarget, yTarget, 0); + + // 转折点:向左上 + var p2 = new Point3d(xTarget - 10, yTarget + 10, 0); + + // 终点:水平向左 + var p3 = new Point3d(p2.X - 35, p2.Y, 0); + + var leader = new Leader(); + leader.SetDatabaseDefaults(); + leader.AppendVertex(p1); + leader.AppendVertex(p2); + leader.AppendVertex(p3); + leader.HasArrowHead = true; + leader.ColorIndex = 7; // 白色 + leader.Layer = "0"; + + ctx.Btr.AppendEntity(leader); + ctx.Tr.AddNewlyCreatedDBObject(leader, true); + + // 绘制文字 + var text = new DBText(); + text.TextString = "HB5936-13"; + text.Height = 3.5; + text.ColorIndex = 7; // 白色 + text.Layer = "0"; + + text.HorizontalMode = TextHorizontalMode.TextLeft; + text.VerticalMode = TextVerticalMode.TextBottom; + text.AlignmentPoint = new Point3d(p3.X, p3.Y + 1.0, 0); + text.Position = text.AlignmentPoint; + + ctx.Btr.AppendEntity(text); + ctx.Tr.AddNewlyCreatedDBObject(text, true); + } + catch + { + // ignore + } + } + + + private static void DrawHardnessSymbol(DrawingContext ctx, double xStart, double yStart) + { + try + { + // 1. 引线 (Diagonal Down-Right -> Horizontal) + // 起点: (xStart, yStart) + // 转折点: (xStart + 15, yStart - 15) + // 终点(圆左侧): (xStart + 15 + 10, yStart - 15) + + var p1 = new Point3d(xStart, yStart, 0); + var p2 = new Point3d(xStart + 15, yStart - 15, 0); + var p3 = new Point3d(p2.X + 10, p2.Y, 0); // 这里的p3是直线的终点,圆接在这里 + + // 绘制引线 + var poly = new Polyline(); + poly.AddVertexAt(0, new Point2d(p1.X, p1.Y), 0, 0, 0); + poly.AddVertexAt(1, new Point2d(p2.X, p2.Y), 0, 0, 0); + poly.AddVertexAt(2, new Point2d(p3.X, p3.Y), 0, 0, 0); + + ctx.Style?.Apply(poly, DrawingStyleManager.Role.Dimension); // 使用 Dimension 角色 + // 确保此时是白色(颜色7) 或 按照标注颜色(青色 or Green?) 图片看起来像青色(Cyan)或白色 + // 用户截图看起来是青色/绿色(标注层颜色). Apply logic usually handles layer/color. + // 我们显式设为青色(4)或者跟随标注层 + poly.ColorIndex = 4; + + ctx.Btr.AppendEntity(poly); + ctx.Tr.AddNewlyCreatedDBObject(poly, true); + + // 2. 圆圈 (HB) + // 圆心 x = p3.X + R + double radius = 4.0; + var center = new Point3d(p3.X + radius, p3.Y, 0); + var circle = new Circle(center, Vector3d.ZAxis, radius); + circle.ColorIndex = 4; + + ctx.Btr.AppendEntity(circle); + ctx.Tr.AddNewlyCreatedDBObject(circle, true); + + // 3. 文字 (HB) + var text = new DBText(); + text.TextString = "HB"; + text.Height = 3.5; + text.ColorIndex = 4; + text.HorizontalMode = TextHorizontalMode.TextCenter; + text.VerticalMode = TextVerticalMode.TextVerticalMid; + text.AlignmentPoint = center; + text.Position = center; + + ctx.Btr.AppendEntity(text); + ctx.Tr.AddNewlyCreatedDBObject(text, true); + } + catch + { + // ignore + } + } + } }