diff --git a/Cad/FeatureDrivenDrawer.cs b/Cad/FeatureDrivenDrawer.cs index a503620..03b4285 100644 --- a/Cad/FeatureDrivenDrawer.cs +++ b/Cad/FeatureDrivenDrawer.cs @@ -166,17 +166,28 @@ namespace CadParamPluging.Cad bool isRolling = !string.IsNullOrWhiteSpace(processMethod) && processMethod.Contains("轧制"); double activeWidth = outerDia; - double extraMargin = 40; // Default margin + var extraMargin = 40.0; // Default margin if (isMachined && isRolling) { - // In schematic mode, width is visually fixed to 2.0 * Height - activeWidth = height * 2.0; - - // 对于示意图模式,边距应按比例计算(图形较大尺寸的50%),上限100 - // 避免小型示意图因边距过大导致"预期尺寸"虚高 - var maxDim = Math.Max(activeWidth, height); - extraMargin = Math.Min(maxDim * 0.5, 100); + var minWallThickness = bag.GetDoubleOrNull(KeyMinWallThickness); + + if (minWallThickness.HasValue && minWallThickness.Value > 0) + { + // Width is controlled by min wall thickness (Width = 3 * Wall) + // Schematic mode: 2/3 hole, 1/3 wall + activeWidth = minWallThickness.Value * 3.0; + } + else + { + // Fallback: visual width is fixed to 3.0 * Height + activeWidth = height * 3.0; + } + + // Increase margin significantly for schematic mode to avoid "Too Small" detection + // leading to unnecessary zoom-in suggestions (e.g. 1:1.35). + // Effectively claims a larger safe zone around the small schematic. + extraMargin = 120; } // 环形图形:宽度=外径(X方向),高度=高度参数(Y方向) @@ -375,40 +386,52 @@ namespace CadParamPluging.Cad { var bag = ctx.Bag; + // --- 几何与视觉映射计算 --- // --- 几何与视觉映射计算 --- double H = height; double physicalOuterR = outerDia / 2.0; - - // 1. 确定视觉外半径 (L) - // 轧制+车加工:强制 L/H = 2 - double visualOuterR = physicalOuterR; - if (ctx.IsMachined) + double physicalInnerR = 0; + + var innerDia = bag.GetDoubleOrNull(KeyInnerDiameter2); + if (innerDia.HasValue && innerDia.Value > 0) { - visualOuterR = H * 2.0; + physicalInnerR = innerDia.Value / 2.0; } - // 2. 确定视觉内半径 - var innerDia = bag.GetDoubleOrNull(KeyInnerDiameter2); - double physicalInnerR = 0; - double visualInnerR = 0; + // 1. 确定视觉半径 + // 默认情况:等于物理半径 + double visualOuterR = physicalOuterR; + double visualInnerR = physicalInnerR; - if (innerDia.HasValue && innerDia.Value > 0 && innerDia.Value < outerDia) + // 轧制+车加工(示意图模式)特殊处理 + if (ctx.IsMachined) { - physicalInnerR = innerDia.Value / 2.0; + var minWallThkParam = bag.GetDoubleOrNull(KeyMinWallThickness); - if (ctx.IsMachined) + if (minWallThkParam.HasValue && minWallThkParam.Value > 0) { - // 强制示意图模式: - // 按照用户提供的参考图 (L/H=2),右侧剖面区域和左侧内孔区域各占一半 - // 即 Visual Inner Radius = Visual Outer Radius / 2.0 - // 这样视觉上就是两个并排的正方形:左边是空的,右边是剖面 - visualInnerR = visualOuterR * 0.5; + // 用户新需求:比例改为 3:1 + // 指定规则:图纸总宽度(视觉外半径) = 最小壁厚 * 3 + // 这意味着: + // 视觉内半径 (孔) = 最小壁厚 * 2 (占2份) + // 视觉剖面宽度 (壁) = 最小壁厚 * 1 (占1份) + // 从而实现了 2:1 的内孔/实体分割 + visualInnerR = minWallThkParam.Value * 2.0; + visualOuterR = minWallThkParam.Value * 3.0; } else { - visualInnerR = physicalInnerR * (visualOuterR / physicalOuterR); + // 降级策略:维持 3:1 比例 + visualOuterR = H * 3.0; + visualInnerR = visualOuterR * (2.0/3.0); } } + // 纯轧制模式(非车加工):按物理比例绘制,无需特殊处理 + else if (Math.Abs(physicalOuterR) > 1e-6) // 避免除零 + { + // visualInnerR 已经在上面初始化为 physicalInnerR + // 这里不需要改变,因为 visualOuterR = physicalOuterR + } // 3. 定义半径映射函数 (非线性映射:孔区线性,壁厚区线性) // r: 物理半径