File size: 49,140 Bytes
5154c4e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 | from __future__ import annotations
import base64
import csv
import hashlib
import json
import math
import os
import re
import stat
import subprocess
import sys
import tempfile
import zipfile
import xml.etree.ElementTree as ET
from collections import Counter
from pathlib import Path, PurePosixPath
TARGET = Path("/home/user/Desktop")
STEP = TARGET / "complex_pockets.step"
CSV_FILE = TARGET / "tool_candidates.csv"
FCSTD = TARGET / "task-19.FCStd"
NC = TARGET / "task-19.nc"
FREECADCMD = Path("/usr/bin/freecadcmd")
EXPECTED_CSV_SHA256 = "1fe9ef157b2642a50dd0140e50acb6f889f226fff1b9b54078eb5f3ff698c366"
EXPECTED_STEP_SHA256 = "a013a4fe398f51898129934d04c3024f4c01b9c48abf50a1f526c91e7845775e"
EXPECTED_VERSION = ("0", "21", "2", "33771 (Git)")
EXPECTED_COMMIT = "b9bfa5c5507506e4515816414cd27f4851d00489"
EXPECTED_TOOLS = {
1: ("end mill", 16.0, 7000.0, 500.0, 4),
2: ("drill", 14.0, 7000.0, 500.0, 4),
3: ("drill", 12.0, 7000.0, 500.0, 4),
4: ("end mill", 10.0, 7000.0, 500.0, 4),
5: ("end mill", 8.0, 7000.0, 500.0, 4),
}
NUMBER = r"[+-]?(?:\d+(?:\.\d*)?|\.\d+)"
WORD_RE = re.compile(rf"([A-Z])\s*({NUMBER})", re.ASCII)
ALLOWED_ADDRESSES = {
"N", "G", "M", "T", "H", "S", "F", "X", "Y", "Z", "I", "J", "R", "P", "Q"
}
ALLOWED_G = {0, 1, 2, 3, 17, 21, 40, 43, 49, 54, 80, 81, 82, 83, 90, 94, 98, 99}
ALLOWED_M = {2, 3, 5, 6, 8, 9, 30}
G_MODAL_GROUPS = (
{0, 1, 2, 3, 80, 81, 82, 83},
{17},
{21},
{40},
{43, 49},
{54},
{90},
{94},
{98, 99},
)
REQUIRED_PROXIES = Counter(
{
("Path.Main.Job", "ObjectJob"): 1,
("Path.Base.SetupSheet", "SetupSheet"): 1,
("Path.Main.Stock", "StockFromBase"): 1,
("draftobjects.clone", "Clone"): 1,
("Path.Tool.Controller", "ToolController"): 5,
("Path.Tool.Bit", "ToolBit"): 5,
("Path.Op.PocketShape", "ObjectPocket"): 5,
("Path.Op.Drilling", "ObjectDrilling"): 2,
("Path.Op.Profile", "ObjectProfile"): 1,
}
)
POCKET_NC_SPECS = (
(-48.0, 18.0, 18.0, -4.0, 1),
(-24.0, 18.0, 16.0, -5.0, 4),
(0.0, 18.0, 14.0, -6.0, 4),
(24.0, 18.0, 12.0, -7.0, 4),
(48.0, 18.0, 10.0, -8.0, 5),
)
EXPECTED_HOLES = {
2: {(x, 27.0) for x in (-50.0, -30.0, -10.0, 10.0, 30.0, 50.0)},
3: {(x, -27.0) for x in (-50.0, -30.0, -10.0, 10.0, 30.0, 50.0)},
}
def fail(message):
print("task-19 evaluator: " + message, file=sys.stderr)
return False
def close(left, right, tolerance=1e-6):
try:
a, b = float(left), float(right)
except (TypeError, ValueError):
return False
return math.isfinite(a) and math.isfinite(b) and abs(a - b) <= tolerance
def regular_file(path, minimum, maximum):
try:
info = path.lstat()
except OSError:
return False
return (
stat.S_ISREG(info.st_mode)
and not path.is_symlink()
and minimum <= info.st_size <= maximum
)
def sha256(path):
digest = hashlib.sha256()
with path.open("rb") as stream:
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def normalized_text_sha256(path):
data = path.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
return hashlib.sha256(data).hexdigest()
def freeze_file(source, target, minimum, maximum):
flags = os.O_RDONLY | os.O_CLOEXEC | os.O_NOFOLLOW
try:
descriptor = os.open(source, flags)
try:
before = os.fstat(descriptor)
if not stat.S_ISREG(before.st_mode) or not minimum <= before.st_size <= maximum:
return False
chunks = []
remaining = maximum + 1
while remaining:
chunk = os.read(descriptor, min(1024 * 1024, remaining))
if not chunk:
break
chunks.append(chunk)
remaining -= len(chunk)
after = os.fstat(descriptor)
finally:
os.close(descriptor)
stable = (
before.st_dev,
before.st_ino,
before.st_size,
before.st_mtime_ns,
before.st_ctime_ns,
) == (
after.st_dev,
after.st_ino,
after.st_size,
after.st_mtime_ns,
after.st_ctime_ns,
)
data = b"".join(chunks)
if not stable or len(data) != before.st_size:
return False
target.write_bytes(data)
target.chmod(0o600)
return True
except OSError:
return False
def validate_csv(path):
if not regular_file(path, 100, 10_000) or normalized_text_sha256(path) != EXPECTED_CSV_SHA256:
return False
try:
with path.open("r", encoding="utf-8", newline="") as stream:
reader = csv.DictReader(stream)
if reader.fieldnames != [
"tool_number", "type", "diameter", "spindle", "feed", "operation_count"
]:
return False
rows = list(reader)
except (OSError, UnicodeError, csv.Error):
return False
if len(rows) != 5:
return False
found = {}
try:
for row in rows:
if set(row) != set(reader.fieldnames) or any(value is None for value in row.values()):
return False
number = int(row["tool_number"])
if number in found:
return False
found[number] = (
row["type"].strip().lower(),
float(row["diameter"]),
float(row["spindle"]),
float(row["feed"]),
int(row["operation_count"]),
)
except (TypeError, ValueError):
return False
return found == EXPECTED_TOOLS
def allowed_property_file(value):
if value in {"", "/home/user/Desktop/task-19.nc"}:
return True
pure = PurePosixPath(value)
return (
pure.is_absolute()
and ".." not in pure.parts
and pure.suffix.lower() in {".fcstd", ".fctb"}
and (
value.startswith("/usr/share/freecad/Mod/Path/Tools/")
or value.startswith("/usr/lib/freecad/Mod/Path/Tools/")
)
)
def validate_archive(path):
if not regular_file(path, 20_000, 20_000_000):
return False
try:
with zipfile.ZipFile(path) as archive:
names = archive.namelist()
if "Document.xml" not in names or len(names) != len(set(names)) or len(names) > 250:
return False
total = 0
for entry in archive.infolist():
pure = PurePosixPath(entry.filename)
mode = entry.external_attr >> 16
if (
not entry.filename
or "\\" in entry.filename
or pure.is_absolute()
or ".." in pure.parts
or entry.flag_bits & 1
or stat.S_ISLNK(mode)
or entry.file_size > 20_000_000
or (entry.compress_size == 0 and entry.file_size > 0)
or (entry.compress_size and entry.file_size / entry.compress_size > 400)
or pure.suffix.lower()
in {".py", ".pyc", ".pyo", ".sh", ".so", ".dll", ".dylib", ".exe"}
):
return False
total += entry.file_size
if total > 80_000_000:
return False
root = ET.fromstring(archive.read("Document.xml"))
proxies = Counter()
for element in root.iter("Python"):
module = element.attrib.get("module")
class_name = element.attrib.get("class")
encoded = element.attrib.get("encoded")
value = element.attrib.get("value")
if encoded != "yes" or not isinstance(value, str) or len(value) > 100_000:
return False
payload = json.loads(base64.b64decode(value, validate=True).decode("utf-8"))
if (module, class_name) == ("draftobjects.clone", "Clone"):
if not isinstance(payload, str):
return False
elif payload is not None and not isinstance(payload, dict):
return False
proxies[(module, class_name)] += 1
if proxies != REQUIRED_PROXIES:
return False
for prop in root.iter("Property"):
if prop.attrib.get("type") != "App::PropertyFile":
continue
values = [child.attrib.get("value") for child in prop if child.tag == "String"]
if len(values) != 1 or not allowed_property_file(values[0]):
return False
for element in root.iter():
if element.tag not in {"Part", "Path"}:
continue
member = element.attrib.get("file")
if (
not member
or member not in names
or PurePosixPath(member).suffix.lower() not in {".brp", ".nc"}
):
return False
return True
except (
OSError,
UnicodeError,
ValueError,
zipfile.BadZipFile,
ET.ParseError,
json.JSONDecodeError,
):
return False
def strip_comments(text):
output = []
in_comment = False
for line in text.replace("\r\n", "\n").replace("\r", "\n").split("\n"):
code = []
for char in line:
if in_comment:
if char == "(":
return None
if char == ")":
in_comment = False
elif char == "(":
in_comment = True
elif char == ")":
return None
elif char == ";":
break
else:
code.append(char)
output.append("".join(code))
return None if in_comment else "\n".join(output)
def integral(value):
rounded = round(value)
return int(rounded) if math.isfinite(value) and abs(value - rounded) <= 1e-9 else None
def parse_nc(path):
try:
executable = strip_comments(path.read_text(encoding="utf-8"))
except (OSError, UnicodeError):
return None
if executable is None:
return None
blocks = []
for raw in executable.splitlines():
line = raw.strip().upper()
if not line or line == "%":
continue
words = []
cursor = 0
for match in WORD_RE.finditer(line):
if line[cursor : match.start()].strip():
return None
value = float(match.group(2))
if not math.isfinite(value):
return None
words.append((match.group(1), value))
cursor = match.end()
if line[cursor:].strip() or not words:
return None
if any(letter not in ALLOWED_ADDRESSES for letter, _ in words):
return None
if any(
sum(letter == address for letter, _ in words) > 1
for address in ALLOWED_ADDRESSES - {"G", "M"}
):
return None
blocks.append(words)
return blocks or None
def validate_nc(path):
if not regular_file(path, 5_000, 2_000_000):
return False
blocks = parse_nc(path)
if blocks is None:
return False
state = {
"units": None,
"absolute": False,
"plane": None,
"wcs": None,
"motion": None,
"cycle": None,
"cycle_z": None,
"cycle_r": None,
"retract": None,
"tool": None,
"changed": False,
"speed": None,
"feed": None,
"spindle": False,
"X": None,
"Y": None,
"Z": None,
}
ended = False
saw_m5 = False
changed_tools = []
spindle_tools = set()
cutting_tools = set()
cycles = []
cuts = {number: [] for number in EXPECTED_TOOLS}
for index, block in enumerate(blocks):
words = dict(block)
gs = [integral(value) for letter, value in block if letter == "G"]
ms = [integral(value) for letter, value in block if letter == "M"]
if ended:
return False
if any(code is None or code not in ALLOWED_G for code in gs):
return False
if any(code is None or code not in ALLOWED_M for code in ms):
return False
if any(sum(code in group for code in gs) > 1 for group in G_MODAL_GROUPS):
return False
terminators = [code for code in ms if code in {2, 30}]
if (
len(ms) != len(set(ms))
or len(terminators) > 1
or (terminators and len(ms) != 1)
):
return False
if 21 in gs:
state["units"] = "mm"
if 17 in gs:
state["plane"] = "XY"
if 90 in gs:
state["absolute"] = True
if 54 in gs:
state["wcs"] = 54
if 98 in gs:
state["retract"] = 98
if 99 in gs:
state["retract"] = 99
for code in gs:
if code in {0, 1, 2, 3}:
state["motion"] = code
if code in {81, 82, 83}:
state["cycle"] = code
elif code == 80:
state["cycle"] = None
state["cycle_z"] = None
state["cycle_r"] = None
if "T" in words:
tool = integral(words["T"])
if tool not in EXPECTED_TOOLS:
return False
if tool != state["tool"]:
state["changed"] = False
state["tool"] = tool
if "H" in words and integral(words["H"]) != state["tool"]:
return False
if "S" in words:
if not close(words["S"], 7000.0):
return False
state["speed"] = words["S"]
if "F" in words:
if state["units"] != "mm" or not close(words["F"], 500.0, 0.01):
return False
state["feed"] = words["F"]
if 5 in ms:
state["spindle"] = False
saw_m5 = True
if 6 in ms:
if (
len(ms) != 1
or not saw_m5
or state["spindle"]
or state["tool"] not in EXPECTED_TOOLS
or state["cycle"] is not None
):
return False
state["changed"] = True
changed_tools.append(state["tool"])
saw_m5 = False
if 3 in ms:
if (
state["tool"] not in EXPECTED_TOOLS
or not state["changed"]
or state["speed"] is None
):
return False
state["spindle"] = True
spindle_tools.add(state["tool"])
before = (state["X"], state["Y"], state["Z"])
for axis in ("X", "Y", "Z"):
if axis in words:
state[axis] = words[axis]
explicit_motion = next((code for code in gs if code in {0, 1, 2, 3}), None)
explicit_cycle = next((code for code in gs if code in {81, 82, 83}), None)
has_axis = any(axis in words for axis in ("X", "Y", "Z"))
if explicit_motion == 0 and ("X" in words or "Y" in words):
if state["Z"] is None or state["Z"] < 2.0 - 1e-6:
return False
if explicit_cycle is not None:
if "Z" not in words or "R" not in words:
return False
state["cycle_z"] = words["Z"]
state["cycle_r"] = words["R"]
if explicit_cycle == 82 and ("P" not in words or words["P"] < 0):
return False
if explicit_cycle == 83 and ("Q" not in words or words["Q"] <= 0):
return False
cycle_visit = (
state["cycle"] in {81, 82, 83}
and state["tool"] in {2, 3}
and (explicit_cycle is not None or "X" in words or "Y" in words)
and explicit_motion is None
and 80 not in gs
)
if cycle_visit:
if (
not state["spindle"]
or not state["changed"]
or state["feed"] is None
or state["units"] != "mm"
or not state["absolute"]
or state["plane"] != "XY"
or state["wcs"] != 54
or state["X"] is None
or state["Y"] is None
or state["cycle_z"] is None
or state["cycle_r"] is None
or state["retract"] != 98
or state["cycle_z"] > -19.0 + 1e-6
or not 1.9 <= state["cycle_r"] <= 5.1
):
return False
cycles.append(
(
state["tool"],
round(state["X"], 4),
round(state["Y"], 4),
round(state["cycle_z"], 4),
)
)
cutting_tools.add(state["tool"])
state["Z"] = before[2] if state["retract"] == 98 else state["cycle_r"]
elif has_axis and state["motion"] in {1, 2, 3} and explicit_motion != 0:
if state["cycle"] is not None:
return False
if (
state["tool"] not in {1, 4, 5}
or not state["spindle"]
or not state["changed"]
or state["feed"] is None
or state["units"] != "mm"
or not state["absolute"]
or state["plane"] != "XY"
or state["wcs"] != 54
or any(state[axis] is None for axis in ("X", "Y", "Z"))
or not (-68.1 <= state["X"] <= 68.1)
or not (-48.1 <= state["Y"] <= 48.1)
or not (-18.001 <= state["Z"] <= 5.001)
):
return False
if state["motion"] in {2, 3} and not all(letter in words for letter in ("I", "J")):
return False
cuts[state["tool"]].append(
(state["X"], state["Y"], state["Z"], state["motion"], before)
)
cutting_tools.add(state["tool"])
if 2 in ms or 30 in ms:
if index != len(blocks) - 1 or state["spindle"] or state["cycle"] is not None:
return False
ended = True
if not ended or set(changed_tools) != set(EXPECTED_TOOLS):
return False
if spindle_tools != set(EXPECTED_TOOLS) or cutting_tools != set(EXPECTED_TOOLS):
return False
if len(cycles) != 12:
return False
for tool in (2, 3):
tool_cycles = [item for item in cycles if item[0] == tool]
if len(tool_cycles) != 6:
return False
if {(item[1], item[2]) for item in tool_cycles} != EXPECTED_HOLES[tool]:
return False
depths = {item[3] for item in tool_cycles}
if len(depths) != 1 or not -25.0 <= next(iter(depths)) <= -19.0:
return False
for cx, length, width, floor, tool in POCKET_NC_SPECS:
hits = [
point
for point in cuts[tool]
if close(point[2], floor, 0.01)
and cx - length / 2.0 - 0.05 <= point[0] <= cx + length / 2.0 + 0.05
and -width / 2.0 - 0.05 <= point[1] <= width / 2.0 + 0.05
]
if len(hits) < 2:
return False
profile = [point for point in cuts[1] if close(point[2], -18.0, 0.01)]
if len(profile) < 8:
return False
px = [point[0] for point in profile]
py = [point[1] for point in profile]
if not (
close(min(px), -68.0, 0.05)
and close(max(px), 68.0, 0.05)
and close(min(py), -48.0, 0.05)
and close(max(py), 48.0, 0.05)
):
return False
return True
CHILD_SOURCE = r'''
import builtins
import json
import math
import os
import pathlib
import re
import sys
import traceback
from collections import Counter
builtins.pythonopen = open
import FreeCAD as App
import Import
import Part
import Path.Post.Command as PathPostCommand
import Path.Tool.Bit as PathToolBit
from Path.Post.Processor import PostProcessor
EXPECTED_VERSION = ("0", "21", "2", "33771 (Git)")
EXPECTED_COMMIT = "b9bfa5c5507506e4515816414cd27f4851d00489"
POCKETS = (
("P1", -48.0, 18.0, 18.0, 8.5, 4.0, 1, 16.0),
("P2", -24.0, 18.0, 16.0, 6.0, 5.0, 4, 10.0),
("P3", 0.0, 18.0, 14.0, 6.0, 6.0, 4, 10.0),
("P4", 24.0, 18.0, 12.0, 5.5, 7.0, 4, 10.0),
("P5", 48.0, 18.0, 10.0, 4.5, 8.0, 5, 8.0),
)
HOLE_X = (-50.0, -30.0, -10.0, 10.0, 30.0, 50.0)
EXPECTED_HOLES = {2: {(x, 27.0) for x in HOLE_X}, 3: {(x, -27.0) for x in HOLE_X}}
CODE_WORD_RE = re.compile(r"([A-Z])\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+))")
def close(a, b, tolerance=1e-6):
try:
left, right = float(a), float(b)
except (TypeError, ValueError):
return False
return math.isfinite(left) and math.isfinite(right) and abs(left - right) <= tolerance
def module(obj):
return getattr(getattr(obj, "Proxy", None).__class__, "__module__", "")
def same_shape(left, right, tolerance=1e-4):
return (
left.isValid()
and right.isValid()
and left.cut(right).Volume <= tolerance
and right.cut(left).Volume <= tolerance
)
def rounded_prism(cx, cy, length, width, radius, zmin, height):
parts = []
if length - 2.0 * radius > 1e-9:
parts.append(
Part.makeBox(
length - 2.0 * radius,
width,
height,
App.Vector(cx - length / 2.0 + radius, cy - width / 2.0, zmin),
)
)
if width - 2.0 * radius > 1e-9:
parts.append(
Part.makeBox(
length,
width - 2.0 * radius,
height,
App.Vector(cx - length / 2.0, cy - width / 2.0 + radius, zmin),
)
)
centers = {
(cx + sx * (length / 2.0 - radius), cy + sy * (width / 2.0 - radius))
for sx in (-1.0, 1.0)
for sy in (-1.0, 1.0)
}
parts.extend(
Part.makeCylinder(radius, height, App.Vector(x, y, zmin))
for x, y in sorted(centers)
)
result = parts[0]
for part in parts[1:]:
result = result.fuse(part)
return result.removeSplitter()
def expected_source_shape():
shape = Part.makeBox(120.0, 80.0, 18.0, App.Vector(-60.0, -40.0, 0.0))
for _, x, length, width, radius, depth, _, _ in POCKETS:
shape = shape.cut(rounded_prism(x, 0.0, length, width, radius, 18.0 - depth, depth))
for x in HOLE_X:
shape = shape.cut(Part.makeCylinder(7.0, 18.0, App.Vector(x, 27.0, 0.0)))
shape = shape.cut(Part.makeCylinder(6.0, 18.0, App.Vector(x, -27.0, 0.0)))
return shape.removeSplitter()
def translated(shape, z):
result = shape.copy()
result.translate(App.Vector(0.0, 0.0, z))
return result
def horizontal_floor(op, model):
try:
base = list(op.Base)
if len(base) != 1 or base[0][0] != model:
return None
names = list(base[0][1])
if len(names) != 1 or not re.fullmatch(r"Face\d+", str(names[0])):
return None
face = getattr(model.Shape, str(names[0]))
if type(face.Surface).__name__ != "Plane":
return None
box = face.BoundBox
if not close(box.ZMin, box.ZMax):
return None
return face
except (AttributeError, TypeError, ValueError):
return None
def rounded_contains(x, y, cx, length, width, radius, shrink=0.0, tolerance=1e-6):
hx = length / 2.0 - shrink
hy = width / 2.0 - shrink
rr = radius - shrink
if hx <= 0.0 or hy <= 0.0 or rr < -tolerance:
return False
rr = max(0.0, rr)
qx = max(abs(x - cx) - max(0.0, hx - rr), 0.0)
qy = max(abs(y) - max(0.0, hy - rr), 0.0)
return qx * qx + qy * qy <= (rr + tolerance) * (rr + tolerance)
def sample_motion(op, spacing=0.35):
position = {"X": None, "Y": None, "Z": None}
samples = []
motions = 0
for command in op.Path.Commands:
name = str(command.Name).upper().replace(" ", "")
before = dict(position)
for axis in position:
if axis in command.Parameters:
position[axis] = float(command.Parameters[axis])
if name not in {"G0", "G1", "G2", "G3"}:
continue
motions += 1
if name == "G0":
if any(axis in command.Parameters for axis in ("X", "Y")):
effective_z = position["Z"]
if effective_z is None or effective_z < 2.0 - 1e-6:
return None
continue
if not all(before[axis] is not None and position[axis] is not None for axis in position):
continue
if name == "G1":
distance = math.sqrt(
sum((position[axis] - before[axis]) ** 2 for axis in ("X", "Y", "Z"))
)
count = max(1, int(math.ceil(distance / spacing)))
for index in range(1, count + 1):
fraction = index / float(count)
samples.append(
(
before["X"] + (position["X"] - before["X"]) * fraction,
before["Y"] + (position["Y"] - before["Y"]) * fraction,
before["Z"] + (position["Z"] - before["Z"]) * fraction,
)
)
continue
if "I" not in command.Parameters or "J" not in command.Parameters:
return None
center_x = before["X"] + float(command.Parameters["I"])
center_y = before["Y"] + float(command.Parameters["J"])
radius = math.hypot(before["X"] - center_x, before["Y"] - center_y)
if radius <= 1e-9:
return None
start = math.atan2(before["Y"] - center_y, before["X"] - center_x)
finish = math.atan2(position["Y"] - center_y, position["X"] - center_x)
if name == "G2":
while finish >= start:
finish -= 2.0 * math.pi
else:
while finish <= start:
finish += 2.0 * math.pi
sweep = finish - start
count = max(4, int(math.ceil(abs(sweep) * radius / spacing)))
for index in range(1, count + 1):
fraction = index / float(count)
angle = start + sweep * fraction
samples.append(
(
center_x + radius * math.cos(angle),
center_y + radius * math.sin(angle),
before["Z"] + (position["Z"] - before["Z"]) * fraction,
)
)
return motions, samples
def validate_pocket_path(op, spec):
_, cx, length, width, radius, depth, _, diameter = spec
result = sample_motion(op)
if result is None:
return False
motions, samples = result
if motions < 5 or not samples:
return False
final_z = -depth
cutting = [point for point in samples if point[2] <= 1e-5]
if not cutting or min(point[2] for point in cutting) < final_z - 1e-4:
return False
tool_radius = diameter / 2.0
if any(
not rounded_contains(
point[0], point[1], cx, length, width, radius, tool_radius, tolerance=0.03
)
for point in cutting
):
return False
floor_samples = [point for point in cutting if close(point[2], final_z, 0.01)]
if len(floor_samples) < 3:
return False
grid = 0.75
x = cx - length / 2.0
targets = []
while x <= cx + length / 2.0 + 1e-9:
y = -width / 2.0
while y <= width / 2.0 + 1e-9:
if rounded_contains(x, y, cx, length, width, radius, tolerance=0.01):
targets.append((x, y))
y += grid
x += grid
reach = tool_radius + 0.85
for target_x, target_y in targets:
if min(math.hypot(target_x - px, target_y - py) for px, py, _ in floor_samples) > reach:
return False
return True
def drilling_cycles(op):
position = {"X": None, "Y": None, "Z": None}
active = False
cycle_z = None
cycle_r = None
records = []
saw_cancel = False
retract = None
for command in op.Path.Commands:
name = str(command.Name).upper().replace(" ", "")
before = dict(position)
for axis in position:
if axis in command.Parameters:
position[axis] = float(command.Parameters[axis])
if name in {"G1", "G2", "G3"}:
return None
if name == "G98":
retract = 98
elif name == "G99":
retract = 99
if name == "G0" and any(axis in command.Parameters for axis in ("X", "Y")):
if position["Z"] is None or position["Z"] < 2.0 - 1e-6:
return None
if name in {"G81", "G82", "G83"}:
active = True
if "Z" in command.Parameters:
cycle_z = float(command.Parameters["Z"])
if "R" in command.Parameters:
cycle_r = float(command.Parameters["R"])
if (
position["X"] is None
or position["Y"] is None
or cycle_z is None
or cycle_r is None
or retract != 98
):
return None
if name == "G82" and ("P" not in command.Parameters or float(command.Parameters["P"]) < 0):
return None
if name == "G83" and ("Q" not in command.Parameters or float(command.Parameters["Q"]) <= 0):
return None
records.append((position["X"], position["Y"], cycle_z, cycle_r))
position["Z"] = before["Z"] if retract == 98 else cycle_r
elif active and name == "G80":
active = False
saw_cancel = True
elif active and name != "G0" and any(
axis in command.Parameters for axis in ("X", "Y")
):
if position["X"] is None or position["Y"] is None or retract != 98:
return None
records.append((position["X"], position["Y"], cycle_z, cycle_r))
position["Z"] = before["Z"] if retract == 98 else cycle_r
elif active and name not in {"G0", "G98", "G99"} and any(
axis in command.Parameters for axis in ("X", "Y", "Z")
):
return None
if active or not saw_cancel:
return None
return records
def validate_profile_path(op):
result = sample_motion(op)
if result is None:
return False
motions, samples = result
if motions < 20 or not samples:
return False
cutting = [point for point in samples if point[2] <= 1e-5]
if not cutting or min(point[2] for point in cutting) < -18.0001:
return False
final = [point for point in cutting if close(point[2], -18.0, 0.01)]
if len(final) < 100:
return False
if any(not (-68.05 <= x <= 68.05 and -48.05 <= y <= 48.05) for x, y, _ in final):
return False
xs = [point[0] for point in final]
ys = [point[1] for point in final]
if not (
close(min(xs), -68.0, 0.05)
and close(max(xs), 68.0, 0.05)
and close(min(ys), -48.0, 0.05)
and close(max(ys), 48.0, 0.05)
):
return False
for target in ((-68.0, 0.0), (68.0, 0.0), (0.0, -48.0), (0.0, 48.0)):
if min(math.hypot(x - target[0], y - target[1]) for x, y, _ in final) > 0.75:
return False
return True
def expected_tool(doc, number, kind, diameter):
attrs = {
"version": 2,
"name": "Evaluator T%d" % number,
"shape": "drill.fcstd" if kind == "drill" else "endmill.fcstd",
"parameter": {
"Diameter": "%g mm" % diameter,
"Length": "60 mm",
},
"attribute": {},
}
if kind == "drill":
attrs["parameter"]["TipAngle"] = "118 deg"
else:
attrs["parameter"]["ShankDiameter"] = "%g mm" % diameter
attrs["parameter"]["CuttingEdgeHeight"] = "24 mm"
return PathToolBit.Factory.CreateFromAttrs(attrs, "EvaluatorTool%d" % number)
def strip_comments(text):
output = []
in_comment = False
for line in text.replace("\r\n", "\n").replace("\r", "\n").split("\n"):
code = []
for char in line:
if in_comment:
if char == "(":
return None
if char == ")":
in_comment = False
elif char == "(":
in_comment = True
elif char == ")":
return None
elif char == ";":
break
else:
code.append(char)
output.append("".join(code))
return None if in_comment else "\n".join(output)
def code_signature(path):
try:
executable = strip_comments(pathlib.Path(path).read_text(encoding="utf-8"))
except (OSError, UnicodeError):
return None
if executable is None:
return None
result = []
for raw in executable.splitlines():
line = raw.strip().upper()
if not line or line == "%":
continue
words = []
cursor = 0
for match in CODE_WORD_RE.finditer(line):
if line[cursor : match.start()].strip():
return None
if match.group(1) != "N":
value = float(match.group(2))
if not math.isfinite(value):
return None
value = 0.0 if abs(value) < 0.0000005 else round(value, 6)
words.append((match.group(1), value))
cursor = match.end()
if line[cursor:].strip() or not words:
return None
if words == [("M", 30.0)]:
words = [("M", 2.0)]
result.append(tuple(words))
return tuple(result)
def validate(step_path, fcstd_path, nc_path, repost_path):
if tuple(App.Version()[:4]) != EXPECTED_VERSION or App.Version()[-1] != EXPECTED_COMMIT:
return False
expected_source = expected_source_shape()
if (
not expected_source.isValid()
or len(expected_source.Solids) != 1
or not close(expected_source.Volume, 137669.0182180575, 1e-4)
):
return False
source_doc = App.newDocument("Task19SourceCheck")
try:
Import.insert(str(step_path), source_doc.Name)
source_doc.recompute()
source_shapes = [
obj.Shape
for obj in source_doc.Objects
if hasattr(obj, "Shape") and not obj.Shape.isNull()
]
if len(source_shapes) != 1:
return False
source_shape = source_shapes[0]
bounds = source_shape.BoundBox
if (
len(source_shape.Solids) != 1
or not same_shape(source_shape, expected_source)
or not all(
close(actual, wanted)
for actual, wanted in zip(
(bounds.XMin, bounds.XMax, bounds.YMin, bounds.YMax, bounds.ZMin, bounds.ZMax),
(-60.0, 60.0, -40.0, 40.0, 0.0, 18.0),
)
)
):
return False
finally:
App.closeDocument(source_doc.Name)
doc = App.openDocument(str(fcstd_path))
try:
jobs = [obj for obj in doc.Objects if module(obj) == "Path.Main.Job"]
pockets = [obj for obj in doc.Objects if module(obj) == "Path.Op.PocketShape"]
drills = [obj for obj in doc.Objects if module(obj) == "Path.Op.Drilling"]
profiles = [obj for obj in doc.Objects if module(obj) == "Path.Op.Profile"]
controllers = [obj for obj in doc.Objects if module(obj) == "Path.Tool.Controller"]
tools = [obj for obj in doc.Objects if module(obj) == "Path.Tool.Bit"]
if not (
len(jobs) == 1
and len(pockets) == 5
and len(drills) == 2
and len(profiles) == 1
and len(controllers) == 5
and len(tools) == 5
):
return False
job = jobs[0]
operations = list(job.Operations.Group)
if len(operations) != 8 or set(operations) != set(pockets + drills + profiles):
return False
if (
len(job.Model.Group) != 1
or str(job.PostProcessor).strip().lower() != "linuxcnc"
or list(job.Fixtures) != ["G54"]
or bool(job.SplitOutput)
or os.path.normpath(str(job.PostProcessorOutputFile))
!= "/home/user/Desktop/task-19.nc"
):
return False
model = job.Model.Group[0]
expected_model = translated(expected_source, -18.0)
if module(model) != "draftobjects.clone" or not same_shape(model.Shape, expected_model):
return False
source_links = list(getattr(model, "Objects", []))
if len(source_links) != 1 or not same_shape(source_links[0].Shape, expected_source):
return False
stock = job.Stock
expected_stock = Part.makeBox(124.0, 84.0, 18.0, App.Vector(-62.0, -42.0, -18.0))
if (
module(stock) != "Path.Main.Stock"
or not same_shape(stock.Shape, expected_stock)
or not close(stock.ExtXneg, 2.0)
or not close(stock.ExtXpos, 2.0)
or not close(stock.ExtYneg, 2.0)
or not close(stock.ExtYpos, 2.0)
or not close(stock.ExtZneg, 0.0)
or not close(stock.ExtZpos, 0.0)
):
return False
by_number = {int(controller.ToolNumber): controller for controller in controllers}
if set(by_number) != {1, 2, 3, 4, 5}:
return False
if [int(controller.ToolNumber) for controller in job.Tools.Group] != [1, 2, 3, 4, 5]:
return False
tool_specs = {
1: ("end mill", 16.0),
2: ("drill", 14.0),
3: ("drill", 12.0),
4: ("end mill", 10.0),
5: ("end mill", 8.0),
}
temporary = []
for number, (kind, diameter) in tool_specs.items():
controller = by_number[number]
tool = controller.Tool
if tool not in tools or any(other.Tool == tool for n, other in by_number.items() if n != number):
return False
shape_name = "drill" if kind == "drill" else "endmill"
if (
not close(tool.Diameter, diameter)
or str(tool.ShapeName).strip().lower() != shape_name
or os.path.basename(str(tool.BitShape)).lower() != shape_name + ".fcstd"
or tool.Shape.isNull()
or len(tool.Shape.Solids) != 1
or not close(tool.Length, 60.0)
or not close(controller.SpindleSpeed, 7000.0)
or str(controller.SpindleDir) != "Forward"
or not close(controller.HorizFeed.getValueAs("mm/min").Value, 500.0)
or not close(controller.VertFeed.getValueAs("mm/min").Value, 500.0)
):
return False
if kind == "drill":
if not close(tool.TipAngle, 118.0):
return False
elif not close(tool.ShankDiameter, diameter) or not close(tool.CuttingEdgeHeight, 24.0):
return False
reference = expected_tool(doc, number, kind, diameter)
temporary.append(reference)
doc.recompute()
if not same_shape(tool.Shape, reference.Shape):
return False
for reference in temporary:
doc.removeObject(reference.Name)
doc.recompute()
matched = {}
for pocket in pockets:
if not bool(pocket.Active) or pocket.ToolController not in controllers:
return False
face = horizontal_floor(pocket, model)
if face is None:
return False
box = face.BoundBox
candidates = [
spec
for spec in POCKETS
if close(face.CenterOfMass.x, spec[1], 1e-4)
and close(face.CenterOfMass.y, 0.0, 1e-4)
and close(box.ZMin, -spec[5], 1e-5)
]
if len(candidates) != 1:
return False
spec = candidates[0]
if spec[0] in matched:
return False
matched[spec[0]] = pocket
if (
pocket.ToolController != by_number[spec[6]]
or pocket.ToolController.Tool.Diameter.Value > min(spec[2], spec[3]) + 1e-7
or not close(pocket.StartDepth, 0.0)
or not close(pocket.FinalDepth, -spec[5])
or not close(pocket.StepDown.Value, 2.0)
or not close(float(pocket.StepOver), 50.0)
or not close(pocket.SafeHeight.Value, 3.0)
or not close(pocket.ClearanceHeight.Value, 5.0)
or bool(pocket.UseOutline)
or not validate_pocket_path(pocket, spec)
):
return False
if set(matched) != {spec[0] for spec in POCKETS}:
return False
drill_by_tool = {}
for drill in drills:
controller = drill.ToolController
if controller not in controllers or int(controller.ToolNumber) not in {2, 3}:
return False
number = int(controller.ToolNumber)
if number in drill_by_tool:
return False
drill_by_tool[number] = drill
records = drilling_cycles(drill)
if records is None or len(records) != 6:
return False
if {(round(x, 4), round(y, 4)) for x, y, _, _ in records} != EXPECTED_HOLES[number]:
return False
depths = {round(z, 4) for _, _, z, _ in records}
retracts = {round(r, 4) for _, _, _, r in records}
if (
len(depths) != 1
or not -25.0 <= next(iter(depths)) <= -19.0
or len(retracts) != 1
or not 1.9 <= next(iter(retracts)) <= 5.1
or not bool(drill.Active)
or not close(drill.StartDepth, 0.0)
or not close(drill.FinalDepth, -19.0)
or not close(drill.RetractHeight, 2.0)
or str(drill.RetractMode) != "G98"
or str(drill.ExtraOffset) != "Drill Tip"
or not close(drill.SafeHeight.Value, 3.0)
or not close(drill.ClearanceHeight.Value, 5.0)
or bool(drill.KeepToolDown)
):
return False
if set(drill_by_tool) != {2, 3}:
return False
profile = profiles[0]
if (
profile.ToolController != by_number[1]
or not bool(profile.Active)
or str(profile.Side) != "Outside"
or not bool(profile.UseComp)
or not bool(profile.processPerimeter)
or bool(profile.processHoles)
or bool(profile.processCircles)
or not close(profile.StartDepth, 0.0)
or not close(profile.FinalDepth, -18.0)
or not close(profile.StepDown.Value, 3.0)
or str(profile.Direction) != "CW"
or not close(profile.SafeHeight.Value, 3.0)
or not close(profile.ClearanceHeight.Value, 5.0)
or not validate_profile_path(profile)
):
return False
expected_operations = [
matched["P1"],
drill_by_tool[2],
drill_by_tool[3],
matched["P2"],
matched["P3"],
matched["P4"],
matched["P5"],
profile,
]
if operations != expected_operations:
return False
operation_tools = Counter(int(op.ToolController.ToolNumber) for op in operations)
if operation_tools != Counter({1: 2, 2: 1, 3: 1, 4: 3, 5: 1}):
return False
if any(count > 4 for count in operation_tools.values()):
return False
for obj in controllers + operations + [job]:
obj.touch()
doc.recompute()
doc.recompute()
if any(list(op.State) != ["Up-to-date"] or len(op.Path.Commands) == 0 for op in operations):
return False
for pocket in pockets:
spec = next(spec for spec in POCKETS if matched[spec[0]] == pocket)
if not validate_pocket_path(pocket, spec):
return False
if any(drilling_cycles(drill) is None for drill in drills) or not validate_profile_path(profile):
return False
sections = PathPostCommand.buildPostList(job)
if len(sections) != 1:
return False
PostProcessor.load("linuxcnc").export(
sections[0][1], str(repost_path), job.PostProcessorArgs
)
repost_signature = code_signature(repost_path)
submitted_signature = code_signature(nc_path)
return repost_signature is not None and repost_signature == submitted_signature
finally:
App.closeDocument(doc.Name)
ok = False
try:
ok = validate(
pathlib.Path(os.environ["TASK19_STEP"]),
pathlib.Path(os.environ["TASK19_FCSTD"]),
pathlib.Path(os.environ["TASK19_NC"]),
pathlib.Path(os.environ["TASK19_REPOST"]),
)
except Exception as error:
print("task-19 child: %s" % error, file=sys.stderr)
traceback.print_exc()
pathlib.Path(os.environ["TASK19_RESULT"]).write_text(
json.dumps({"ok": bool(ok)}, sort_keys=True), encoding="utf-8"
)
raise SystemExit(0 if ok else 1)
'''
def validate_freecad(step_path, fcstd_path, nc_path, workdir):
child = workdir / "validate_task19.py"
repost = workdir / "repost.nc"
result_file = workdir / "result.json"
child.write_text(CHILD_SOURCE, encoding="utf-8")
child.chmod(0o600)
try:
result = subprocess.run(
[str(FREECADCMD), str(child)],
cwd=workdir,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
timeout=300,
check=False,
env={
"HOME": str(workdir),
"LANG": "C.UTF-8",
"LC_ALL": "C.UTF-8",
"PATH": "/usr/bin:/bin",
"TMPDIR": str(workdir),
"TASK19_STEP": str(step_path),
"TASK19_FCSTD": str(fcstd_path),
"TASK19_NC": str(nc_path),
"TASK19_REPOST": str(repost),
"TASK19_RESULT": str(result_file),
},
)
except (OSError, subprocess.TimeoutExpired):
return False
try:
payload = json.loads(result_file.read_text(encoding="utf-8"))
except (OSError, UnicodeError, json.JSONDecodeError):
payload = None
if result.returncode != 0 or payload != {"ok": True}:
if result.stderr:
print(result.stderr[-5000:], file=sys.stderr)
return False
return regular_file(repost, 5_000, 2_000_000)
def main():
if not FREECADCMD.is_file():
return fail("freecadcmd missing")
if not validate_csv(CSV_FILE):
return fail("wrong tool_candidates.csv")
if not regular_file(STEP, 5_000, 5_000_000):
return fail("invalid STEP file")
if normalized_text_sha256(STEP) != EXPECTED_STEP_SHA256:
return fail("wrong init STEP")
if not validate_archive(FCSTD):
return fail("invalid FCStd archive")
if not validate_nc(NC):
return fail("invalid NC semantics")
with tempfile.TemporaryDirectory(prefix="task-19-eval-") as directory:
workdir = Path(directory)
frozen_step = workdir / "complex_pockets.step"
frozen_csv = workdir / "tool_candidates.csv"
frozen_fcstd = workdir / "task-19.FCStd"
frozen_nc = workdir / "task-19.nc"
if not freeze_file(STEP, frozen_step, 5_000, 5_000_000):
return fail("could not freeze STEP")
if not freeze_file(CSV_FILE, frozen_csv, 100, 10_000):
return fail("could not freeze CSV")
if not freeze_file(FCSTD, frozen_fcstd, 20_000, 20_000_000):
return fail("could not freeze FCStd")
if not freeze_file(NC, frozen_nc, 5_000, 2_000_000):
return fail("could not freeze NC")
if not validate_csv(frozen_csv):
return fail("CSV changed during evaluation")
if normalized_text_sha256(frozen_step) != EXPECTED_STEP_SHA256:
return fail("STEP changed during evaluation")
if not validate_freecad(frozen_step, frozen_fcstd, frozen_nc, workdir):
return fail("FreeCAD validation failed")
return True
if __name__ == "__main__":
try:
result = main()
except Exception as error:
print("task-19 evaluator exception: " + str(error), file=sys.stderr)
result = False
print(True if result else False)
|