Adjust center-punch inner lower fillets

This commit is contained in:
sladro 2026-05-08 10:27:51 +08:00
parent 06740d4eef
commit 2fb938cf96
3 changed files with 196 additions and 38 deletions

97
AGENTS.md Normal file
View File

@ -0,0 +1,97 @@
# AGENTS.md
## 输出风格
- 先给结论,再说明必要条件和风险。
- 说业务含义,不只报类名、方法名。
- 不重复用户已经明确的前提。
- 不用长篇背景说明替代直接答案。
- 发现需求表达可能有歧义时,先确认,不要自行扩大范围。
## 开发原则
- 不过度开发,只做当前需求能闭环的最小改动。
- 每一行改动都要能对应到用户需求。
- 不顺手重构、不清理无关代码、不改无关格式。
- 先定位模板和调用链,再改代码。
- 物理隔离模板优先改各自独立 Drawer不要改通用 `FeatureDrivenDrawer`,除非明确要影响所有模板。
## 项目结构认知
- 这是 AutoCAD 插件项目,主工程是 `CadParamPluging.csproj`
- CAD 绘图逻辑主要在 `Cad/`
- 模板生成器注册在 `Cad/Drawers/`
- 模板参数默认配置在 `Common/TemplateSchemaDefaults.cs`
- UI 参数入口主要在 `UI/ParamDrawingPanel.cs` 和相关窗体。
- 断线、中心线、图层、线型样式由 `Cad/DrawingStyleManager.cs` 管理。
## 模板隔离规则
当前项目模板是物理分开的,改模板前必须先确认对应文件:
- 车加工-轧制-环形:
- Drawer`Cad/RingMachinedRollingDrawer.cs`
- Generator`Cad/Drawers/RingMachinedRollingGenerator.cs`
- 毛料态-轧制-环形:
- Drawer`Cad/RingRawRollingDrawer.cs`
- Generator`Cad/Drawers/RingRawRollingGenerator.cs`
- 毛料态-自由锻-轴杆-圆轴:
- Drawer`Cad/ShaftRawFreeForgeRoundShaftDrawer.cs`
- Generator`Cad/Drawers/ShaftRawFreeForgeRoundShaftGenerator.cs`
- 毛料态-自由锻-轴杆-方轴:
- Drawer`Cad/ShaftRawFreeForgeSquareShaftDrawer.cs`
- Generator`Cad/Drawers/ShaftRawFreeForgeSquareShaftGenerator.cs`
不要因为模板逻辑相似就改错文件。确认 `TemplateKeyBuilder.Build(...)` 的四个参数后再动代码。
## 断线相关约定
- “断线数量”和“线型样式”是两回事:
- 几何断线数量:图上实际画几根竖线。
- 线型样式:每一根线内部显示为长线、短线、点划线等。
- 用户说“中间三个短竖线”时,通常指单根断线的线型图案,不是新增第三根几何断线。
- 四个相关模板的断线几何应保持两根竖向断线。
- 断线线型统一走 `DrawingStyleManager.Role.BreakLine`
- 断线对象需要显式设置 `LinetypeScale = 5.0`
- 若要改断线图案,优先改 `DrawingStyleManager` 的 BreakLine 线型定义,不要在各模板里新增额外断线实体。
## 轧制环形左侧断口约定
车加工-轧制-环形和毛料态-轧制-环形应保持一致:
- 左侧上下横线需要向断线左侧外延 10 个单位。
- 外延后的最左侧需要加中心线。
- 中心线使用 `Centerline` 样式,线型比例为 `8.0`
- 上下横线不能穿过两根断线之间,断线区域要断开。
- 底部水平尺寸标注线的左侧起点要和左延后的图形最左边对齐。
## 验证要求
修改后至少执行:
```powershell
& "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" "CadParamPluging.csproj" /p:Configuration=Debug /p:Platform=AnyCPU /nologo
```
当前项目可能存在既有警告:
- AutoCAD 引用是 AMD64项目是 AnyCPU可能出现 `MSB3270`
- 个别文件可能有重复 `using System` 警告。
如果编译结果是 `0 个错误`,这些既有警告不要顺手处理,除非用户明确要求。
## 测试与回归检查
- 若行为可以用轻量源码级检查覆盖,可以在 `Tests/` 下增加窄范围测试。
- 测试只覆盖本次需求,不要扩大成通用框架。
- 测试生成的临时 `.exe` 要清理,不要留编译产物。
## Git 与改动边界
- 可能存在用户未提交改动,不能随意回退。
- 不使用 `git reset --hard`、`git checkout --` 等破坏性命令,除非用户明确要求。
- 不改 `bin/`、`obj/` 里的生成产物。
- 最终说明要列清楚改了哪些模板、哪些文件、验证结果。

