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."); } } }