You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
5.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*- coding: utf-8 -*-
"""Комплект конструкторской документации ВКП.25.250.00.000 — единый вход.
Запуск (из корня проекта):
tools/freecad/squashfs-root/usr/bin/python drawings/make_drawings.py
Все изображения строятся из 3D-модели (cad/build_model.build()), все числа — из valve/params.py, valve/norms.py,
out/calc/*.json, out/cad/bom.json, docs/02_decisions.md / docs/03_requirements_digest.md (через drawings/dw_env.py).
Выход: out/drawings/<обозначение>_<наименование>.pdf|png|dxf, сводный ВКП.25.250.00.000_комплект.pdf,
out/drawings/manifest.json (состав комплекта, перенумерация позиций, принятые при оформлении требования).
"""
import hashlib
import json
import os
import sys
import time
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT)
from drawings import dw_env # noqa: E402 (подключает FreeCAD)
from drawings.dw_env import OUT, DES, MODEL2POS, ACCEPTED, REQ, detail_code # noqa: E402
from drawings.dw_parts import Model # noqa: E402
from drawings import dw_sb, dw_spec, dw_body, dw_nozzle, dw_spring # noqa: E402
def _sha(path):
with open(path, "rb") as f:
return hashlib.sha256(f.read()).hexdigest()[:16]
def main():
t0 = time.time()
os.makedirs(OUT, exist_ok=True)
M = Model()
print("модель: %.1f с" % (time.time() - t0))
sheets = [] # (обозначение, наименование, формат, масштаб, Sheet, базовое имя файла)
base = os.path.join(OUT, DES + "_спецификация")
for i, sh in enumerate(dw_spec.make(M, base)):
fn = base + "_л%d" % (i + 1)
sh.save(fn, formats=("png", "dxf"))
sheets.append((DES, "Спецификация, лист %d" % (i + 1), "A4", "—", sh, fn))
print("спецификация: %.1f с" % (time.time() - t0))
fn = os.path.join(OUT, DES + "_СБ")
sh = dw_sb.make(M, fn)
sheets.append((DES + " СБ", "Сборочный чертеж", "A1", "1:2", sh, fn))
print("СБ: %.1f с" % (time.time() - t0))
fn = os.path.join(OUT, detail_code(MODEL2POS[1]) + "_корпус")
sh = dw_body.make(M, fn)
sheets.append((detail_code(MODEL2POS[1]), "Корпус", "A1", "1:1", sh, fn))
print("корпус: %.1f с" % (time.time() - t0))
fn = os.path.join(OUT, detail_code(MODEL2POS[2]) + "_сопло")
sh = dw_nozzle.make(M, fn)
sheets.append((detail_code(MODEL2POS[2]), "Сопло", "A3", "2:1", sh, fn))
print("сопло: %.1f с" % (time.time() - t0))
fn = os.path.join(OUT, detail_code(MODEL2POS[9]) + "_пружина")
sh = dw_spring.make(M, fn)
sheets.append((detail_code(MODEL2POS[9]), "Пружина № 1", "A3", "1:1", sh, fn))
print("пружина: %.1f с" % (time.time() - t0))
# многостраничная спецификация и сводный комплект (порядок: спецификация, СБ, детали по обозначениям)
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
meta = {"Creator": "valve-project drawings/make_drawings.py", "Title": DES, "CreationDate": None,
"ModDate": None}
spec_pdf = os.path.join(OUT, DES + "_спецификация.pdf")
kit_pdf = os.path.join(OUT, DES + "_комплект.pdf")
with PdfPages(spec_pdf, metadata=dict(meta, Title=DES + " Спецификация")) as pp:
for s in sheets:
if s[2] == "A4":
fig = s[4].figure()
pp.savefig(fig)
plt.close(fig)
with PdfPages(kit_pdf, metadata=dict(meta, Title=DES + " Комплект КД")) as pp:
for s in sheets:
fig = s[4].figure()
pp.savefig(fig)
plt.close(fig)
print("комплект: %.1f с" % (time.time() - t0))
srcs = ["valve/params.py", "valve/norms.py", "cad/build_model.py", "out/cad/bom.json", "out/calc/valve_calc.json",
"out/calc/strength.json", "out/calc/loads.json", "out/calc/flanges.json", "docs/02_decisions.md",
"docs/03_requirements_digest.md"]
man = dict(
designation=DES,
sheets=[dict(code=s[0], name=s[1], format=s[2], scale=s[3],
files=sorted(os.path.basename(p) for p in os.listdir(OUT)
if p.startswith(os.path.basename(s[5]) + ".")))
for s in sheets],
kit=os.path.basename(kit_pdf),
positions_model_to_kd={str(k): v for k, v in sorted(MODEL2POS.items())},
accepted_requirements={k: v for k, v in ACCEPTED.items()},
requirements_from_decisions_digest={k: dict(value=v[0], ref=v[1]) for k, v in REQ.items()},
sources={p: _sha(os.path.join(dw_env.ROOT, p)) for p in srcs if os.path.exists(os.path.join(dw_env.ROOT, p))},
)
with open(os.path.join(OUT, "manifest.json"), "w", encoding="utf-8") as f:
json.dump(man, f, ensure_ascii=False, indent=1)
print("готово: %d листов, %.1f с -> %s" % (len(sheets), time.time() - t0, OUT))
if __name__ == "__main__":
main()

Powered by TurnKey Linux.