Refine break lines and half-outline drawing

This commit is contained in:
sladro 2026-04-27 16:38:27 +08:00
parent 69ef76e16e
commit 06740d4eef
6 changed files with 299 additions and 37 deletions

View File

@ -5,6 +5,8 @@ namespace CadParamPluging.Cad
{ {
internal sealed class DrawingStyleManager internal sealed class DrawingStyleManager
{ {
private const string BreakLineLinetypeName = "BREAK_THREE_SHORT_V2";
public enum Role public enum Role
{ {
OutlineBold, OutlineBold,
@ -40,6 +42,10 @@ namespace CadParamPluging.Cad
try { ent.Layer = spec.LayerName; } catch { } try { ent.Layer = spec.LayerName; } catch { }
try { ent.ColorIndex = 256; } catch { } // ByLayer try { ent.ColorIndex = 256; } catch { } // ByLayer
try { ent.Linetype = "ByLayer"; } catch { } try { ent.Linetype = "ByLayer"; } catch { }
if (role == Role.BreakLine)
{
try { ent.Linetype = BreakLineLinetypeName; } catch { }
}
try { ent.LineWeight = LineWeight.ByLayer; } catch { } try { ent.LineWeight = LineWeight.ByLayer; } catch { }
} }
@ -60,7 +66,7 @@ namespace CadParamPluging.Cad
case Role.PartContour: case Role.PartContour:
return new LayerSpec { LayerName = "双点划线", DefaultLinetypeName = "PHANTOM", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 }; return new LayerSpec { LayerName = "双点划线", DefaultLinetypeName = "PHANTOM", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 };
case Role.BreakLine: case Role.BreakLine:
return new LayerSpec { LayerName = "截断线", DefaultLinetypeName = "PHANTOM", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 }; return new LayerSpec { LayerName = "截断线", DefaultLinetypeName = BreakLineLinetypeName, DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 };
case Role.Centerline: case Role.Centerline:
return new LayerSpec { LayerName = "中心线", DefaultLinetypeName = "CENTER", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 }; return new LayerSpec { LayerName = "中心线", DefaultLinetypeName = "CENTER", DefaultLineWeight = LineWeight.LineWeight015, DefaultColorIndex = 7 };
case Role.Hidden: case Role.Hidden:
@ -171,6 +177,29 @@ namespace CadParamPluging.Cad
return; return;
} }
if (linetypeName == BreakLineLinetypeName)
{
lt.UpgradeOpen();
var record = new LinetypeTableRecord
{
Name = BreakLineLinetypeName,
AsciiDescription = "Long dash, three short dashes",
PatternLength = 1.68,
NumDashes = 8
};
record.SetDashLengthAt(0, 0.6);
record.SetDashLengthAt(1, -0.18);
record.SetDashLengthAt(2, 0.12);
record.SetDashLengthAt(3, -0.18);
record.SetDashLengthAt(4, 0.12);
record.SetDashLengthAt(5, -0.18);
record.SetDashLengthAt(6, 0.12);
record.SetDashLengthAt(7, -0.18);
lt.Add(record);
_tr.AddNewlyCreatedDBObject(record, true);
return;
}
try try
{ {
_db.LoadLineTypeFile(linetypeName, "acad.lin"); _db.LoadLineTypeFile(linetypeName, "acad.lin");

View File

@ -182,7 +182,7 @@ namespace CadParamPluging.Cad
{ {
FeatureDrivenDrawer.DrawRingSectionContourWithFillet(ctx, xInnerRight.Value, ox + visualOuterR, oy, H, unspecifiedFillet.Value); FeatureDrivenDrawer.DrawRingSectionContourWithFillet(ctx, xInnerRight.Value, ox + visualOuterR, oy, H, unspecifiedFillet.Value);
FeatureDrivenDrawer.DrawHoleHorizontalLines(ctx, ox, xInnerRight.Value, oy, H, unspecifiedFillet.Value); DrawHoleHorizontalLinesWithLeftExtension(ctx, ox, xInnerRight.Value, oy, H, unspecifiedFillet.Value);
var sectionWidth = (ox + visualOuterR) - (xInnerRight.Value); var sectionWidth = (ox + visualOuterR) - (xInnerRight.Value);
var maxR = Math.Min(sectionWidth * 0.5, H * 0.5); var maxR = Math.Min(sectionWidth * 0.5, H * 0.5);
@ -450,16 +450,7 @@ namespace CadParamPluging.Cad
} }
} }
var poly = new Polyline(); DrawOpenHalfOutlineWithLeftExtension(ctx, ox, oy, radius, height);
poly.AddVertexAt(0, new Point2d(ox, oy), 0, 0, 0);
poly.AddVertexAt(1, new Point2d(ox + radius, oy), 0, 0, 0);
poly.AddVertexAt(2, new Point2d(ox + radius, oy + height), 0, 0, 0);
poly.AddVertexAt(3, new Point2d(ox, oy + height), 0, 0, 0);
poly.Closed = false;
ctx.Style?.Apply(poly, DrawingStyleManager.Role.OutlineBold);
ctx.Btr.AppendEntity(poly);
ctx.Tr.AddNewlyCreatedDBObject(poly, true);
} }
private static void DrawRingSymmetryAxis(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double height) private static void DrawRingSymmetryAxis(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double height)
@ -491,13 +482,72 @@ namespace CadParamPluging.Cad
var line1 = new Line(new Point3d(ox, y0, 0), new Point3d(ox, y1, 0)); var line1 = new Line(new Point3d(ox, y0, 0), new Point3d(ox, y1, 0));
ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine);
line1.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line1); ctx.Btr.AppendEntity(line1);
ctx.Tr.AddNewlyCreatedDBObject(line1, true); ctx.Tr.AddNewlyCreatedDBObject(line1, true);
var line2 = new Line(new Point3d(ox - lineSpacing, y0, 0), new Point3d(ox - lineSpacing, y1, 0)); var line2 = new Line(new Point3d(ox - lineSpacing, y0, 0), new Point3d(ox - lineSpacing, y1, 0));
ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine);
line2.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line2); ctx.Btr.AppendEntity(line2);
ctx.Tr.AddNewlyCreatedDBObject(line2, true); ctx.Tr.AddNewlyCreatedDBObject(line2, true);
}
private static void DrawHoleHorizontalLinesWithLeftExtension(FeatureDrivenDrawer.DrawingContext ctx, double xAxis, double xSectionLeft, double yBottom, double height, double filletR)
{
const double leftExtension = 10.0;
const double lineSpacing = 3.0;
var yTop = yBottom + height;
var maxR = Math.Min(100.0, height * 0.5);
var r = Math.Min(filletR, maxR);
var xTarget = r > 0.01 ? xSectionLeft + r : xSectionLeft;
var xLeft = xAxis - leftExtension;
DrawOutlineLine(ctx, xLeft, yBottom, xAxis - lineSpacing, yBottom);
DrawOutlineLine(ctx, xAxis, yBottom, xTarget, yBottom);
DrawOutlineLine(ctx, xLeft, yTop, xAxis - lineSpacing, yTop);
DrawOutlineLine(ctx, xAxis, yTop, xTarget, yTop);
DrawLeftCutCenterLine(ctx, xLeft, yBottom, height);
}
private static void DrawOpenHalfOutlineWithLeftExtension(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double radius, double height)
{
const double leftExtension = 10.0;
const double lineSpacing = 3.0;
var xLeft = ox - leftExtension;
var xBreakLeft = ox - lineSpacing;
var xRight = ox + radius;
var yTop = oy + height;
DrawOutlineLine(ctx, xLeft, oy, xBreakLeft, oy);
DrawOutlineLine(ctx, ox, oy, xRight, oy);
DrawOutlineLine(ctx, xRight, oy, xRight, yTop);
DrawOutlineLine(ctx, xRight, yTop, ox, yTop);
DrawOutlineLine(ctx, xBreakLeft, yTop, xLeft, yTop);
DrawLeftCutCenterLine(ctx, xLeft, oy, height);
}
private static void DrawOutlineLine(FeatureDrivenDrawer.DrawingContext ctx, double x1, double y1, double x2, double y2)
{
var line = new Line(new Point3d(x1, y1, 0), new Point3d(x2, y2, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.OutlineBold);
ctx.Btr.AppendEntity(line);
ctx.Tr.AddNewlyCreatedDBObject(line, true);
}
private static void DrawLeftCutCenterLine(FeatureDrivenDrawer.DrawingContext ctx, double x, double yBottom, double height)
{
var yTop = yBottom + height;
var centerLine = new Line(new Point3d(x, yBottom - 5.0, 0), new Point3d(x, yTop + 5.0, 0));
ctx.Style?.Apply(centerLine, DrawingStyleManager.Role.Centerline);
centerLine.LinetypeScale = 8.0;
ctx.Btr.AppendEntity(centerLine);
ctx.Tr.AddNewlyCreatedDBObject(centerLine, true);
} }
private static void DrawOuterDiameterDimensionHalf(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double radius, double height, private static void DrawOuterDiameterDimensionHalf(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double radius, double height,
@ -522,11 +572,13 @@ namespace CadParamPluging.Cad
? baseText + $"\\X(%%c{FeatureDrivenDrawer.FormatDimNumber(diameterPrimeVal.Value)})" ? baseText + $"\\X(%%c{FeatureDrivenDrawer.FormatDimNumber(diameterPrimeVal.Value)})"
: baseText; : baseText;
const double leftExtension = 10.0;
var xLeft = ox - leftExtension;
AddLinearDim( AddLinearDim(
ctx, ctx,
new Point3d(ox, oy, 0), new Point3d(xLeft, oy, 0),
new Point3d(ox + radius, oy, 0), new Point3d(ox + radius, oy, 0),
new Point3d(ox + radius / 2, oy - 25, 0), new Point3d((xLeft + ox + radius) / 2.0, oy - 25, 0),
0, 0,
dimText, dimText,
ApplyHalfSideDimStyle); ApplyHalfSideDimStyle);
@ -565,11 +617,13 @@ namespace CadParamPluging.Cad
double innerRadius = xInnerRight - oxAxis; double innerRadius = xInnerRight - oxAxis;
var dimLineY = yBottom - 10; var dimLineY = yBottom - 10;
const double leftExtension = 10.0;
var xLeft = oxAxis - leftExtension;
AddLinearDim( AddLinearDim(
ctx, ctx,
new Point3d(oxAxis, yBottom, 0), new Point3d(xLeft, yBottom, 0),
new Point3d(xInnerRight, yBottom + offsetY, 0), new Point3d(xInnerRight, yBottom + offsetY, 0),
new Point3d(oxAxis + innerRadius / 2, dimLineY, 0), new Point3d((xLeft + xInnerRight) / 2.0, dimLineY, 0),
0, 0,
dimText, dimText,
ApplyHalfSideDimStyle); ApplyHalfSideDimStyle);

View File

@ -185,7 +185,7 @@ namespace CadParamPluging.Cad
{ {
FeatureDrivenDrawer.DrawRingSectionContourWithFillet(ctx, xInnerRight.Value, ox + visualOuterR, oy, H, unspecifiedFillet.Value); FeatureDrivenDrawer.DrawRingSectionContourWithFillet(ctx, xInnerRight.Value, ox + visualOuterR, oy, H, unspecifiedFillet.Value);
FeatureDrivenDrawer.DrawHoleHorizontalLines(ctx, ox, xInnerRight.Value, oy, H, unspecifiedFillet.Value); DrawHoleHorizontalLinesWithLeftExtension(ctx, ox, xInnerRight.Value, oy, H, unspecifiedFillet.Value);
var sectionWidth = (ox + visualOuterR) - (xInnerRight.Value); var sectionWidth = (ox + visualOuterR) - (xInnerRight.Value);
var maxR = Math.Min(sectionWidth * 0.5, H * 0.5); var maxR = Math.Min(sectionWidth * 0.5, H * 0.5);
@ -341,16 +341,7 @@ namespace CadParamPluging.Cad
} }
} }
var poly = new Polyline(); DrawOpenHalfOutlineWithLeftExtension(ctx, ox, oy, radius, height);
poly.AddVertexAt(0, new Point2d(ox, oy), 0, 0, 0);
poly.AddVertexAt(1, new Point2d(ox + radius, oy), 0, 0, 0);
poly.AddVertexAt(2, new Point2d(ox + radius, oy + height), 0, 0, 0);
poly.AddVertexAt(3, new Point2d(ox, oy + height), 0, 0, 0);
poly.Closed = false;
ctx.Style?.Apply(poly, DrawingStyleManager.Role.OutlineBold);
ctx.Btr.AppendEntity(poly);
ctx.Tr.AddNewlyCreatedDBObject(poly, true);
} }
private static void DrawRingSymmetryAxis(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double height) private static void DrawRingSymmetryAxis(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double height)
@ -382,13 +373,72 @@ namespace CadParamPluging.Cad
var line1 = new Line(new Point3d(ox, y0, 0), new Point3d(ox, y1, 0)); var line1 = new Line(new Point3d(ox, y0, 0), new Point3d(ox, y1, 0));
ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine);
line1.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line1); ctx.Btr.AppendEntity(line1);
ctx.Tr.AddNewlyCreatedDBObject(line1, true); ctx.Tr.AddNewlyCreatedDBObject(line1, true);
var line2 = new Line(new Point3d(ox - lineSpacing, y0, 0), new Point3d(ox - lineSpacing, y1, 0)); var line2 = new Line(new Point3d(ox - lineSpacing, y0, 0), new Point3d(ox - lineSpacing, y1, 0));
ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine);
line2.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line2); ctx.Btr.AppendEntity(line2);
ctx.Tr.AddNewlyCreatedDBObject(line2, true); ctx.Tr.AddNewlyCreatedDBObject(line2, true);
}
private static void DrawHoleHorizontalLinesWithLeftExtension(FeatureDrivenDrawer.DrawingContext ctx, double xAxis, double xSectionLeft, double yBottom, double height, double filletR)
{
const double leftExtension = 10.0;
const double lineSpacing = 3.0;
var yTop = yBottom + height;
var maxR = Math.Min(100.0, height * 0.5);
var r = Math.Min(filletR, maxR);
var xTarget = r > 0.01 ? xSectionLeft + r : xSectionLeft;
var xLeft = xAxis - leftExtension;
DrawOutlineLine(ctx, xLeft, yBottom, xAxis - lineSpacing, yBottom);
DrawOutlineLine(ctx, xAxis, yBottom, xTarget, yBottom);
DrawOutlineLine(ctx, xLeft, yTop, xAxis - lineSpacing, yTop);
DrawOutlineLine(ctx, xAxis, yTop, xTarget, yTop);
DrawLeftCutCenterLine(ctx, xLeft, yBottom, height);
}
private static void DrawOpenHalfOutlineWithLeftExtension(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double radius, double height)
{
const double leftExtension = 10.0;
const double lineSpacing = 3.0;
var xLeft = ox - leftExtension;
var xBreakLeft = ox - lineSpacing;
var xRight = ox + radius;
var yTop = oy + height;
DrawOutlineLine(ctx, xLeft, oy, xBreakLeft, oy);
DrawOutlineLine(ctx, ox, oy, xRight, oy);
DrawOutlineLine(ctx, xRight, oy, xRight, yTop);
DrawOutlineLine(ctx, xRight, yTop, ox, yTop);
DrawOutlineLine(ctx, xBreakLeft, yTop, xLeft, yTop);
DrawLeftCutCenterLine(ctx, xLeft, oy, height);
}
private static void DrawOutlineLine(FeatureDrivenDrawer.DrawingContext ctx, double x1, double y1, double x2, double y2)
{
var line = new Line(new Point3d(x1, y1, 0), new Point3d(x2, y2, 0));
ctx.Style?.Apply(line, DrawingStyleManager.Role.OutlineBold);
ctx.Btr.AppendEntity(line);
ctx.Tr.AddNewlyCreatedDBObject(line, true);
}
private static void DrawLeftCutCenterLine(FeatureDrivenDrawer.DrawingContext ctx, double x, double yBottom, double height)
{
var yTop = yBottom + height;
var centerLine = new Line(new Point3d(x, yBottom - 5.0, 0), new Point3d(x, yTop + 5.0, 0));
ctx.Style?.Apply(centerLine, DrawingStyleManager.Role.Centerline);
centerLine.LinetypeScale = 8.0;
ctx.Btr.AppendEntity(centerLine);
ctx.Tr.AddNewlyCreatedDBObject(centerLine, true);
} }
private static void DrawOuterDiameterDimensionHalf(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double radius, double height, private static void DrawOuterDiameterDimensionHalf(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double radius, double height,
@ -413,11 +463,13 @@ namespace CadParamPluging.Cad
? baseText + $"\\X(%%c{FeatureDrivenDrawer.FormatDimNumber(diameterPrimeVal.Value)})" ? baseText + $"\\X(%%c{FeatureDrivenDrawer.FormatDimNumber(diameterPrimeVal.Value)})"
: baseText; : baseText;
const double leftExtension = 10.0;
var xLeft = ox - leftExtension;
AddLinearDim( AddLinearDim(
ctx, ctx,
new Point3d(ox, oy, 0), new Point3d(xLeft, oy, 0),
new Point3d(ox + radius, oy, 0), new Point3d(ox + radius, oy, 0),
new Point3d(ox + radius / 2, oy - 25, 0), new Point3d((xLeft + ox + radius) / 2.0, oy - 25, 0),
0, 0,
dimText, dimText,
ApplyHalfSideDimStyle); ApplyHalfSideDimStyle);
@ -456,11 +508,13 @@ namespace CadParamPluging.Cad
double innerRadius = xInnerRight - oxAxis; double innerRadius = xInnerRight - oxAxis;
var dimLineY = yBottom - 10; var dimLineY = yBottom - 10;
const double leftExtension = 10.0;
var xLeft = oxAxis - leftExtension;
AddLinearDim( AddLinearDim(
ctx, ctx,
new Point3d(oxAxis, yBottom, 0), new Point3d(xLeft, yBottom, 0),
new Point3d(xInnerRight, yBottom + offsetY, 0), new Point3d(xInnerRight, yBottom + offsetY, 0),
new Point3d(oxAxis + innerRadius / 2, dimLineY, 0), new Point3d((xLeft + xInnerRight) / 2.0, dimLineY, 0),
0, 0,
dimText, dimText,
ApplyHalfSideDimStyle); ApplyHalfSideDimStyle);

View File

@ -79,7 +79,7 @@ namespace CadParamPluging.Cad
// 判断是否需要断线 // 判断是否需要断线
bool needBreakLines = originalW > 150; bool needBreakLines = originalW > 150;
const double lineSpacing = 3.5; const double lineSpacing = 3.0;
// 计算平滑相切数据模型 // 计算平滑相切数据模型
double arcHeight = H / 5.0; double arcHeight = H / 5.0;
@ -506,7 +506,7 @@ namespace CadParamPluging.Cad
/// </summary> /// </summary>
private static void DrawBreakLines(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double width, double height) private static void DrawBreakLines(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double width, double height)
{ {
const double lineSpacing = 3.5; const double lineSpacing = 3.0;
const double extend = 5.0; const double extend = 5.0;
double xBreak = ox + width / 4.0; double xBreak = ox + width / 4.0;
@ -516,13 +516,16 @@ namespace CadParamPluging.Cad
var line1 = new Line(new Point3d(xBreak, y0, 0), new Point3d(xBreak, y1, 0)); var line1 = new Line(new Point3d(xBreak, y0, 0), new Point3d(xBreak, y1, 0));
ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine);
line1.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line1); ctx.Btr.AppendEntity(line1);
ctx.Tr.AddNewlyCreatedDBObject(line1, true); ctx.Tr.AddNewlyCreatedDBObject(line1, true);
var line2 = new Line(new Point3d(xBreak + lineSpacing, y0, 0), new Point3d(xBreak + lineSpacing, y1, 0)); var line2 = new Line(new Point3d(xBreak + lineSpacing, y0, 0), new Point3d(xBreak + lineSpacing, y1, 0));
ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine);
line2.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line2); ctx.Btr.AppendEntity(line2);
ctx.Tr.AddNewlyCreatedDBObject(line2, true); ctx.Tr.AddNewlyCreatedDBObject(line2, true);
} }
// Legacy box-drawing method replaced. // Legacy box-drawing method replaced.

