feat: add drawing logic for raw free forge square and round shafts

This commit is contained in:
sladro 2026-02-06 08:56:02 +08:00
parent 91c7255a8b
commit b9b46192b4
2 changed files with 56 additions and 16 deletions

View File

@ -81,10 +81,12 @@ namespace CadParamPluging.Cad
bool needBreakLines = originalW > 150; bool needBreakLines = originalW > 150;
const double lineSpacing = 3.5; const double lineSpacing = 3.5;
// 1. 绘制主体轮廓 (矩形 + 圆角) - 保持原来的白色边框
double xBreak = ox + W / 4.0;
// 1. 绘制主体轮廓 (矩形 + 圆角) - 保持原来的白色边框 // 1. 绘制主体轮廓 (矩形 + 圆角) - 保持原来的白色边框
if (needBreakLines) if (needBreakLines)
{ {
double xBreak = ox + W / 4.0;
DrawRectWithBreak(ctx, ox, oy, W, H, filletR, xBreak, lineSpacing); DrawRectWithBreak(ctx, ox, oy, W, H, filletR, xBreak, lineSpacing);
} }
else else
@ -98,7 +100,7 @@ namespace CadParamPluging.Cad
DrawEndArcs(ctx, ox, oy, W, H, arcHeight); DrawEndArcs(ctx, ox, oy, W, H, arcHeight);
// 3. 绘制中心线 (横向,在中间位置) // 3. 绘制中心线 (横向,在中间位置)
DrawHorizontalCenterLine(ctx, ctx.Center.Y, ox, ox + W); DrawHorizontalCenterLine(ctx, ctx.Center.Y, ox, ox + W, needBreakLines, xBreak, lineSpacing);
// 4. 绘制断线 (如果需要) // 4. 绘制断线 (如果需要)
if (needBreakLines) if (needBreakLines)
@ -188,7 +190,7 @@ namespace CadParamPluging.Cad
if (needBreakLines) if (needBreakLines)
{ {
// 使用与锻件相同的断线X坐标和间距 // 使用与锻件相同的断线X坐标和间距
double xBreak = ox + W / 4.0; // double xBreak = ox + W / 4.0; // variable is already declared in outer scope
DrawRectOutlineWithBreak(ctx, pOx, pOy, pW, pH, xBreak, lineSpacing, DrawingStyleManager.Role.PartContour); DrawRectOutlineWithBreak(ctx, pOx, pOy, pW, pH, xBreak, lineSpacing, DrawingStyleManager.Role.PartContour);
} }
else else
@ -295,13 +297,31 @@ namespace CadParamPluging.Cad
} }
} }
private static void DrawHorizontalCenterLine(FeatureDrivenDrawer.DrawingContext ctx, double centerY, double xLeft, double xRight) private static void DrawHorizontalCenterLine(FeatureDrivenDrawer.DrawingContext ctx, double centerY, double xLeft, double xRight, bool hasBreak = false, double xBreak = 0, double breakWidth = 0)
{ {
const double extend = 5.0; const double extend = 5.0;
var line = new Line(new Point3d(xLeft - extend, centerY, 0), new Point3d(xRight + extend, centerY, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.Centerline); if (!hasBreak)
ctx.Btr.AppendEntity(line); {
ctx.Tr.AddNewlyCreatedDBObject(line, true); var line = new Line(new Point3d(xLeft - extend, centerY, 0), new Point3d(xRight + extend, centerY, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.Centerline);
ctx.Btr.AppendEntity(line);
ctx.Tr.AddNewlyCreatedDBObject(line, true);
}
else
{
// Left segment
var line1 = new Line(new Point3d(xLeft - extend, centerY, 0), new Point3d(xBreak, centerY, 0));
ctx.Style?.Apply(line1, DrawingStyleManager.Role.Centerline);
ctx.Btr.AppendEntity(line1);
ctx.Tr.AddNewlyCreatedDBObject(line1, true);
// Right segment
var line2 = new Line(new Point3d(xBreak + breakWidth, centerY, 0), new Point3d(xRight + extend, centerY, 0));
ctx.Style?.Apply(line2, DrawingStyleManager.Role.Centerline);
ctx.Btr.AppendEntity(line2);
ctx.Tr.AddNewlyCreatedDBObject(line2, true);
}
} }
private static ParamBag ScaleParamBag(ParamBag original, double scaleFactor) private static ParamBag ScaleParamBag(ParamBag original, double scaleFactor)

View File

@ -81,10 +81,12 @@ namespace CadParamPluging.Cad
bool needBreakLines = originalS1 > 150; bool needBreakLines = originalS1 > 150;
const double lineSpacing = 3.5; const double lineSpacing = 3.5;
// 1. Draw Main View - 如果需要断线,则绘制带缺口的轮廓
double xBreak = ox + S1 / 4.0;
// 1. Draw Main View - 如果需要断线,则绘制带缺口的轮廓 // 1. Draw Main View - 如果需要断线,则绘制带缺口的轮廓
if (needBreakLines) if (needBreakLines)
{ {
double xBreak = ox + S1 / 4.0;
DrawRectWithBreak(ctx, ox, oy, S1, S2, filletR, xBreak, lineSpacing); DrawRectWithBreak(ctx, ox, oy, S1, S2, filletR, xBreak, lineSpacing);
} }
else else
@ -98,7 +100,7 @@ namespace CadParamPluging.Cad
DrawEndArcs(ctx, ox, oy, S1, S2, arcHeight); DrawEndArcs(ctx, ox, oy, S1, S2, arcHeight);
// 3. 绘制中心线 (横向,在中间位置) // 3. 绘制中心线 (横向,在中间位置)
DrawHorizontalCenterLine(ctx, ctx.Center.Y, ox, ox + S1); DrawHorizontalCenterLine(ctx, ctx.Center.Y, ox, ox + S1, needBreakLines, xBreak, lineSpacing);
// 4. Draw Break Lines if needed // 4. Draw Break Lines if needed
if (needBreakLines) if (needBreakLines)
@ -222,7 +224,7 @@ namespace CadParamPluging.Cad
if (needBreakLines) if (needBreakLines)
{ {
double xBreak = ox + S1 / 4.0; // double xBreak = ox + S1 / 4.0; // variable is already declared in outer scope
DrawRectOutlineWithBreak(ctx, pOx, pOy, pL, pH, xBreak, lineSpacing, DrawingStyleManager.Role.PartContour); DrawRectOutlineWithBreak(ctx, pOx, pOy, pL, pH, xBreak, lineSpacing, DrawingStyleManager.Role.PartContour);
} }
else else
@ -444,13 +446,31 @@ namespace CadParamPluging.Cad
} }
} }
private static void DrawHorizontalCenterLine(FeatureDrivenDrawer.DrawingContext ctx, double centerY, double xLeft, double xRight) private static void DrawHorizontalCenterLine(FeatureDrivenDrawer.DrawingContext ctx, double centerY, double xLeft, double xRight, bool hasBreak = false, double xBreak = 0, double breakWidth = 0)
{ {
const double extend = 5.0; const double extend = 5.0;
var line = new Line(new Point3d(xLeft - extend, centerY, 0), new Point3d(xRight + extend, centerY, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.Centerline); if (!hasBreak)
ctx.Btr.AppendEntity(line); {
ctx.Tr.AddNewlyCreatedDBObject(line, true); var line = new Line(new Point3d(xLeft - extend, centerY, 0), new Point3d(xRight + extend, centerY, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.Centerline);
ctx.Btr.AppendEntity(line);
ctx.Tr.AddNewlyCreatedDBObject(line, true);
}
else
{
// Left segment
var line1 = new Line(new Point3d(xLeft - extend, centerY, 0), new Point3d(xBreak, centerY, 0));
ctx.Style?.Apply(line1, DrawingStyleManager.Role.Centerline);
ctx.Btr.AppendEntity(line1);
ctx.Tr.AddNewlyCreatedDBObject(line1, true);
// Right segment
var line2 = new Line(new Point3d(xBreak + breakWidth, centerY, 0), new Point3d(xRight + extend, centerY, 0));
ctx.Style?.Apply(line2, DrawingStyleManager.Role.Centerline);
ctx.Btr.AppendEntity(line2);
ctx.Tr.AddNewlyCreatedDBObject(line2, true);
}
} }