From ac0908e95002e58bed9dbb50dbf4799cca8e5aa8 Mon Sep 17 00:00:00 2001 From: sladro Date: Thu, 18 Dec 2025 16:39:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9FeatureDrivenDrawer=E5=92=8CP?= =?UTF-8?q?aramCatalog,=E5=8F=AF=E4=BB=A5=E9=80=82=E9=85=8D=E6=9C=89?= =?UTF-8?q?=E5=9C=86=E5=A4=B4=E7=AE=97=E6=B3=95=E4=BA=86=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E6=A8=A1=E6=9D=BF=E4=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cad/FeatureDrivenDrawer.cs | 446 ++++++++++++++++++++++++++++++------- Common/ParamCatalog.cs | 234 ++++++++++++++++--- 2 files changed, 578 insertions(+), 102 deletions(-) diff --git a/Cad/FeatureDrivenDrawer.cs b/Cad/FeatureDrivenDrawer.cs index b1aedb6..4fc85f0 100644 --- a/Cad/FeatureDrivenDrawer.cs +++ b/Cad/FeatureDrivenDrawer.cs @@ -24,17 +24,14 @@ namespace CadParamPluging.Cad public const string KeyHeight1TolPlus = "Height1TolPlus"; public const string KeyHeight1TolMinus = "Height1TolMinus"; public const string KeyMinWallThickness = "MinWallThickness"; + public const string KeyUnspecifiedFilletRadiusMax = "UnspecifiedFilletRadiusMax"; // 环形未注圆角 + public const string KeyInnerRadiusMax = "InnerRadiusMax"; // 内径半径R≤(中心冲孔) - // 零件尺寸(车加工态) + // 环形零件尺寸(车加工态) public const string KeyOuterDiameter1Prime = "OuterDiameter1Prime"; public const string KeyInnerDiameter2Prime = "InnerDiameter2Prime"; public const string KeyHeight1Prime = "Height1Prime"; - // 可选特征参数 - public const string KeyUnspecifiedFilletRadiusMax = "UnspecifiedFilletRadiusMax"; - public const string KeyInnerRadiusMax = "InnerRadiusMax"; - public const string KeyRoundHeadFilletRadiusMax = "RoundHeadFilletRadiusMax"; - // 饼盘参数 public const string KeyDiskDiameter = "DiskDiameter"; public const string KeyDiskDiameterTolPlus = "DiskDiameterTolPlus"; @@ -42,25 +39,36 @@ namespace CadParamPluging.Cad public const string KeyDiskHeight = "DiskHeight"; public const string KeyDiskHeightTolPlus = "DiskHeightTolPlus"; public const string KeyDiskHeightTolMinus = "DiskHeightTolMinus"; + public const string KeyDiskFilletRadiusMax = "DiskFilletRadiusMax"; // 饼盘未注圆角 + public const string KeyDiskDiameterPrime = "DiskDiameterPrime"; // 饼盘零件直径 + public const string KeyDiskHeightPrime = "DiskHeightPrime"; // 饼盘零件高度 - // 轴杆参数 + // 轴杆参数(圆轴) public const string KeyDiameter = "Diameter"; public const string KeyDiameterTolPlus = "DiameterTolPlus"; public const string KeyDiameterTolMinus = "DiameterTolMinus"; public const string KeyLength = "Length"; public const string KeyLengthTolPlus = "LengthTolPlus"; public const string KeyLengthTolMinus = "LengthTolMinus"; + public const string KeyShaftFilletRadiusMax = "ShaftFilletRadiusMax"; // 轴杆未注圆角 + public const string KeyDiameterPrime = "DiameterPrime"; // 轴杆零件直径 + public const string KeyLengthPrime = "LengthPrime"; // 轴杆零件长度 - // 方形参数 - public const string KeySize1 = "Size1"; - public const string KeySize2 = "Size2"; - public const string KeySize3 = "Size3"; - public const string KeySize1TolPlus = "Size1TolPlus"; - public const string KeySize1TolMinus = "Size1TolMinus"; - public const string KeySize2TolPlus = "Size2TolPlus"; - public const string KeySize2TolMinus = "Size2TolMinus"; - public const string KeySize3TolPlus = "Size3TolPlus"; - public const string KeySize3TolMinus = "Size3TolMinus"; + // 方体参数 + public const string KeyBoxSize1 = "BoxSize1"; + public const string KeyBoxSize1TolPlus = "BoxSize1TolPlus"; + public const string KeyBoxSize1TolMinus = "BoxSize1TolMinus"; + public const string KeyBoxSize2 = "BoxSize2"; + public const string KeyBoxSize2TolPlus = "BoxSize2TolPlus"; + public const string KeyBoxSize2TolMinus = "BoxSize2TolMinus"; + public const string KeyBoxSize3 = "BoxSize3"; + public const string KeyBoxSize3TolPlus = "BoxSize3TolPlus"; + public const string KeyBoxSize3TolMinus = "BoxSize3TolMinus"; + public const string KeyBoxFilletRadiusMax = "BoxFilletRadiusMax"; // 方体未注圆角 + public const string KeyBoxRoundHeadFilletRadiusMax = "BoxRoundHeadFilletRadiusMax"; // 方体圆头处圆角 + public const string KeyBoxSize1Prime = "BoxSize1Prime"; // 方体零件尺寸1 + public const string KeyBoxSize2Prime = "BoxSize2Prime"; // 方体零件尺寸2 + public const string KeyBoxSize3Prime = "BoxSize3Prime"; // 方体零件尺寸3 #endregion @@ -176,8 +184,8 @@ namespace CadParamPluging.Cad private static ExpectedDrawingSize CalculateBlockSize(ParamBag bag) { - var size1 = bag.GetDoubleOrNull(KeySize1) ?? bag.GetDoubleOrNull("Size123") ?? 0; - var size2 = bag.GetDoubleOrNull(KeySize2) ?? size1; + var size1 = bag.GetDoubleOrNull(KeyBoxSize1) ?? 0; + var size2 = bag.GetDoubleOrNull(KeyBoxSize2) ?? size1; var extraMargin = 40; return new ExpectedDrawingSize @@ -595,12 +603,72 @@ namespace CadParamPluging.Cad AddLinearDim(ctx, new Point3d(ox + diameter.Value, oy, 0), new Point3d(ox + diameter.Value, oy + H, 0), new Point3d(ox + diameter.Value + 20, ctx.Center.Y, 0), 90, htDimText); - // 未注圆角 - var unspecifiedFillet = bag.GetDoubleOrNull(KeyUnspecifiedFilletRadiusMax); + // 未注圆角(使用饼盘专用Key) + var unspecifiedFillet = bag.GetDoubleOrNull(KeyDiskFilletRadiusMax); if (unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0) { DrawUnspecifiedFilletNote(ctx, ox, oy + H, R, diameter.Value, unspecifiedFillet.Value); } + + // 零件尺寸(如果有) + var diaPrime = bag.GetDoubleOrNull(KeyDiskDiameterPrime); + var heightPrime = bag.GetDoubleOrNull(KeyDiskHeightPrime); + if (diaPrime.HasValue && diaPrime.Value > 0 && heightPrime.HasValue && heightPrime.Value > 0) + { + DrawDiskPartContour(ctx, ox, oy, diameter.Value, H, diaPrime.Value, heightPrime.Value); + } + } + + private static void DrawDiskPartContour(DrawingContext ctx, double ox, double oy, + double forgingDia, double forgingH, double partDia, double partH) + { + double offsetX = (forgingDia - partDia) / 2.0; + double offsetY = (forgingH - partH) / 2.0; + + var polyPart = new Polyline(); + polyPart.AddVertexAt(0, new Point2d(ox + offsetX, oy + offsetY), 0, 0, 0); + polyPart.AddVertexAt(1, new Point2d(ox + offsetX + partDia, oy + offsetY), 0, 0, 0); + polyPart.AddVertexAt(2, new Point2d(ox + offsetX + partDia, oy + offsetY + partH), 0, 0, 0); + polyPart.AddVertexAt(3, new Point2d(ox + offsetX, oy + offsetY + partH), 0, 0, 0); + polyPart.Closed = true; + polyPart.ColorIndex = 7; + + ctx.Btr.AppendEntity(polyPart); + ctx.Tr.AddNewlyCreatedDBObject(polyPart, true); + + // 填充 + try + { + var hatch = new Hatch(); + hatch.SetDatabaseDefaults(); + hatch.Normal = new Vector3d(0, 0, 1); + hatch.Elevation = 0.0; + + ctx.Btr.AppendEntity(hatch); + ctx.Tr.AddNewlyCreatedDBObject(hatch, true); + + hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31"); + hatch.PatternScale = 0.8; + hatch.PatternAngle = 0; + hatch.Associative = false; + hatch.ColorIndex = 7; + + var ids = new ObjectIdCollection(); + ids.Add(polyPart.ObjectId); + hatch.AppendLoop(HatchLoopTypes.External, ids); + hatch.EvaluateHatch(true); + } + catch { } + + // 零件直径标注 + AddLinearDim(ctx, new Point3d(ox + offsetX, oy + offsetY, 0), + new Point3d(ox + offsetX + partDia, oy + offsetY, 0), + new Point3d(ox + offsetX + partDia / 2, oy + offsetY - 10, 0), 0, $"%%c{partDia}"); + + // 零件高度标注 + AddLinearDim(ctx, new Point3d(ox + offsetX + partDia, oy + offsetY, 0), + new Point3d(ox + offsetX + partDia, oy + offsetY + partH, 0), + new Point3d(ox + offsetX + partDia + 10, oy + offsetY + partH / 2, 0), 90, $"{partH}"); } #endregion @@ -611,6 +679,18 @@ namespace CadParamPluging.Cad { var bag = ctx.Bag; + // 圆轴使用Diameter/Length,方轴使用BoxSize1/2/3 + var isSquareShaft = !string.IsNullOrWhiteSpace(ctx.SpecialCondition) + && ctx.SpecialCondition.IndexOf("方轴", StringComparison.OrdinalIgnoreCase) >= 0; + + if (isSquareShaft) + { + // 方轴使用方体参数绘制 + DrawSquareShaftFeatures(ctx); + return; + } + + // 圆轴绘制 var diameter = bag.GetDoubleOrNull(KeyDiameter); var length = bag.GetDoubleOrNull(KeyLength); @@ -657,46 +737,166 @@ namespace CadParamPluging.Cad AddLinearDim(ctx, new Point3d(ox, oy - R, 0), new Point3d(ox + L, oy - R, 0), new Point3d(ctx.Center.X, oy - R - 20, 0), 0, lenDimText); - // 未注圆角 - var unspecifiedFillet = bag.GetDoubleOrNull(KeyUnspecifiedFilletRadiusMax); + // 未注圆角(使用轴杆专用Key) + var unspecifiedFillet = bag.GetDoubleOrNull(KeyShaftFilletRadiusMax); if (unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0) { DrawUnspecifiedFilletNote(ctx, ox, oy, R, L, unspecifiedFillet.Value); } - // 圆头处圆角(如果有圆头) - if (ctx.HasRoundHead) + // 零件尺寸(如果有) + var diaPrime = bag.GetDoubleOrNull(KeyDiameterPrime); + var lenPrime = bag.GetDoubleOrNull(KeyLengthPrime); + if (diaPrime.HasValue && diaPrime.Value > 0 && lenPrime.HasValue && lenPrime.Value > 0) { - var roundHeadFillet = bag.GetDoubleOrNull(KeyRoundHeadFilletRadiusMax); - if (roundHeadFillet.HasValue && roundHeadFillet.Value > 0) - { - // 绘制圆头 - DrawRoundHeadEnds(ctx, ox, oy, R, L, roundHeadFillet.Value); - } + DrawShaftPartContour(ctx, ox, oy, R, L, diaPrime.Value, lenPrime.Value); } } - private static void DrawRoundHeadEnds(DrawingContext ctx, double ox, double oy, double R, double L, double filletR) + /// + /// 方轴绘制(使用方体参数) + /// + private static void DrawSquareShaftFeatures(DrawingContext ctx) { - // 左端圆头 + var bag = ctx.Bag; + + var size1 = bag.GetDoubleOrNull(KeyBoxSize1); + var size2 = bag.GetDoubleOrNull(KeyBoxSize2); + var size3 = bag.GetDoubleOrNull(KeyBoxSize3); + + if (!size1.HasValue || size1.Value <= 0) return; + + double width = size1.Value; + double height = size2.HasValue && size2.Value > 0 ? size2.Value : size1.Value; + double depth = size3.HasValue && size3.Value > 0 ? size3.Value : 0; + + double ox = ctx.Center.X - width / 2.0; + double oy = ctx.Center.Y - height / 2.0; + + // 绘制正视图(矩形) + var poly = new Polyline(); + poly.AddVertexAt(0, new Point2d(ox, oy), 0, 0, 0); + poly.AddVertexAt(1, new Point2d(ox + width, oy), 0, 0, 0); + poly.AddVertexAt(2, new Point2d(ox + width, oy + height), 0, 0, 0); + poly.AddVertexAt(3, new Point2d(ox, oy + height), 0, 0, 0); + poly.Closed = true; + poly.ColorIndex = 7; + + ctx.Btr.AppendEntity(poly); + ctx.Tr.AddNewlyCreatedDBObject(poly, true); + + // 尺寸1标注 + var tol1Plus = bag.GetDoubleOrNull(KeyBoxSize1TolPlus); + var tol1Minus = bag.GetDoubleOrNull(KeyBoxSize1TolMinus); + var dim1Text = BuildDimensionText($"{width}", tol1Plus, tol1Minus); + AddLinearDim(ctx, new Point3d(ox, oy, 0), new Point3d(ox + width, oy, 0), + new Point3d(ctx.Center.X, oy - 20, 0), 0, dim1Text); + + // 尺寸2标注 + if (size2.HasValue && size2.Value > 0) + { + var tol2Plus = bag.GetDoubleOrNull(KeyBoxSize2TolPlus); + var tol2Minus = bag.GetDoubleOrNull(KeyBoxSize2TolMinus); + var dim2Text = BuildDimensionText($"{height}", tol2Plus, tol2Minus); + AddLinearDim(ctx, new Point3d(ox + width, oy, 0), new Point3d(ox + width, oy + height, 0), + new Point3d(ox + width + 20, ctx.Center.Y, 0), 90, dim2Text); + } + + // 尺寸3标注 + if (depth > 0) + { + var tol3Plus = bag.GetDoubleOrNull(KeyBoxSize3TolPlus); + var tol3Minus = bag.GetDoubleOrNull(KeyBoxSize3TolMinus); + var dim3Text = BuildDimensionText($"深度:{depth}", tol3Plus, tol3Minus); + try + { + var text = new DBText(); + text.TextString = dim3Text; + text.Position = new Point3d(ox + width + 10, oy + height + 10, 0); + text.Height = 5; + text.ColorIndex = 7; + ctx.Btr.AppendEntity(text); + ctx.Tr.AddNewlyCreatedDBObject(text, true); + } + catch { } + } + + // 未注圆角(使用方体专用Key) + var unspecifiedFillet = bag.GetDoubleOrNull(KeyBoxFilletRadiusMax); + if (unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0) + { + try + { + var text = new DBText(); + text.TextString = $"未注圆角半径R≤{unspecifiedFillet.Value}"; + text.Position = new Point3d(ox + width + 10, oy + height + 20, 0); + text.Height = 5; + text.ColorIndex = 7; + ctx.Btr.AppendEntity(text); + ctx.Tr.AddNewlyCreatedDBObject(text, true); + } + catch { } + } + + // 零件尺寸 + var size1Prime = bag.GetDoubleOrNull(KeyBoxSize1Prime); + var size2Prime = bag.GetDoubleOrNull(KeyBoxSize2Prime); + var size3Prime = bag.GetDoubleOrNull(KeyBoxSize3Prime); + if (size1Prime.HasValue && size1Prime.Value > 0) + { + DrawBlockPartContour(ctx, ox, oy, width, height, + size1Prime.Value, size2Prime ?? size1Prime.Value, size3Prime); + } + } + + private static void DrawShaftPartContour(DrawingContext ctx, double ox, double oy, + double R, double L, double partDia, double partLen) + { + double offsetX = (L - partLen) / 2.0; + double Rp = partDia / 2.0; + + var polyPart = new Polyline(); + polyPart.AddVertexAt(0, new Point2d(ox + offsetX, oy - Rp), 0, 0, 0); + polyPart.AddVertexAt(1, new Point2d(ox + offsetX + partLen, oy - Rp), 0, 0, 0); + polyPart.AddVertexAt(2, new Point2d(ox + offsetX + partLen, oy + Rp), 0, 0, 0); + polyPart.AddVertexAt(3, new Point2d(ox + offsetX, oy + Rp), 0, 0, 0); + polyPart.Closed = true; + polyPart.ColorIndex = 7; + + ctx.Btr.AppendEntity(polyPart); + ctx.Tr.AddNewlyCreatedDBObject(polyPart, true); + + // 填充 try { - var arcLeft = new Arc(new Point3d(ox, oy, 0), R, Math.PI / 2, Math.PI * 1.5); - arcLeft.ColorIndex = 7; - ctx.Btr.AppendEntity(arcLeft); - ctx.Tr.AddNewlyCreatedDBObject(arcLeft, true); + var hatch = new Hatch(); + hatch.SetDatabaseDefaults(); + hatch.Normal = new Vector3d(0, 0, 1); + hatch.Elevation = 0.0; + + ctx.Btr.AppendEntity(hatch); + ctx.Tr.AddNewlyCreatedDBObject(hatch, true); + + hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31"); + hatch.PatternScale = 0.8; + hatch.PatternAngle = 0; + hatch.Associative = false; + hatch.ColorIndex = 7; + + var ids = new ObjectIdCollection(); + ids.Add(polyPart.ObjectId); + hatch.AppendLoop(HatchLoopTypes.External, ids); + hatch.EvaluateHatch(true); } catch { } - // 右端圆头 - try - { - var arcRight = new Arc(new Point3d(ox + L, oy, 0), R, -Math.PI / 2, Math.PI / 2); - arcRight.ColorIndex = 7; - ctx.Btr.AppendEntity(arcRight); - ctx.Tr.AddNewlyCreatedDBObject(arcRight, true); - } - catch { } + // 零件直径标注 + AddLinearDim(ctx, new Point3d(ox + offsetX, oy + Rp, 0), new Point3d(ox + offsetX, oy - Rp, 0), + new Point3d(ox + offsetX - 10, oy, 0), 90, $"%%c{partDia}"); + + // 零件长度标注 + AddLinearDim(ctx, new Point3d(ox + offsetX, oy - Rp, 0), new Point3d(ox + offsetX + partLen, oy - Rp, 0), + new Point3d(ox + offsetX + partLen / 2, oy - Rp - 10, 0), 0, $"{partLen}"); } #endregion @@ -707,10 +907,10 @@ namespace CadParamPluging.Cad { var bag = ctx.Bag; - // 尝试读取Size1/2/3,如果没有则尝试通用尺寸 - var size1 = bag.GetDoubleOrNull(KeySize1) ?? bag.GetDoubleOrNull("Size123"); - var size2 = bag.GetDoubleOrNull(KeySize2); - var size3 = bag.GetDoubleOrNull(KeySize3); + // 使用方体专用参数 + var size1 = bag.GetDoubleOrNull(KeyBoxSize1); + var size2 = bag.GetDoubleOrNull(KeyBoxSize2); + var size3 = bag.GetDoubleOrNull(KeyBoxSize3); if (!size1.HasValue || size1.Value <= 0) return; @@ -734,28 +934,28 @@ namespace CadParamPluging.Cad ctx.Btr.AppendEntity(poly); ctx.Tr.AddNewlyCreatedDBObject(poly, true); - // 宽度标注 (Size1) - var tol1Plus = bag.GetDoubleOrNull(KeySize1TolPlus); - var tol1Minus = bag.GetDoubleOrNull(KeySize1TolMinus); + // 宽度标注 (BoxSize1) + var tol1Plus = bag.GetDoubleOrNull(KeyBoxSize1TolPlus); + var tol1Minus = bag.GetDoubleOrNull(KeyBoxSize1TolMinus); var dim1Text = BuildDimensionText($"{width}", tol1Plus, tol1Minus); AddLinearDim(ctx, new Point3d(ox, oy, 0), new Point3d(ox + width, oy, 0), new Point3d(ctx.Center.X, oy - 20, 0), 0, dim1Text); - // 高度标注 (Size2) + // 高度标注 (BoxSize2) if (size2.HasValue && size2.Value > 0) { - var tol2Plus = bag.GetDoubleOrNull(KeySize2TolPlus); - var tol2Minus = bag.GetDoubleOrNull(KeySize2TolMinus); + var tol2Plus = bag.GetDoubleOrNull(KeyBoxSize2TolPlus); + var tol2Minus = bag.GetDoubleOrNull(KeyBoxSize2TolMinus); var dim2Text = BuildDimensionText($"{height}", tol2Plus, tol2Minus); AddLinearDim(ctx, new Point3d(ox + width, oy, 0), new Point3d(ox + width, oy + height, 0), new Point3d(ox + width + 20, ctx.Center.Y, 0), 90, dim2Text); } - // 深度标注 (Size3) - 如果有的话,以文字形式标注 + // 深度标注 (BoxSize3) - 如果有的话,以文字形式标注 if (depth > 0) { - var tol3Plus = bag.GetDoubleOrNull(KeySize3TolPlus); - var tol3Minus = bag.GetDoubleOrNull(KeySize3TolMinus); + var tol3Plus = bag.GetDoubleOrNull(KeyBoxSize3TolPlus); + var tol3Minus = bag.GetDoubleOrNull(KeyBoxSize3TolMinus); var dim3Text = BuildDimensionText($"深度:{depth}", tol3Plus, tol3Minus); try { @@ -770,8 +970,8 @@ namespace CadParamPluging.Cad catch { } } - // 未注圆角 - var unspecifiedFillet = bag.GetDoubleOrNull(KeyUnspecifiedFilletRadiusMax); + // 未注圆角(使用方体专用Key) + var unspecifiedFillet = bag.GetDoubleOrNull(KeyBoxFilletRadiusMax); if (unspecifiedFillet.HasValue && unspecifiedFillet.Value > 0) { try @@ -787,18 +987,109 @@ namespace CadParamPluging.Cad catch { } } - // 圆头处圆角 + // 有圆头时,绘制两端半圆形圆头 if (ctx.HasRoundHead) { - var roundHeadFillet = bag.GetDoubleOrNull(KeyRoundHeadFilletRadiusMax); - if (roundHeadFillet.HasValue && roundHeadFillet.Value > 0) + double R = height / 2.0; // 圆头半径 = 高度/2(示意性) + double centerY = oy + height / 2.0; + + // 左端圆头(半圆) + try { - // 绘制四角圆角 - DrawFilletArc(ctx, ox + roundHeadFillet.Value, oy + roundHeadFillet.Value, roundHeadFillet.Value, Math.PI, Math.PI * 1.5); - DrawFilletArc(ctx, ox + width - roundHeadFillet.Value, oy + roundHeadFillet.Value, roundHeadFillet.Value, Math.PI * 1.5, Math.PI * 2); - DrawFilletArc(ctx, ox + width - roundHeadFillet.Value, oy + height - roundHeadFillet.Value, roundHeadFillet.Value, 0, Math.PI / 2); - DrawFilletArc(ctx, ox + roundHeadFillet.Value, oy + height - roundHeadFillet.Value, roundHeadFillet.Value, Math.PI / 2, Math.PI); + var arcLeft = new Arc(new Point3d(ox, centerY, 0), R, Math.PI / 2, Math.PI * 1.5); + arcLeft.ColorIndex = 7; + ctx.Btr.AppendEntity(arcLeft); + ctx.Tr.AddNewlyCreatedDBObject(arcLeft, true); } + catch { } + + // 右端圆头(半圆) + try + { + var arcRight = new Arc(new Point3d(ox + width, centerY, 0), R, -Math.PI / 2, Math.PI / 2); + arcRight.ColorIndex = 7; + ctx.Btr.AppendEntity(arcRight); + ctx.Tr.AddNewlyCreatedDBObject(arcRight, true); + } + catch { } + } + + // 零件尺寸 + var size1Prime = bag.GetDoubleOrNull(KeyBoxSize1Prime); + var size2Prime = bag.GetDoubleOrNull(KeyBoxSize2Prime); + var size3Prime = bag.GetDoubleOrNull(KeyBoxSize3Prime); + if (size1Prime.HasValue && size1Prime.Value > 0) + { + DrawBlockPartContour(ctx, ox, oy, width, height, + size1Prime.Value, size2Prime ?? size1Prime.Value, size3Prime); + } + } + + private static void DrawBlockPartContour(DrawingContext ctx, double ox, double oy, + double forgingW, double forgingH, double partW, double partH, double? partD) + { + double offsetX = (forgingW - partW) / 2.0; + double offsetY = (forgingH - partH) / 2.0; + + var polyPart = new Polyline(); + polyPart.AddVertexAt(0, new Point2d(ox + offsetX, oy + offsetY), 0, 0, 0); + polyPart.AddVertexAt(1, new Point2d(ox + offsetX + partW, oy + offsetY), 0, 0, 0); + polyPart.AddVertexAt(2, new Point2d(ox + offsetX + partW, oy + offsetY + partH), 0, 0, 0); + polyPart.AddVertexAt(3, new Point2d(ox + offsetX, oy + offsetY + partH), 0, 0, 0); + polyPart.Closed = true; + polyPart.ColorIndex = 7; + + ctx.Btr.AppendEntity(polyPart); + ctx.Tr.AddNewlyCreatedDBObject(polyPart, true); + + // 填充 + try + { + var hatch = new Hatch(); + hatch.SetDatabaseDefaults(); + hatch.Normal = new Vector3d(0, 0, 1); + hatch.Elevation = 0.0; + + ctx.Btr.AppendEntity(hatch); + ctx.Tr.AddNewlyCreatedDBObject(hatch, true); + + hatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31"); + hatch.PatternScale = 0.8; + hatch.PatternAngle = 0; + hatch.Associative = false; + hatch.ColorIndex = 7; + + var ids = new ObjectIdCollection(); + ids.Add(polyPart.ObjectId); + hatch.AppendLoop(HatchLoopTypes.External, ids); + hatch.EvaluateHatch(true); + } + catch { } + + // 零件尺寸1标注 + AddLinearDim(ctx, new Point3d(ox + offsetX, oy + offsetY, 0), + new Point3d(ox + offsetX + partW, oy + offsetY, 0), + new Point3d(ox + offsetX + partW / 2, oy + offsetY - 10, 0), 0, $"{partW}"); + + // 零件尺寸2标注 + AddLinearDim(ctx, new Point3d(ox + offsetX + partW, oy + offsetY, 0), + new Point3d(ox + offsetX + partW, oy + offsetY + partH, 0), + new Point3d(ox + offsetX + partW + 10, oy + offsetY + partH / 2, 0), 90, $"{partH}"); + + // 零件尺寸3标注(如果有) + if (partD.HasValue && partD.Value > 0) + { + try + { + var text = new DBText(); + text.TextString = $"深度:{partD.Value}"; + text.Position = new Point3d(ox + offsetX + partW + 10, oy + offsetY + partH + 5, 0); + text.Height = 4; + text.ColorIndex = 7; + ctx.Btr.AppendEntity(text); + ctx.Tr.AddNewlyCreatedDBObject(text, true); + } + catch { } } } @@ -891,12 +1182,17 @@ namespace CadParamPluging.Cad KeyMinWallThickness, // 饼盘参数 KeyDiskDiameter, KeyDiskHeight, + KeyDiskDiameterPrime, KeyDiskHeightPrime, // 轴杆参数 KeyDiameter, KeyLength, - // 方形参数 - KeySize1, KeySize2, KeySize3, "Size123", + KeyDiameterPrime, KeyLengthPrime, + // 方体参数 + KeyBoxSize1, KeyBoxSize2, KeyBoxSize3, + KeyBoxSize1Prime, KeyBoxSize2Prime, KeyBoxSize3Prime, // 圆角参数 - KeyUnspecifiedFilletRadiusMax, KeyInnerRadiusMax, KeyRoundHeadFilletRadiusMax + KeyUnspecifiedFilletRadiusMax, KeyInnerRadiusMax, + KeyDiskFilletRadiusMax, KeyShaftFilletRadiusMax, + KeyBoxFilletRadiusMax, KeyBoxRoundHeadFilletRadiusMax }; // 公差参数也需要缩放 @@ -909,9 +1205,9 @@ namespace CadParamPluging.Cad KeyDiskHeightTolPlus, KeyDiskHeightTolMinus, KeyDiameterTolPlus, KeyDiameterTolMinus, KeyLengthTolPlus, KeyLengthTolMinus, - KeySize1TolPlus, KeySize1TolMinus, - KeySize2TolPlus, KeySize2TolMinus, - KeySize3TolPlus, KeySize3TolMinus + KeyBoxSize1TolPlus, KeyBoxSize1TolMinus, + KeyBoxSize2TolPlus, KeyBoxSize2TolMinus, + KeyBoxSize3TolPlus, KeyBoxSize3TolMinus }; foreach (var key in original.GetKeys()) diff --git a/Common/ParamCatalog.cs b/Common/ParamCatalog.cs index f2b3934..5315dad 100644 --- a/Common/ParamCatalog.cs +++ b/Common/ParamCatalog.cs @@ -443,18 +443,7 @@ namespace CadParamPluging.Common Order = 610, Group = "尺寸-环形" }, - new ParamDefinition - { - Key = "RoundHeadFilletRadiusMax", - Label = "圆头处圆角半径≤", - Type = ParamValueType.Enum, - Required = false, - DefaultValue = "", - EnumOptions = new List { "8", "10" }, - Hint = "仅方体有圆头结构:下拉列表(8/10),可手动编辑", - Order = 620, - Group = "尺寸-环形" - }, + new ParamDefinition { Key = "OuterDiameter1Prime", @@ -556,40 +545,197 @@ namespace CadParamPluging.Common Order = 750, Group = "尺寸-轴杆" }, - - // --- Dimensions: generic multi-size --- new ParamDefinition { - Key = "Size123", - Label = "尺寸1/尺寸2/尺寸3", - Type = ParamValueType.String, + Key = "ShaftFilletRadiusMax", + Label = "未注圆角半径R≤(轴杆)", + Type = ParamValueType.Enum, + Required = false, + DefaultValue = "", + EnumOptions = new List { "6", "5", "4" }, + Hint = "下拉列表(6/5/4),可手动编辑", + Order = 760, + Group = "尺寸-轴杆" + }, + new ParamDefinition + { + Key = "DiameterPrime", + Label = "直径Φ'", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "零件尺寸,手动编辑", + Order = 770, + Group = "尺寸-轴杆" + }, + new ParamDefinition + { + Key = "LengthPrime", + Label = "长度L'", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "零件尺寸,手动编辑", + Order = 780, + Group = "尺寸-轴杆" + }, + + // --- Dimensions: box (方体) --- + new ParamDefinition + { + Key = "BoxSize1", + Label = "尺寸1", + Type = ParamValueType.Double, Required = false, DefaultValue = "", Hint = "手动编辑", Order = 800, - Group = "尺寸-通用" + Group = "尺寸-方体" }, new ParamDefinition { - Key = "SizeTolPlusA123", - Label = "尺寸上差a1/a2/a3", - Type = ParamValueType.String, + Key = "BoxSize1TolPlus", + Label = "尺寸1上差a1", + Type = ParamValueType.Double, Required = false, DefaultValue = "", Hint = "下拉列表(+2~+7),可手动编辑", - Order = 810, - Group = "尺寸-通用" + Order = 801, + Group = "尺寸-方体" }, new ParamDefinition { - Key = "SizeTolMinusB123", - Label = "尺寸下差b1/b2/b3", - Type = ParamValueType.String, + Key = "BoxSize1TolMinus", + Label = "尺寸1下差b1", + Type = ParamValueType.Double, Required = false, DefaultValue = "", Hint = "下拉列表(-2~-7),可手动编辑", + Order = 802, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize2", + Label = "尺寸2", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "手动编辑", + Order = 810, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize2TolPlus", + Label = "尺寸2上差a2", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "下拉列表(+2~+7),可手动编辑", + Order = 811, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize2TolMinus", + Label = "尺寸2下差b2", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "下拉列表(-2~-7),可手动编辑", + Order = 812, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize3", + Label = "尺寸3", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "手动编辑", Order = 820, - Group = "尺寸-通用" + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize3TolPlus", + Label = "尺寸3上差a3", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "下拉列表(+2~+7),可手动编辑", + Order = 821, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize3TolMinus", + Label = "尺寸3下差b3", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "下拉列表(-2~-7),可手动编辑", + Order = 822, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize1Prime", + Label = "尺寸1'", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "零件尺寸,手动编辑", + Order = 830, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize2Prime", + Label = "尺寸2'", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "零件尺寸,手动编辑", + Order = 831, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxSize3Prime", + Label = "尺寸3'", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "零件尺寸,手动编辑", + Order = 832, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxFilletRadiusMax", + Label = "未注圆角半径R≤(方体)", + Type = ParamValueType.Enum, + Required = false, + DefaultValue = "", + EnumOptions = new List { "6", "5", "4" }, + Hint = "下拉列表(6/5/4),可手动编辑", + Order = 840, + Group = "尺寸-方体" + }, + new ParamDefinition + { + Key = "BoxRoundHeadFilletRadiusMax", + Label = "圆头处圆角半径≤(方体)", + Type = ParamValueType.Enum, + Required = false, + DefaultValue = "", + EnumOptions = new List { "8", "10" }, + Hint = "仅方体有圆头结构:下拉列表(8/10),可手动编辑", + Order = 841, + Group = "尺寸-方体" }, // --- Dimensions: disk (饼盘) --- @@ -658,6 +804,40 @@ namespace CadParamPluging.Common Hint = "下拉列表(-2~-7),可手动编辑", Order = 950, Group = "尺寸-饼盘" + }, + new ParamDefinition + { + Key = "DiskFilletRadiusMax", + Label = "未注圆角半径R≤(饼盘)", + Type = ParamValueType.Enum, + Required = false, + DefaultValue = "", + EnumOptions = new List { "6", "5", "4" }, + Hint = "下拉列表(6/5/4),可手动编辑", + Order = 960, + Group = "尺寸-饼盘" + }, + new ParamDefinition + { + Key = "DiskDiameterPrime", + Label = "直径Φ'(饼盘)", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "零件尺寸,手动编辑", + Order = 970, + Group = "尺寸-饼盘" + }, + new ParamDefinition + { + Key = "DiskHeightPrime", + Label = "高度H'(饼盘)", + Type = ParamValueType.Double, + Required = false, + DefaultValue = "", + Hint = "零件尺寸,手动编辑", + Order = 980, + Group = "尺寸-饼盘" } } };