View File

@ -81,7 +81,7 @@ namespace CadParamPluging.Cad
// 判断是否需要断线 // 判断是否需要断线
bool needBreakLines = originalS1 > 150; bool needBreakLines = originalS1 > 150;
const double lineSpacing = 3.5; const double lineSpacing = 3.0;
// 1. Draw Main View - 如果需要断线,则绘制带缺口的轮廓 // 1. Draw Main View - 如果需要断线,则绘制带缺口的轮廓
double xBreak = ox + S1 / 4.0; double xBreak = ox + S1 / 4.0;
@ -269,7 +269,7 @@ namespace CadParamPluging.Cad
/// </summary> /// </summary>
private static void DrawBreakLines(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double width, double height) private static void DrawBreakLines(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double width, double height)
{ {
const double lineSpacing = 3.5; const double lineSpacing = 3.0;
const double extend = 5.0; const double extend = 5.0;
double xBreak = ox + width / 4.0; double xBreak = ox + width / 4.0;
@ -279,13 +279,16 @@ namespace CadParamPluging.Cad
var line1 = new Line(new Point3d(xBreak, y0, 0), new Point3d(xBreak, y1, 0)); var line1 = new Line(new Point3d(xBreak, y0, 0), new Point3d(xBreak, y1, 0));
ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line1, DrawingStyleManager.Role.BreakLine);
line1.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line1); ctx.Btr.AppendEntity(line1);
ctx.Tr.AddNewlyCreatedDBObject(line1, true); ctx.Tr.AddNewlyCreatedDBObject(line1, true);
var line2 = new Line(new Point3d(xBreak + lineSpacing, y0, 0), new Point3d(xBreak + lineSpacing, y1, 0)); var line2 = new Line(new Point3d(xBreak + lineSpacing, y0, 0), new Point3d(xBreak + lineSpacing, y1, 0));
ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine); ctx.Style?.Apply(line2, DrawingStyleManager.Role.BreakLine);
line2.LinetypeScale = 5.0;
ctx.Btr.AppendEntity(line2); ctx.Btr.AppendEntity(line2);
ctx.Tr.AddNewlyCreatedDBObject(line2, true); ctx.Tr.AddNewlyCreatedDBObject(line2, true);
} }
private static void DrawShaftRoundHeadUnifiedOutline(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double W, double H, double w, double r, double xf_left, double xf_right, double fx_L_tangTop, double fy_L_tangTop, double fx_L_tangBotX, double fy_L_tangBot, double fx_R_tangTop, double fy_R_tangTop, double fx_R_tangBotX, double fy_R_tangBot, bool needBreakLines, double xBreak, double breakWidth, double sectionOx, double sectionW) private static void DrawShaftRoundHeadUnifiedOutline(FeatureDrivenDrawer.DrawingContext ctx, double ox, double oy, double W, double H, double w, double r, double xf_left, double xf_right, double fx_L_tangTop, double fy_L_tangTop, double fx_L_tangBotX, double fy_L_tangBot, double fx_R_tangTop, double fy_R_tangTop, double fx_R_tangBotX, double fy_R_tangBot, bool needBreakLines, double xBreak, double breakWidth, double sectionOx, double sectionW)
@ -691,5 +694,3 @@ namespace CadParamPluging.Cad
} }
} }
} }

