121 lines
4.8 KiB
C#
121 lines
4.8 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
public static class HardnessSymbolArrowTests
|
|
{
|
|
public static int Main()
|
|
{
|
|
try
|
|
{
|
|
AnnotationArrowsUseDimensionArrowSize();
|
|
Console.WriteLine("Annotation arrow size tests passed.");
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine(ex.Message);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private static void AnnotationArrowsUseDimensionArrowSize()
|
|
{
|
|
var sourcePath = Path.Combine("Cad", "FeatureDrivenDrawer.cs");
|
|
var source = File.ReadAllText(sourcePath);
|
|
|
|
if (!source.Contains("public const double DimensionArrowSize = 2.5;"))
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": dimension arrow size must be controlled by one shared 2.5 variable.");
|
|
}
|
|
|
|
if (!source.Contains("TrySetDimProp(dim, \"Dimasz\", DimensionArrowSize);"))
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": dimension Dimasz must use DimensionArrowSize.");
|
|
}
|
|
|
|
var methodStart = source.IndexOf("public static void DrawHardnessSymbol", StringComparison.Ordinal);
|
|
if (methodStart < 0)
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": DrawHardnessSymbol method was not found.");
|
|
}
|
|
|
|
var methodEnd = source.IndexOf("/// <summary>", methodStart, StringComparison.Ordinal);
|
|
if (methodEnd < 0)
|
|
{
|
|
methodEnd = source.Length;
|
|
}
|
|
|
|
var method = source.Substring(methodStart, methodEnd - methodStart);
|
|
if (!method.Contains("var leader = new Leader()") ||
|
|
!method.Contains("ctx.Style?.Apply(leader, DrawingStyleManager.Role.Dimension)") ||
|
|
!method.Contains("DrawLeaderArrowHead(ctx, p1, p2, 4)") ||
|
|
method.Contains("double arrowLength = 5.0") ||
|
|
method.Contains("double arrowWidth = 1.5"))
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": hardness symbol arrow must use the shared dimension arrow size.");
|
|
}
|
|
|
|
RequireMethodUsesSharedArrow(source, sourcePath, "public static void DrawSpecialInnerHoleLeader");
|
|
RequireMethodUsesSharedArrow(source, sourcePath, "public static void DrawSpecialHBLeaderToTop");
|
|
RequireFileMethodUsesSharedArrow(
|
|
Path.Combine("Cad", "BlockRawFreeForgeNoRoundHeadDrawer.cs"),
|
|
"private static void DrawSpecialHBLeaderToTop",
|
|
"FeatureDrivenDrawer.DrawLeaderArrowHead(ctx, p1, p2, 7)");
|
|
RequireFileMethodUsesSharedArrow(
|
|
Path.Combine("Cad", "BlockRawFreeForgeRoundHeadDrawer.cs"),
|
|
"private static void DrawSpecialHBLeaderToTop",
|
|
"FeatureDrivenDrawer.DrawLeaderArrowHead(ctx, p1, p2, 7)");
|
|
RequireFileMethodUsesSharedArrow(
|
|
Path.Combine("Cad", "RingMachinedRollingDrawer.cs"),
|
|
"private static void DrawSpecialInnerHoleLeader",
|
|
"FeatureDrivenDrawer.DrawLeaderArrowHead(ctx, p1, p2, 7)");
|
|
}
|
|
|
|
private static void RequireMethodUsesSharedArrow(string source, string sourcePath, string signature)
|
|
{
|
|
var methodStart = source.IndexOf(signature, StringComparison.Ordinal);
|
|
if (methodStart < 0)
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": " + signature + " method was not found.");
|
|
}
|
|
|
|
var methodEnd = source.IndexOf("public static void", methodStart + signature.Length, StringComparison.Ordinal);
|
|
if (methodEnd < 0)
|
|
{
|
|
methodEnd = source.IndexOf("private static void", methodStart + signature.Length, StringComparison.Ordinal);
|
|
}
|
|
if (methodEnd < 0)
|
|
{
|
|
methodEnd = source.Length;
|
|
}
|
|
|
|
var method = source.Substring(methodStart, methodEnd - methodStart);
|
|
if (!method.Contains("DrawLeaderArrowHead(ctx, p1, p2, 7)"))
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": " + signature + " must draw its arrow with DimensionArrowSize.");
|
|
}
|
|
}
|
|
|
|
private static void RequireFileMethodUsesSharedArrow(string sourcePath, string signature, string expectedCall)
|
|
{
|
|
var source = File.ReadAllText(sourcePath);
|
|
var methodStart = source.IndexOf(signature, StringComparison.Ordinal);
|
|
if (methodStart < 0)
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": " + signature + " method was not found.");
|
|
}
|
|
|
|
var methodEnd = source.IndexOf("private static void", methodStart + signature.Length, StringComparison.Ordinal);
|
|
if (methodEnd < 0)
|
|
{
|
|
methodEnd = source.Length;
|
|
}
|
|
|
|
var method = source.Substring(methodStart, methodEnd - methodStart);
|
|
if (!method.Contains(expectedCall))
|
|
{
|
|
throw new InvalidOperationException(sourcePath + ": " + signature + " must draw its arrow with DimensionArrowSize.");
|
|
}
|
|
}
|
|
}
|