有圆头/无圆头模板完成
This commit is contained in:
parent
c0c9b27789
commit
4a3cfbe649
@ -120,10 +120,27 @@ namespace CadParamPluging.Cad
|
||||
// 2. 绘制分段式内框(左、中、右三段)以支持中间剖面区域的独立圆角
|
||||
// 中间区域(剖面)作为主体,如果设置了圆角,四个角都应为圆角
|
||||
|
||||
// 计算分段坐标
|
||||
double sectionWidth = innerWidth / 3.0;
|
||||
double xSectionLeft = xInnerLeft + sectionWidth;
|
||||
double xSectionRight = xInnerLeft + sectionWidth * 2.0;
|
||||
// 计算视觉上的剖面宽度
|
||||
// 依据用户需求:尺寸3 (BoxSize3) 对应剖面的宽
|
||||
var size3 = bag.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxSize3);
|
||||
double visualSectionWidth;
|
||||
|
||||
if (size3.HasValue && size3.Value > 0)
|
||||
{
|
||||
// 按比例映射:VisualW / PhysicalW
|
||||
double scale = visualTotalW / W;
|
||||
visualSectionWidth = size3.Value * scale;
|
||||
if (visualSectionWidth > innerWidth * 0.95) visualSectionWidth = innerWidth * 0.95;
|
||||
}
|
||||
else
|
||||
{
|
||||
visualSectionWidth = innerWidth / 3.0;
|
||||
}
|
||||
|
||||
// 居中布置剖面
|
||||
double sectionOffset = (innerWidth - visualSectionWidth) / 2.0;
|
||||
double xSectionLeft = xInnerLeft + sectionOffset;
|
||||
double xSectionRight = xSectionLeft + visualSectionWidth;
|
||||
|
||||
// 绘制中间剖面框(带圆角 - 根据需求保留)
|
||||
DrawBoxSectionContourWithFillet(ctx, xSectionLeft, xSectionRight, oy, H, innerFilletR);
|
||||
@ -184,11 +201,19 @@ namespace CadParamPluging.Cad
|
||||
|
||||
var dimText = BuildDimensionText(FormatDimNumber(val, str), tolPlus, tolMinus, tolPlusStr, tolMinusStr);
|
||||
|
||||
// 标注点从内框左右边界开始(连接到矩形内框)
|
||||
// 添加零件尺寸 (Prime) 到下方,用括号包裹
|
||||
var valPrime = ctx.OriginalBag?.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxSize1Prime);
|
||||
if (valPrime.HasValue && valPrime.Value > 0)
|
||||
{
|
||||
dimText += $"\\X({FormatDimNumber(valPrime.Value, null)})";
|
||||
}
|
||||
|
||||
// 标注点从内框左右边界开始(连接到矩形内框) - Modify Y to center to ensure extension lines touch the geometry
|
||||
double dimOriginY = oy + innerFilletR;
|
||||
AddLinearDim(
|
||||
ctx,
|
||||
new Point3d(xInnerLeft, oy, 0),
|
||||
new Point3d(xInnerRight, oy, 0),
|
||||
new Point3d(xInnerLeft, dimOriginY, 0),
|
||||
new Point3d(xInnerRight, dimOriginY, 0),
|
||||
new Point3d((xInnerLeft + xInnerRight) / 2, oy - 25, 0),
|
||||
0,
|
||||
dimText);
|
||||
@ -206,6 +231,13 @@ namespace CadParamPluging.Cad
|
||||
|
||||
var dimText = BuildDimensionText(FormatDimNumber(val, str), tolPlus, tolMinus, tolPlusStr, tolMinusStr);
|
||||
|
||||
// 添加零件尺寸 (Prime) 到下方
|
||||
var valPrime = ctx.OriginalBag?.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxSize2Prime);
|
||||
if (valPrime.HasValue && valPrime.Value > 0)
|
||||
{
|
||||
dimText += $"\\X({FormatDimNumber(valPrime.Value, null)})";
|
||||
}
|
||||
|
||||
// 标注从圆弧最外侧开始(避免与圆弧轮廓线重叠)
|
||||
double xOuterRight = ox + visualTotalW;
|
||||
|
||||
@ -221,18 +253,35 @@ namespace CadParamPluging.Cad
|
||||
dimText);
|
||||
}
|
||||
|
||||
// 8. 中间矩形宽度标注(剖面区域宽度)- 第二个宽度标注,位于上方
|
||||
// 8. 中间矩形宽度标注 (BoxSize3) - 位于上方
|
||||
// 对应剖面区域宽度
|
||||
{
|
||||
var rectRealWidth = W - 2 * arcHeight; // 实际中间矩形宽度 = 总宽度 - 两端圆头
|
||||
if (rectRealWidth > 0)
|
||||
var val = ctx.OriginalBag?.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxSize3) ?? 0;
|
||||
var str = ctx.OriginalBag?.GetString(FeatureDrivenDrawer.KeyBoxSize3);
|
||||
|
||||
if (val > 0)
|
||||
{
|
||||
var tolPlus = ctx.OriginalBag?.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxSize3TolPlus);
|
||||
var tolMinus = ctx.OriginalBag?.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxSize3TolMinus);
|
||||
var tolPlusStr = ctx.OriginalBag?.GetString(FeatureDrivenDrawer.KeyBoxSize3TolPlus);
|
||||
var tolMinusStr = ctx.OriginalBag?.GetString(FeatureDrivenDrawer.KeyBoxSize3TolMinus);
|
||||
|
||||
var dimText = BuildDimensionText(FormatDimNumber(val, str), tolPlus, tolMinus, tolPlusStr, tolMinusStr);
|
||||
|
||||
// 添加零件尺寸 (Prime) 到下方
|
||||
var valPrime = ctx.OriginalBag?.GetDoubleOrNull(FeatureDrivenDrawer.KeyBoxSize3Prime);
|
||||
if (valPrime.HasValue && valPrime.Value > 0)
|
||||
{
|
||||
dimText += $"\\X({FormatDimNumber(valPrime.Value, null)})";
|
||||
}
|
||||
|
||||
AddLinearDim(
|
||||
ctx,
|
||||
new Point3d(xSectionLeft, oy + H, 0),
|
||||
new Point3d(xSectionRight, oy + H, 0),
|
||||
new Point3d((xSectionLeft + xSectionRight) / 2, oy + H + 15, 0),
|
||||
0,
|
||||
FormatDimNumber(rectRealWidth, null));
|
||||
dimText);
|
||||
}
|
||||
}
|
||||
|
||||
@ -676,10 +725,42 @@ namespace CadParamPluging.Cad
|
||||
try { dim.GetType().GetProperty(prop)?.SetValue(dim, val, null); } catch {}
|
||||
}
|
||||
|
||||
private static string FormatDimNumber(double val, string overrideStr)
|
||||
private static string FormatDimNumber(double value, string rawInput = null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(overrideStr)) return overrideStr;
|
||||
return Math.Round(val, 2).ToString();
|
||||
try
|
||||
{
|
||||
// If rawInput is provided and matches the value, use its precision
|
||||
if (!string.IsNullOrWhiteSpace(rawInput) && double.TryParse(rawInput, out var d) && Math.Abs(d - value) < 0.000001)
|
||||
{
|
||||
int decIndex = rawInput.IndexOf('.');
|
||||
int decimals = 0;
|
||||
if (decIndex >= 0)
|
||||
{
|
||||
decimals = rawInput.Length - decIndex - 1;
|
||||
}
|
||||
if (decimals == 0) return value.ToString("0");
|
||||
return value.ToString("0." + new string('0', decimals));
|
||||
}
|
||||
|
||||
// Fallback: auto-detect from value (strip trailing zeros)
|
||||
string str = value.ToString("0.##########");
|
||||
int decimalIndex = str.IndexOf('.');
|
||||
if (decimalIndex < 0)
|
||||
{
|
||||
return str; // Integer, no decimal
|
||||
}
|
||||
|
||||
int autoDecimals = str.Length - decimalIndex - 1;
|
||||
|
||||
if (autoDecimals == 0) return str;
|
||||
|
||||
string format = "0." + new string('0', autoDecimals);
|
||||
return value.ToString(format);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private static string BuildDimensionText(string baseText, double? tolPlus, double? tolMinus, string tolPlusStr = null, string tolMinusStr = null)
|
||||
|
||||
@ -2998,10 +2998,33 @@ namespace CadParamPluging.Cad
|
||||
// 2. 绘制分段式内框(左、中、右三段)以支持中间剖面区域的独立圆角
|
||||
// 中间区域(剖面)作为主体,如果设置了圆角,四个角都应为圆角
|
||||
|
||||
// 计算分段坐标
|
||||
double sectionWidth = innerWidth / 3.0;
|
||||
double xSectionLeft = xInnerLeft + sectionWidth;
|
||||
double xSectionRight = xInnerLeft + sectionWidth * 2.0;
|
||||
// 计算视觉上的剖面宽度
|
||||
// 依据用户需求:尺寸3 (BoxSize3) 对应剖面的宽
|
||||
var size3 = bag.GetDoubleOrNull(KeyBoxSize3);
|
||||
double visualSectionWidth;
|
||||
|
||||
if (size3.HasValue && size3.Value > 0)
|
||||
{
|
||||
// 按比例映射:VisualW / PhysicalW
|
||||
double scale = visualTotalW / W;
|
||||
visualSectionWidth = size3.Value * scale;
|
||||
|
||||
// 限制最大宽度,防止出错
|
||||
if (visualSectionWidth > innerWidth * 0.95)
|
||||
{
|
||||
visualSectionWidth = innerWidth * 0.95;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 降级策略
|
||||
visualSectionWidth = innerWidth / 3.0;
|
||||
}
|
||||
|
||||
// 居中布置剖面
|
||||
double sectionOffset = (innerWidth - visualSectionWidth) / 2.0;
|
||||
double xSectionLeft = xInnerLeft + sectionOffset;
|
||||
double xSectionRight = xSectionLeft + visualSectionWidth;
|
||||
|
||||
// 绘制中间剖面框(带圆角)
|
||||
// 复用 Ring 模板的 SectionContourWithFillet 逻辑绘制中间闭合框
|
||||
@ -3054,7 +3077,7 @@ namespace CadParamPluging.Cad
|
||||
}
|
||||
|
||||
// 6. 宽度标注 (BoxSize1) - 位于底部
|
||||
// 标注从锻件最左端到最右端(包括圆头)
|
||||
// 标注从锻件最左端到最右端 (BoxSize1 对应 锻件总宽)
|
||||
{
|
||||
var val = ctx.OriginalBag?.GetDoubleOrNull(KeyBoxSize1) ?? W;
|
||||
var str = ctx.OriginalBag?.GetString(KeyBoxSize1);
|
||||
@ -3065,11 +3088,21 @@ namespace CadParamPluging.Cad
|
||||
|
||||
var dimText = BuildDimensionText(FormatDimNumber(val, str), tolPlus, tolMinus, tolPlusStr, tolMinusStr);
|
||||
|
||||
// 标注点从内框左右边界开始(连接到矩形内框)
|
||||
// 添加零件尺寸 (Prime) 到下方,用括号包裹
|
||||
var valPrime = ctx.OriginalBag?.GetDoubleOrNull(KeyBoxSize1Prime);
|
||||
if (valPrime.HasValue && valPrime.Value > 0)
|
||||
{
|
||||
dimText += $"\\X({FormatDimNumber(valPrime.Value, null)})";
|
||||
}
|
||||
|
||||
// 修正:标注需涵盖内框宽度 (矩形部分)
|
||||
|
||||
// 修正:引线起点改为内框边界 (xInnerLeft/Right) 和高度底部上移圆角半径 (oy + innerFilletR),确保闭合到白色线框
|
||||
double dimOriginY = oy + innerFilletR;
|
||||
AddLinearDim(
|
||||
ctx,
|
||||
new Point3d(xInnerLeft, oy, 0),
|
||||
new Point3d(xInnerRight, oy, 0),
|
||||
new Point3d(xInnerLeft, dimOriginY, 0),
|
||||
new Point3d(xInnerRight, dimOriginY, 0),
|
||||
new Point3d((xInnerLeft + xInnerRight) / 2, oy - 25, 0),
|
||||
0,
|
||||
dimText);
|
||||
@ -3087,6 +3120,13 @@ namespace CadParamPluging.Cad
|
||||
|
||||
var dimText = BuildDimensionText(FormatDimNumber(val, str), tolPlus, tolMinus, tolPlusStr, tolMinusStr);
|
||||
|
||||
// 添加零件尺寸 (Prime) 到下方
|
||||
var valPrime = ctx.OriginalBag?.GetDoubleOrNull(KeyBoxSize2Prime);
|
||||
if (valPrime.HasValue && valPrime.Value > 0)
|
||||
{
|
||||
dimText += $"\\X({FormatDimNumber(valPrime.Value, null)})";
|
||||
}
|
||||
|
||||
// 标注从圆弧最外侧开始(避免与圆弧轮廓线重叠)
|
||||
double xOuterRight = ox + visualTotalW;
|
||||
// 修正:标注界线起点应从圆弧顶端开始,往内缩进一个圆弧高度 arcHeight + innerFilletR,定位在弦线上
|
||||
@ -3101,18 +3141,36 @@ namespace CadParamPluging.Cad
|
||||
dimText);
|
||||
}
|
||||
|
||||
// 8. 中间矩形宽度标注(剖面区域宽度)- 第二个宽度标注,位于上方
|
||||
// 8. 中间矩形宽度标注 (BoxSize3) - 位于上方
|
||||
// 对应剖面区域宽度
|
||||
{
|
||||
var rectRealWidth = W - 2 * arcHeight; // 实际中间矩形宽度 = 总宽度 - 两端圆头
|
||||
if (rectRealWidth > 0)
|
||||
var val = ctx.OriginalBag?.GetDoubleOrNull(KeyBoxSize3) ?? 0;
|
||||
var str = ctx.OriginalBag?.GetString(KeyBoxSize3);
|
||||
|
||||
// 只有当有值时才标注
|
||||
if (val > 0)
|
||||
{
|
||||
var tolPlus = ctx.OriginalBag?.GetDoubleOrNull(KeyBoxSize3TolPlus);
|
||||
var tolMinus = ctx.OriginalBag?.GetDoubleOrNull(KeyBoxSize3TolMinus);
|
||||
var tolPlusStr = ctx.OriginalBag?.GetString(KeyBoxSize3TolPlus);
|
||||
var tolMinusStr = ctx.OriginalBag?.GetString(KeyBoxSize3TolMinus);
|
||||
|
||||
var dimText = BuildDimensionText(FormatDimNumber(val, str), tolPlus, tolMinus, tolPlusStr, tolMinusStr);
|
||||
|
||||
// 添加零件尺寸 (Prime) 到下方
|
||||
var valPrime = ctx.OriginalBag?.GetDoubleOrNull(KeyBoxSize3Prime);
|
||||
if (valPrime.HasValue && valPrime.Value > 0)
|
||||
{
|
||||
dimText += $"\\X({FormatDimNumber(valPrime.Value, null)})";
|
||||
}
|
||||
|
||||
AddLinearDim(
|
||||
ctx,
|
||||
new Point3d(xSectionLeft, oy + H, 0),
|
||||
new Point3d(xSectionRight, oy + H, 0),
|
||||
new Point3d((xSectionLeft + xSectionRight) / 2, oy + H + 15, 0),
|
||||
0,
|
||||
FormatDimNumber(rectRealWidth, null));
|
||||
dimText);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user