feat: 新增环形毛料自由锻中心冲孔和块状毛料自由锻圆头零件的CAD绘图逻辑。

This commit is contained in:
sladro 2026-02-23 09:42:24 +08:00
parent 11dd4b0568
commit 467db9c31d
2 changed files with 121 additions and 13 deletions

View File

@ -157,6 +157,20 @@ namespace CadParamPluging.Cad
// This ensures the Big Arc starts curving exactly where the Side Frame vertical edge ends.
DrawBlockRoundHeadOutline(ctx, ox, oy, visualTotalW, H, arcHeight, effectiveHeadR);
// 绘制圆角的斜向标注如果存在圆角4-R<=*
if (effectiveHeadR > 0)
{
// 左上角
double yTop = oy + H;
double cxLeft = xInnerLeft + effectiveHeadR;
double cyLeft = yTop - effectiveHeadR;
DrawHeadFilletRadiusLeader(ctx, cxLeft, cyLeft, effectiveHeadR, true);
// 右上角
double cxRight = xInnerRight - effectiveHeadR;
DrawHeadFilletRadiusLeader(ctx, cxRight, cyLeft, effectiveHeadR, false);
}
// 3. 剖面填充 - 只在中间区域
// 使用 sectionFilletR
if (sectionFilletR > 0.01)
@ -629,6 +643,89 @@ namespace CadParamPluging.Cad
catch { }
}
private static void DrawHeadFilletRadiusLeader(FeatureDrivenDrawer.DrawingContext ctx, double cx, double cy, double r, bool isLeftSection)
{
try
{
var val = ctx.OriginalBag?.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxRoundHeadFilletRadiusMax);
if (!val.HasValue || val.Value <= 0) return;
// 左上角向左上(135),右上角向右上(45)
double angleDeg = isLeftSection ? 135 : 45;
double angleRad = angleDeg * Math.PI / 180.0;
// 起点(外圆角,引线从圆弧表面引出)
double px = cx + r * Math.Cos(angleRad);
double py = cy + r * Math.Sin(angleRad);
// 终点
double ex = px + 25 * Math.Cos(angleRad);
double ey = py + 25 * Math.Sin(angleRad);
// 画直线
var line = new Line(new Point3d(px, py, 0), new Point3d(ex, ey, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.Dimension);
line.ColorIndex = 4; // Cyan
ctx.Btr.AppendEntity(line);
ctx.Tr.AddNewlyCreatedDBObject(line, true);
// 绘制实心箭头
double arrowLength = 5.0; // 箭头长度,加长
double arrowWidth = 1.5; // 箭头宽度,加宽
double baseX = px + arrowLength * Math.Cos(angleRad);
double baseY = py + arrowLength * Math.Sin(angleRad);
double perpAngle = angleRad + Math.PI / 2;
double p1X = baseX + (arrowWidth / 2) * Math.Cos(perpAngle);
double p1Y = baseY + (arrowWidth / 2) * Math.Sin(perpAngle);
double p2X = baseX - (arrowWidth / 2) * Math.Cos(perpAngle);
double p2Y = baseY - (arrowWidth / 2) * Math.Sin(perpAngle);
var arrow = new Solid(new Point3d(px, py, 0), new Point3d(p1X, p1Y, 0), new Point3d(p2X, p2Y, 0));
arrow.ColorIndex = 4;
ctx.Btr.AppendEntity(arrow);
ctx.Tr.AddNewlyCreatedDBObject(arrow, true);
// 文字(与线对齐)
var textStr = $"4-R\\U+2264{val.Value}";
var text = new DBText();
text.TextString = textStr;
text.Height = 3.5;
text.ColorIndex = 4; // Cyan
// 倾斜文字角度
double textRotation = angleRad;
if (isLeftSection)
{
// 左侧角度是 135文字应该 -45度(减去180)保证从左向右读
textRotation = angleRad - Math.PI;
}
text.Rotation = textRotation;
// 对齐设置
text.HorizontalMode = TextHorizontalMode.TextCenter;
text.VerticalMode = TextVerticalMode.TextBottom;
// 计算文字放置点,紧贴在线端上方
double offsetX = 2.0 * Math.Cos(textRotation + Math.PI / 2);
double offsetY = 2.0 * Math.Sin(textRotation + Math.PI / 2);
var tp = new Point3d(ex + offsetX, ey + offsetY, 0);
text.AlignmentPoint = tp;
text.Position = tp;
ctx.Style?.Apply(text, DrawingStyleManager.Role.Text);
text.ColorIndex = 4;
ctx.Btr.AppendEntity(text);
ctx.Tr.AddNewlyCreatedDBObject(text, true);
}
catch
{
// ignore
}
}
private static void DrawSpecialHBLeaderToTop(FeatureDrivenDrawer.DrawingContext ctx, double xTarget, double yTarget, string textContent)
{
try

View File

@ -385,20 +385,33 @@ namespace CadParamPluging.Cad.Drawers
double px = cx + r * Math.Cos(angleRad);
double py = cy + r * Math.Sin(angleRad);
// 终点(沿着同一角度延伸出去一定长度作为引出线,比如长 25
// 终点
double ex = px + 25 * Math.Cos(angleRad);
double ey = py + 25 * Math.Sin(angleRad);
var leader = new Leader();
leader.SetDatabaseDefaults();
leader.AppendVertex(new Point3d(px, py, 0));
leader.AppendVertex(new Point3d(ex, ey, 0));
leader.HasArrowHead = true;
ctx.Style?.Apply(leader, DrawingStyleManager.Role.Dimension);
leader.ColorIndex = 4; // Cyan
// 画线
var line = new Line(new Point3d(px, py, 0), new Point3d(ex, ey, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.Dimension);
line.ColorIndex = 4; // Cyan
ctx.Btr.AppendEntity(line);
ctx.Tr.AddNewlyCreatedDBObject(line, true);
ctx.Btr.AppendEntity(leader);
ctx.Tr.AddNewlyCreatedDBObject(leader, true);
// 绘制实心剪头,调大尺寸
double arrowLength = 5.0; // 箭头长度 (原为 3.0)
double arrowWidth = 1.5; // 箭头宽度 (原为 1.0)
double baseX = px + arrowLength * Math.Cos(angleRad);
double baseY = py + arrowLength * Math.Sin(angleRad);
double perpAngle = angleRad + Math.PI / 2;
double p1X = baseX + (arrowWidth / 2) * Math.Cos(perpAngle);
double p1Y = baseY + (arrowWidth / 2) * Math.Sin(perpAngle);
double p2X = baseX - (arrowWidth / 2) * Math.Cos(perpAngle);
double p2Y = baseY - (arrowWidth / 2) * Math.Sin(perpAngle);
var arrow = new Solid(new Point3d(px, py, 0), new Point3d(p1X, p1Y, 0), new Point3d(p2X, p2Y, 0));
arrow.ColorIndex = 4;
ctx.Btr.AppendEntity(arrow);
ctx.Tr.AddNewlyCreatedDBObject(arrow, true);
// 文字(与线对齐同角度)
var textStr = $"R\\U+2264{val.Value}";
@ -412,7 +425,6 @@ namespace CadParamPluging.Cad.Drawers
if (!isLeftSection)
{
// For the right side (135 degrees), we want the text to read left-to-right
// So we subtract 180 degrees (PI) from the angle, which makes it -45 degrees
textRotation = angleRad - Math.PI;
}
text.Rotation = textRotation;
@ -421,8 +433,7 @@ namespace CadParamPluging.Cad.Drawers
text.HorizontalMode = TextHorizontalMode.TextCenter;
text.VerticalMode = TextVerticalMode.TextBottom;
// 计算文字放置点,紧贴在结束点上方
// 为了让文字准确地骑在线上,基于文字的旋转角度计算偏移
// 计算文字放置点
double offsetX = 2.0 * Math.Cos(textRotation + Math.PI / 2);
double offsetY = 2.0 * Math.Sin(textRotation + Math.PI / 2);