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.

61 lines
2.6 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 -*-
"""Выполняется ВНУТРИ FreeCAD GUI через MCP (tools/fcmcp.py execfile cad/mcp_show.py [full|cut]).
Строит документ «Клапан» с раскрашенными деталями (полная сборка и сборка с вырезом четверти),
сохраняет out/cad/valve_assembly.FCStd и выставляет вид."""
import os
import sys
import FreeCAD as App
import FreeCADGui as Gui
ROOT = globals().get("PROJECT_ROOT") or os.getcwd() # передаётся tools/fcmcp.py
if ROOT not in sys.path:
sys.path.insert(0, ROOT)
for m in [k for k in list(sys.modules) if k.startswith(("cad.", "valve.", "calc."))]:
del sys.modules[m]
from cad import build_model as bm # noqa: E402
from valve.fcutil import Part, V # noqa: E402
mode = (globals().get("ARGS") or "full").strip()
name = "Valve"
if name in App.listDocuments():
App.closeDocument(name)
doc = App.newDocument(name)
parts, info = bm.build()
grp_full = doc.addObject("App::DocumentObjectGroup", "Сборка")
grp_cut = doc.addObject("App::DocumentObjectGroup", "Сборка_разрез")
cutter = Part.makeBox(2000, 2000, 2000, V(0, -2000, -500)) # вырез четверти: x > 0, y < 0
cutter = cutter.common(Part.makeBox(2000, 2000, 2000, V(0, -1000, -500)))
for p in parts:
shapes = bm.solids_of(p) + [e["shape"] for e in p.get("extra", [])]
colors = [p["color"]] * len(bm.solids_of(p)) + [e["color"] for e in p.get("extra", [])]
for k, (s, c) in enumerate(zip(shapes, colors)):
label = "%02d_%s%s" % (p["pos"], p["name"].replace(" ", "_"), "_%d" % (k + 1) if len(shapes) > 1 else "")
o = doc.addObject("Part::Feature", label)
o.Shape = s
o.ViewObject.ShapeColor = c
grp_full.addObject(o)
if p["pos"] in (17,): # рычаг и мелочь снаружи — без разреза
sc = s
else:
try:
sc = s.cut(cutter)
except Exception:
sc = s
oc = doc.addObject("Part::Feature", label + "_cut")
oc.Shape = sc
oc.ViewObject.ShapeColor = c
grp_cut.addObject(oc)
doc.recompute()
show_cut = mode == "cut"
for o in grp_full.Group:
o.Visibility = not show_cut
for o in grp_cut.Group:
o.Visibility = show_cut
os.makedirs(os.path.join(ROOT, "out", "cad"), exist_ok=True)
doc.saveAs(os.path.join(ROOT, "out", "cad", "valve_assembly.FCStd"))
v = Gui.ActiveDocument.ActiveView
v.viewIsometric()
v.fitAll()
print("Документ сохранён: out/cad/valve_assembly.FCStd; объектов: %d; режим: %s" % (len(doc.Objects), mode))

Powered by TurnKey Linux.