View File

@ -126,6 +126,7 @@ namespace CadParamPluging.Cad.Drawers
// Radii
var outerFilletR = bag.GetDoubleOrNull(FeatureDrivenDrawer.KeyUnspecifiedFilletRadiusMax) ?? 0;
var innerFilletR = bag.GetDoubleOrNull(FeatureDrivenDrawer.KeyInnerRadiusMax) ?? 0;
var lowerInnerFilletR = outerFilletR;
// Pre-calculate inner hole parameters
var innerDia = bag.GetDoubleOrNull(FeatureDrivenDrawer.KeyInnerDiameter2);
@ -141,9 +142,9 @@ namespace CadParamPluging.Cad.Drawers
double xInnerRightVal = ctx.Center.X + innerDia.Value / 2.0;
// Draw Left Section Contour (Outer Edge: ox, Inner Edge: xInnerLeftVal)
// Left Side of Left Section is Outer -> outerFilletR
// Right Side of Left Section is Inner -> innerFilletR
DrawSectionWithAsymmetricFillets(ctx, ox, xInnerLeftVal, oy, H, outerFilletR, innerFilletR);
DrawSectionWithCornerFillets(
ctx, ox, xInnerLeftVal, oy, H,
rBottomLeft: outerFilletR, rBottomRight: lowerInnerFilletR, rTopRight: innerFilletR, rTopLeft: outerFilletR);
if (innerFilletR > 0)
{
@ -153,29 +154,31 @@ namespace CadParamPluging.Cad.Drawers
}
// Draw Right Section Contour (Inner Edge: xInnerRightVal, Outer Edge: ox + W)
// Left Side of Right Section is Inner -> innerFilletR
// Right Side of Right Section is Outer -> outerFilletR
DrawSectionWithAsymmetricFillets(ctx, xInnerRightVal, ox + W, oy, H, innerFilletR, outerFilletR);
DrawSectionWithCornerFillets(
ctx, xInnerRightVal, ox + W, oy, H,
rBottomLeft: lowerInnerFilletR, rBottomRight: outerFilletR, rTopRight: outerFilletR, rTopLeft: innerFilletR);
// Draw Connecting Lines (Hole Back View) - Top and Bottom
// Extend into the inner fillet radius
double lineStart = xInnerLeftVal - innerFilletR;
double lineEnd = xInnerRightVal + innerFilletR;
double lineStartTop = xInnerLeftVal - innerFilletR;
double lineEndTop = xInnerRightVal + innerFilletR;
double lineStartBottom = xInnerLeftVal - lowerInnerFilletR;
double lineEndBottom = xInnerRightVal + lowerInnerFilletR;
var connectingLineTop = new Line(new Point3d(lineStart, oy + H, 0), new Point3d(lineEnd, oy + H, 0));
var connectingLineTop = new Line(new Point3d(lineStartTop, oy + H, 0), new Point3d(lineEndTop, oy + H, 0));
ctx.Style?.Apply(connectingLineTop, DrawingStyleManager.Role.OutlineBold);
ctx.Btr.AppendEntity(connectingLineTop);
ctx.Tr.AddNewlyCreatedDBObject(connectingLineTop, true);
var connectingLineBottom = new Line(new Point3d(lineStart, oy, 0), new Point3d(lineEnd, oy, 0));
var connectingLineBottom = new Line(new Point3d(lineStartBottom, oy, 0), new Point3d(lineEndBottom, oy, 0));
ctx.Style?.Apply(connectingLineBottom, DrawingStyleManager.Role.OutlineBold);
ctx.Btr.AppendEntity(connectingLineBottom);
ctx.Tr.AddNewlyCreatedDBObject(connectingLineBottom, true);
// Adjust Inner Dim to attach to vertical wall (offset by innerFilletR)
FeatureDrivenDrawer.DrawInnerDiameterDimension(ctx, xInnerLeftVal, xInnerRightVal, oy + innerFilletR, innerDia.Value, innerTolPlus, innerTolMinus, innerDiaPrime);
FeatureDrivenDrawer.DrawInnerDiameterDimension(ctx, xInnerLeftVal, xInnerRightVal, oy + lowerInnerFilletR, innerDia.Value, innerTolPlus, innerTolMinus, innerDiaPrime);
// Store values for later use in dimensions/notes
xInnerRight = xInnerRightVal;
@ -244,9 +247,9 @@ namespace CadParamPluging.Cad.Drawers
var dimText = $"{FeatureDrivenDrawer.FormatDimNumber(val)}min";
FeatureDrivenDrawer.AddLinearDim(
ctx,
new Point3d(xInnerRight.Value, oy + innerFilletR, 0),
new Point3d(xInnerRight.Value, oy + lowerInnerFilletR, 0),
new Point3d(ox + W, oy + outerFilletR, 0),
new Point3d((xInnerRight.Value + ox + W) / 2, oy + innerFilletR - 25, 0),
new Point3d((xInnerRight.Value + ox + W) / 2, oy + lowerInnerFilletR - 25, 0),
0,
dimText);
}
@ -292,25 +295,36 @@ namespace CadParamPluging.Cad.Drawers
}
/// <summary>
/// Draws a section rectangle with potentially different fillet radii for left and right sides.
/// Draws a section rectangle with potentially different fillet radii for each corner.
/// Also handles hatching.
/// rLeft: Radius for Top-Left and Bottom-Left corners.
/// rRight: Radius for Top-Right and Bottom-Right corners.
/// </summary>
private static void DrawSectionWithAsymmetricFillets(FeatureDrivenDrawer.DrawingContext ctx, double xLeft, double xRight, double yBottom, double height, double rLeft, double rRight)
private static void DrawSectionWithCornerFillets(
FeatureDrivenDrawer.DrawingContext ctx,
double xLeft,
double xRight,
double yBottom,
double height,
double rBottomLeft,
double rBottomRight,
double rTopRight,
double rTopLeft)
{
var yTop = yBottom + height;
var width = xRight - xLeft;
// Constrain radii
var maxR = Math.Min(width * 0.5, height * 0.5);
var rl = Math.Min(rLeft, maxR);
var rr = Math.Min(rRight, maxR);
if (rl < 0) rl = 0;
if (rr < 0) rr = 0;
var rbl = Math.Min(rBottomLeft, maxR);
var rbr = Math.Min(rBottomRight, maxR);
var rtr = Math.Min(rTopRight, maxR);
var rtl = Math.Min(rTopLeft, maxR);
if (rbl < 0) rbl = 0;
if (rbr < 0) rbr = 0;
if (rtr < 0) rtr = 0;
if (rtl < 0) rtl = 0;
// If radii are negligible, draw rectangle
if (rl <= 0.01 && rr <= 0.01)
if (rbl <= 0.01 && rbr <= 0.01 && rtr <= 0.01 && rtl <= 0.01)
{
// ... (Logic from FeatureDrivenDrawer but combined)
// Use reuse logic or just implement simply.
@ -335,29 +349,29 @@ namespace CadParamPluging.Cad.Drawers
var poly = new Polyline();
// 1. Bottom Line Start (xLeft + rl)
poly.AddVertexAt(0, new Point2d(xLeft + rl, yBottom), 0, 0, 0);
// 1. Bottom Line Start
poly.AddVertexAt(0, new Point2d(xLeft + rbl, yBottom), 0, 0, 0);
// 2. Bottom Line End / Bottom-Right Arc Start (xRight - rr)
poly.AddVertexAt(1, new Point2d(xRight - rr, yBottom), bulge, 0, 0);
// 2. Bottom Line End / Bottom-Right Arc Start
poly.AddVertexAt(1, new Point2d(xRight - rbr, yBottom), bulge, 0, 0);
// 3. Right Line Start / Bottom-Right Arc End (xRight, yBottom + rr)
poly.AddVertexAt(2, new Point2d(xRight, yBottom + rr), 0, 0, 0);
// 3. Right Line Start / Bottom-Right Arc End
poly.AddVertexAt(2, new Point2d(xRight, yBottom + rbr), 0, 0, 0);
// 4. Right Line End / Top-Right Arc Start (xRight, yTop - rr)
poly.AddVertexAt(3, new Point2d(xRight, yTop - rr), bulge, 0, 0);
// 4. Right Line End / Top-Right Arc Start
poly.AddVertexAt(3, new Point2d(xRight, yTop - rtr), bulge, 0, 0);
// 5. Top Line Start / Top-Right Arc End (xRight - rr, yTop)
poly.AddVertexAt(4, new Point2d(xRight - rr, yTop), 0, 0, 0);
// 5. Top Line Start / Top-Right Arc End
poly.AddVertexAt(4, new Point2d(xRight - rtr, yTop), 0, 0, 0);
// 6. Top Line End / Top-Left Arc Start (xLeft + rl, yTop)
poly.AddVertexAt(5, new Point2d(xLeft + rl, yTop), bulge, 0, 0);
// 6. Top Line End / Top-Left Arc Start
poly.AddVertexAt(5, new Point2d(xLeft + rtl, yTop), bulge, 0, 0);
// 7. Left Line Start / Top-Left Arc End (xLeft, yTop - rl)
poly.AddVertexAt(6, new Point2d(xLeft, yTop - rl), 0, 0, 0);
// 7. Left Line Start / Top-Left Arc End
poly.AddVertexAt(6, new Point2d(xLeft, yTop - rtl), 0, 0, 0);
// 8. Left Line End / Bottom-Left Arc Start (xLeft, yBottom + rl)
poly.AddVertexAt(7, new Point2d(xLeft, yBottom + rl), bulge, 0, 0);
// 8. Left Line End / Bottom-Left Arc Start
poly.AddVertexAt(7, new Point2d(xLeft, yBottom + rbl), bulge, 0, 0);
poly.Closed = true;

View File

@ -0,0 +1,47 @@
using System;
using System.IO;
public static class RingRawFreeForgeCenterPunchFilletTests
{
public static int Main()
{
try
{
CenterPunchInnerLowerFilletsUseUnspecifiedRadius();
Console.WriteLine("Ring raw free-forge center-punch fillet tests passed.");
return 0;
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
return 1;
}
}
private static void CenterPunchInnerLowerFilletsUseUnspecifiedRadius()
{
var sourcePath = Path.Combine("Cad", "Drawers", "RingRawFreeForgeCenterPunchDrawer.cs");
var source = File.ReadAllText(sourcePath);
if (!source.Contains("var lowerInnerFilletR = outerFilletR;"))
{
throw new InvalidOperationException(sourcePath + ": lower inner hole fillets must use UnspecifiedFilletRadiusMax.");
}
if (!source.Contains("rBottomLeft: outerFilletR, rBottomRight: lowerInnerFilletR, rTopRight: innerFilletR, rTopLeft: outerFilletR"))
{
throw new InvalidOperationException(sourcePath + ": left section must keep the upper inner fillet as InnerRadiusMax and use UnspecifiedFilletRadiusMax only for the lower inner fillet.");
}
if (!source.Contains("rBottomLeft: lowerInnerFilletR, rBottomRight: outerFilletR, rTopRight: outerFilletR, rTopLeft: innerFilletR"))
{
throw new InvalidOperationException(sourcePath + ": right section must keep the upper inner fillet as InnerRadiusMax and use UnspecifiedFilletRadiusMax only for the lower inner fillet.");
}
if (!source.Contains("double lineStartBottom = xInnerLeftVal - lowerInnerFilletR;") ||
!source.Contains("double lineEndBottom = xInnerRightVal + lowerInnerFilletR;"))
{
throw new InvalidOperationException(sourcePath + ": lower hole connecting line must align with the new lower inner fillet radius.");
}
}
}