diff --git a/Cad/ShaftRawFreeForgeRoundShaftDrawer.cs b/Cad/ShaftRawFreeForgeRoundShaftDrawer.cs index 9faf608..fcf7753 100644 --- a/Cad/ShaftRawFreeForgeRoundShaftDrawer.cs +++ b/Cad/ShaftRawFreeForgeRoundShaftDrawer.cs @@ -81,10 +81,12 @@ namespace CadParamPluging.Cad bool needBreakLines = originalW > 150; const double lineSpacing = 3.5; + // 1. 绘制主体轮廓 (矩形 + 圆角) - 保持原来的白色边框 + double xBreak = ox + W / 4.0; + // 1. 绘制主体轮廓 (矩形 + 圆角) - 保持原来的白色边框 if (needBreakLines) { - double xBreak = ox + W / 4.0; DrawRectWithBreak(ctx, ox, oy, W, H, filletR, xBreak, lineSpacing); } else @@ -98,7 +100,7 @@ namespace CadParamPluging.Cad DrawEndArcs(ctx, ox, oy, W, H, arcHeight); // 3. 绘制中心线 (横向,在中间位置) - DrawHorizontalCenterLine(ctx, ctx.Center.Y, ox, ox + W); + DrawHorizontalCenterLine(ctx, ctx.Center.Y, ox, ox + W, needBreakLines, xBreak, lineSpacing); // 4. 绘制断线 (如果需要) if (needBreakLines) @@ -188,7 +190,7 @@ namespace CadParamPluging.Cad if (needBreakLines) { // 使用与锻件相同的断线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); } 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; - 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); + + if (!hasBreak) + { + 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) diff --git a/Cad/ShaftRawFreeForgeSquareShaftDrawer.cs b/Cad/ShaftRawFreeForgeSquareShaftDrawer.cs index b914214..7eb2b8f 100644 --- a/Cad/ShaftRawFreeForgeSquareShaftDrawer.cs +++ b/Cad/ShaftRawFreeForgeSquareShaftDrawer.cs @@ -81,10 +81,12 @@ namespace CadParamPluging.Cad bool needBreakLines = originalS1 > 150; const double lineSpacing = 3.5; + // 1. Draw Main View - 如果需要断线,则绘制带缺口的轮廓 + double xBreak = ox + S1 / 4.0; + // 1. Draw Main View - 如果需要断线,则绘制带缺口的轮廓 if (needBreakLines) { - double xBreak = ox + S1 / 4.0; DrawRectWithBreak(ctx, ox, oy, S1, S2, filletR, xBreak, lineSpacing); } else @@ -98,7 +100,7 @@ namespace CadParamPluging.Cad DrawEndArcs(ctx, ox, oy, S1, S2, arcHeight); // 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 if (needBreakLines) @@ -222,7 +224,7 @@ namespace CadParamPluging.Cad 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); } 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; - 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); + + if (!hasBreak) + { + 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); + } }