View File

@ -0,0 +1,121 @@
using System;
using System.IO;
public static class RingMachinedRollingBreakLineStyleTests
{
public static int Main()
{
try
{
BreakLinesUseReferenceStyle(3.0, "Cad", "RingMachinedRollingDrawer.cs");
BreakLinesUseReferenceStyle(3.0, "Cad", "RingRawRollingDrawer.cs");
BreakLinesUseReferenceStyle(3.0, "Cad", "ShaftRawFreeForgeRoundShaftDrawer.cs");
BreakLinesUseReferenceStyle(3.0, "Cad", "ShaftRawFreeForgeSquareShaftDrawer.cs");
RingRollingHasLeftCutExtension("Cad", "RingMachinedRollingDrawer.cs");
RingRollingHasLeftCutExtension("Cad", "RingRawRollingDrawer.cs");
RingRollingHorizontalLinesBreakAtCut("Cad", "RingMachinedRollingDrawer.cs");
RingRollingHorizontalLinesBreakAtCut("Cad", "RingRawRollingDrawer.cs");
RingRollingBottomDimensionsStartAtLeftExtension("Cad", "RingMachinedRollingDrawer.cs");
RingRollingBottomDimensionsStartAtLeftExtension("Cad", "RingRawRollingDrawer.cs");
BreakLineStyleUsesThreeShortDashLinetype();
Console.WriteLine("Break-line style tests passed.");
return 0;
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
return 1;
}
}
private static void BreakLinesUseReferenceStyle(double expectedSpacing, params string[] pathParts)
{
var sourcePath = Path.Combine(pathParts);
var source = File.ReadAllText(sourcePath);
var first = source.IndexOf("line1.LinetypeScale = 5.0;", StringComparison.Ordinal);
var second = source.IndexOf("line2.LinetypeScale = 5.0;", StringComparison.Ordinal);
if (first < 0 || second < 0)
{
throw new InvalidOperationException(sourcePath + ": both break lines must explicitly use linetype scale 5.0.");
}
if (source.Contains("line3.LinetypeScale = 5.0;"))
{
throw new InvalidOperationException(sourcePath + ": break must remain two geometric lines; do not add a third line.");
}
var spacingText = "const double lineSpacing = " + expectedSpacing.ToString("0.0", System.Globalization.CultureInfo.InvariantCulture) + ";";
if (!source.Contains(spacingText))
{
throw new InvalidOperationException(sourcePath + ": break-line spacing must be " + expectedSpacing.ToString("0.0", System.Globalization.CultureInfo.InvariantCulture) + ".");
}
}
private static void RingRollingHasLeftCutExtension(params string[] pathParts)
{
var sourcePath = Path.Combine(pathParts);
var source = File.ReadAllText(sourcePath);
if (!source.Contains("const double leftExtension = 10.0;"))
{
throw new InvalidOperationException(sourcePath + ": left cut horizontal lines must extend left by 10.");
}
if (!source.Contains("DrawingStyleManager.Role.Centerline") || !source.Contains("centerLine.LinetypeScale = 8.0;"))
{
throw new InvalidOperationException(sourcePath + ": left cut must add a centerline with linetype scale 8.0.");
}
}
private static void RingRollingHorizontalLinesBreakAtCut(params string[] pathParts)
{
var sourcePath = Path.Combine(pathParts);
var source = File.ReadAllText(sourcePath);
if (!source.Contains("DrawOutlineLine(ctx, xLeft, oy, xBreakLeft, oy);") ||
!source.Contains("DrawOutlineLine(ctx, ox, oy, xRight, oy);") ||
!source.Contains("DrawOutlineLine(ctx, xRight, yTop, ox, yTop);") ||
!source.Contains("DrawOutlineLine(ctx, xBreakLeft, yTop, xLeft, yTop);"))
{
throw new InvalidOperationException(sourcePath + ": ordinary outline must leave a gap between the two break lines.");
}
if (!source.Contains("DrawOutlineLine(ctx, xLeft, yBottom, xAxis - lineSpacing, yBottom);") ||
!source.Contains("DrawOutlineLine(ctx, xAxis, yBottom, xTarget, yBottom);") ||
!source.Contains("DrawOutlineLine(ctx, xLeft, yTop, xAxis - lineSpacing, yTop);") ||
!source.Contains("DrawOutlineLine(ctx, xAxis, yTop, xTarget, yTop);"))
{
throw new InvalidOperationException(sourcePath + ": fillet horizontal lines must leave a gap between the two break lines.");
}
}
private static void BreakLineStyleUsesThreeShortDashLinetype()
{
var sourcePath = Path.Combine("Cad", "DrawingStyleManager.cs");
var source = File.ReadAllText(sourcePath);
if (!source.Contains("BreakLineLinetypeName = \"BREAK_THREE_SHORT_V2\"") ||
!source.Contains("DefaultLinetypeName = BreakLineLinetypeName") ||
!source.Contains("ent.Linetype = BreakLineLinetypeName") ||
!source.Contains("NumDashes = 8") ||
!source.Contains("record.SetDashLengthAt(7, -0.18);"))
{
throw new InvalidOperationException(sourcePath + ": BreakLine must use the custom long plus three short dashes linetype.");
}
}
private static void RingRollingBottomDimensionsStartAtLeftExtension(params string[] pathParts)
{
var sourcePath = Path.Combine(pathParts);
var source = File.ReadAllText(sourcePath);
if (!source.Contains("new Point3d(xLeft, oy, 0)") ||
!source.Contains("new Point3d((xLeft + ox + radius) / 2.0, oy - 25, 0)") ||
!source.Contains("new Point3d(xLeft, yBottom, 0)") ||
!source.Contains("new Point3d((xLeft + xInnerRight) / 2.0, dimLineY, 0)"))
{
throw new InvalidOperationException(sourcePath + ": bottom dimensions must start from the left extension.");
}
}
}