# Grouper: rewrite section 11 of gr_measure.py (the raw silhouette tables) from build/outline_tables.json, so the tables # always come from the current masks (python gr_views.py first). Plain Python. import os, json HERE = os.path.dirname(os.path.abspath(__file__)) MARK = "# 11. RAW SILHOUETTES" T = json.load(open(os.path.join(HERE, "outline_tables.json"))) def table(name, step): t = {int(k): v for k, v in T[name].items()} keys = sorted(t) rows = [(k, t[k][2], t[k][3]) for k in keys if (k - keys[0]) % step == 0 or k == keys[-1]] out, line = [], [] for r in rows: line.append("(%d, %.2f, %.2f)" % r) if len(line) == 8: out.append(", ".join(line)); line = [] if line: out.append(", ".join(line)) return "%s_SIL = [%s]\n" % (name.upper(), (",\n ").join(out)) src = open(os.path.join(HERE, "gr_measure.py"), encoding="utf-8").read() i = src.index(MARK) head = src[:i] body = ("# 11. RAW SILHOUETTES (build/gr_views.py -> outline_tables.json -> build/gr_sil_tables.py; every 3 px, FRONT/BACK every 2 rows)\n" "# =====================================================================================================================\n" "# SIDE_SIL, TOP_SIL, BOTTOM_SIL: (x, y_top_line, y_bottom_line); FRONT_SIL, BACK_SIL: (y, x_left_line, x_right_line).\n" "# The outline line's centre (the silhouette's outer edge moved 0.75 px in), every part included (SIDE: the antenna, the\n" "# collar, the emitters, the drum and its cradle; TOP: the stern fins, the pods). FRONT and BACK: the right halves carry\n" "# label leaders (FRONT x 283-310, BACK x 1225-1290 at y 300-330): use the left halves. For overlays and checks only:\n" "# the hull is built from section 1's tables.\n") for n, st in (("side", 3), ("top", 3), ("bottom", 3), ("front", 2), ("back", 2)): body += table(n, st) + "\n" open(os.path.join(HERE, "gr_measure.py"), "w", encoding="utf-8").write(head + body) print("section 11 rewritten")