feat: implement CAD drawing functionality and parameter UI for disk raw free forge parts.

This commit is contained in:
sladro 2026-03-25 10:59:37 +08:00
parent 3b15853821
commit f8ed9ebc2e
3 changed files with 36 additions and 10 deletions

View File

@ -183,7 +183,9 @@ namespace CadParamPluging.Cad
var markingText = bag.GetString(FeatureDrivenDrawer.KeyMarkingContent); var markingText = bag.GetString(FeatureDrivenDrawer.KeyMarkingContent);
if (!string.IsNullOrWhiteSpace(markingText)) if (!string.IsNullOrWhiteSpace(markingText))
{ {
double xTarget = ctx.Center.X; double flatHalfWidth = (diameter.Value / 2.0) - r;
double offset = Math.Min(15.0, flatHalfWidth * 0.8);
double xTarget = ctx.Center.X - offset;
double yTarget = oy + H; double yTarget = oy + H;
FeatureDrivenDrawer.DrawSpecialHBLeaderToTop(ctx, xTarget, yTarget, markingText); FeatureDrivenDrawer.DrawSpecialHBLeaderToTop(ctx, xTarget, yTarget, markingText);
} }
@ -192,7 +194,9 @@ namespace CadParamPluging.Cad
var hardnessVal = bag.GetString(FeatureDrivenDrawer.KeyHardness); var hardnessVal = bag.GetString(FeatureDrivenDrawer.KeyHardness);
if (!string.IsNullOrWhiteSpace(hardnessVal) && hardnessVal != "空") if (!string.IsNullOrWhiteSpace(hardnessVal) && hardnessVal != "空")
{ {
double xHardness = ctx.Center.X; double flatHalfWidth = (diameter.Value / 2.0) - r;
double offset = Math.Min(15.0, flatHalfWidth * 0.8);
double xHardness = ctx.Center.X + offset;
double yHardness = oy; double yHardness = oy;
FeatureDrivenDrawer.DrawHardnessSymbol(ctx, xHardness, yHardness, hardnessVal); FeatureDrivenDrawer.DrawHardnessSymbol(ctx, xHardness, yHardness, hardnessVal);
} }

View File

@ -2905,26 +2905,40 @@ namespace CadParamPluging.Cad
poly.AddVertexAt(2, new Point2d(p3.X, p3.Y), 0, 0, 0); poly.AddVertexAt(2, new Point2d(p3.X, p3.Y), 0, 0, 0);
ctx.Style?.Apply(poly, DrawingStyleManager.Role.Dimension); // 使用 Dimension 角色 ctx.Style?.Apply(poly, DrawingStyleManager.Role.Dimension); // 使用 Dimension 角色
// 用户要求改为绿色 (ColorIndex 3) // 修改为青色 (ColorIndex 4)
poly.ColorIndex = 3; poly.ColorIndex = 4;
ctx.Btr.AppendEntity(poly); ctx.Btr.AppendEntity(poly);
ctx.Tr.AddNewlyCreatedDBObject(poly, true); ctx.Tr.AddNewlyCreatedDBObject(poly, true);
// 2. 文字 (硬度的具体值) // 2. 文字和包裹圆圈
string displayTxt = string.IsNullOrWhiteSpace(hardnessVal) ? "HB" : hardnessVal; string displayTxt = string.IsNullOrWhiteSpace(hardnessVal) ? "HB" : hardnessVal;
// 估算圆圈半径基础半径至少3.5,以保证能舒适包裹"HB";长字符串相应按比例扩大
double radius = Math.Max(3.5, displayTxt.Length * 3.5 * 0.35 + 0.5);
var centerPt = new Point3d(p3.X + radius, p3.Y, 0);
// 绘制文字
var text = new DBText(); var text = new DBText();
text.TextString = displayTxt; text.TextString = displayTxt;
text.Height = 3.5; text.Height = 3.5;
text.ColorIndex = 3; text.ColorIndex = 4; // 青色
text.HorizontalMode = TextHorizontalMode.TextLeft; text.HorizontalMode = TextHorizontalMode.TextCenter;
text.VerticalMode = TextVerticalMode.TextVerticalMid; text.VerticalMode = TextVerticalMode.TextVerticalMid;
var tp = new Point3d(p3.X + 2.0, p3.Y, 0); text.AlignmentPoint = centerPt;
text.AlignmentPoint = tp; text.Position = centerPt; // TextCenter 时通常主要使用 AlignmentPoint
text.Position = tp;
ctx.Btr.AppendEntity(text); ctx.Btr.AppendEntity(text);
ctx.Tr.AddNewlyCreatedDBObject(text, true); ctx.Tr.AddNewlyCreatedDBObject(text, true);
// 绘制外圈圆
var circle = new Circle();
circle.Center = centerPt;
circle.Radius = radius;
circle.ColorIndex = 4; // 青色
ctx.Btr.AppendEntity(circle);
ctx.Tr.AddNewlyCreatedDBObject(circle, true);
} }
catch catch
{ {

View File

@ -857,6 +857,14 @@ namespace CadParamPluging.UI
{ {
display = "有扩孔"; display = "有扩孔";
} }
else if (item == "车加工")
{
display = "粗加工";
}
else if (item == "毛料态")
{
display = "非粗加工";
}
dropDownItems.Add(new DropdownItem { Display = display, Value = item }); dropDownItems.Add(new DropdownItem { Display = display, Value = item });
} }
cb.Items.AddRange(dropDownItems.ToArray()); cb.Items.AddRange(dropDownItems.ToArray());