diff --git a/Cad/DiskRawFreeForgeDrawer.cs b/Cad/DiskRawFreeForgeDrawer.cs index 198c143..08e3cec 100644 --- a/Cad/DiskRawFreeForgeDrawer.cs +++ b/Cad/DiskRawFreeForgeDrawer.cs @@ -62,13 +62,40 @@ namespace CadParamPluging.Cad double R = diameter.Value / 2.0; double H = height.Value; - // 绘制饼盘轮廓(俯视图为圆,侧视图为矩形) - // 这里绘制侧视图 + // 获取未注圆角半径 + var unspecifiedFillet = bag.GetDoubleOrNull(FeatureDrivenDrawer.KeyUnspecifiedFilletRadiusMax); + double r = unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0 ? unspecifiedFillet.Value : 0; + + // 安全检查:圆角不能超过宽或高的一半 + double maxR = Math.Min(diameter.Value * 0.5, H * 0.5); + r = Math.Min(r, maxR); + + // 绘制饼盘轮廓(俯视图为圆,侧视图为矩形,根据 R 控制圆角弧度) var poly = new Polyline(); - poly.AddVertexAt(0, new Point2d(ox, oy), 0, 0, 0); - poly.AddVertexAt(1, new Point2d(ox + diameter.Value, oy), 0, 0, 0); - poly.AddVertexAt(2, new Point2d(ox + diameter.Value, oy + H), 0, 0, 0); - poly.AddVertexAt(3, new Point2d(ox, oy + H), 0, 0, 0); + if (r > 0.01) + { + var bulge = Math.Tan(Math.PI / 8.0); + double xLeft = ox; + double xRight = ox + diameter.Value; + double yBottom = oy; + double yTop = oy + H; + + poly.AddVertexAt(0, new Point2d(xLeft + r, yBottom), 0, 0, 0); + poly.AddVertexAt(1, new Point2d(xRight - r, yBottom), bulge, 0, 0); + poly.AddVertexAt(2, new Point2d(xRight, yBottom + r), 0, 0, 0); + poly.AddVertexAt(3, new Point2d(xRight, yTop - r), bulge, 0, 0); + poly.AddVertexAt(4, new Point2d(xRight - r, yTop), 0, 0, 0); + poly.AddVertexAt(5, new Point2d(xLeft + r, yTop), bulge, 0, 0); + poly.AddVertexAt(6, new Point2d(xLeft, yTop - r), 0, 0, 0); + poly.AddVertexAt(7, new Point2d(xLeft, yBottom + r), bulge, 0, 0); + } + else + { + poly.AddVertexAt(0, new Point2d(ox, oy), 0, 0, 0); + poly.AddVertexAt(1, new Point2d(ox + diameter.Value, oy), 0, 0, 0); + poly.AddVertexAt(2, new Point2d(ox + diameter.Value, oy + H), 0, 0, 0); + poly.AddVertexAt(3, new Point2d(ox, oy + H), 0, 0, 0); + } poly.Closed = true; ctx.Style?.Apply(poly, DrawingStyleManager.Role.OutlineBold); @@ -83,7 +110,8 @@ namespace CadParamPluging.Cad var diaTolMinusStr = bag.GetString(FeatureDrivenDrawer.KeyDiameterTolMinus); var diaDimText = BuildDimensionText($"%%c{FormatDimNumber(diameter.Value, diameterStr)}", diaTolPlus, diaTolMinus, diaTolPlusStr, diaTolMinusStr); - AddLinearDim(ctx, new Point3d(ox, oy, 0), new Point3d(ox + diameter.Value, oy, 0), + // 为避免标注界线悬空,根据 r 的存在小幅调整起点 + AddLinearDim(ctx, new Point3d(ox, oy + r, 0), new Point3d(ox + diameter.Value, oy + r, 0), new Point3d(ctx.Center.X, oy - 20, 0), 0, diaDimText); // 高度标注 @@ -94,11 +122,10 @@ namespace CadParamPluging.Cad var htTolMinusStr = bag.GetString(FeatureDrivenDrawer.KeyHeight1TolMinus); var htDimText = BuildDimensionText(FormatDimNumber(H, heightStr), htTolPlus, htTolMinus, htTolPlusStr, htTolMinusStr); - AddLinearDim(ctx, new Point3d(ox + diameter.Value, oy, 0), new Point3d(ox + diameter.Value, oy + H, 0), + AddLinearDim(ctx, new Point3d(ox + diameter.Value - r, oy, 0), new Point3d(ox + diameter.Value - r, oy + H, 0), new Point3d(ox + diameter.Value + 20, ctx.Center.Y, 0), 90, htDimText); - // 未注圆角(使用通用 Key) - var unspecifiedFillet = bag.GetDoubleOrNull(FeatureDrivenDrawer.KeyUnspecifiedFilletRadiusMax); + // 添加未注圆角文字标注 if (unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0) { DrawUnspecifiedFilletNote(ctx, ox, oy + H, R, diameter.Value, unspecifiedFillet.Value);