Files
2026-09-30 21:10:51 -03:00

254 lines
15 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""Monta as pranchas A3 (SVG -> PDF/PNG) a partir dos desenhos em traço do
Blender (img/*.png + *.json). Estilo manual de instruções."""
import base64, json, os, subprocess
from PIL import Image
D = os.path.dirname(os.path.abspath(__file__))
IMG = os.path.join(D, "img")
W, H = 420.0, 297.0
INK = "#141414"
ACC = "#E85A1F" # laranja da apresentação
BLU = "#1F4E8A"
FONT = "DejaVu Sans, Arial, sans-serif"
MONO = "DejaVu Sans Mono, monospace"
def img_tag(name, x, y, w, h=None):
p = os.path.join(IMG, name)
im = Image.open(p)
if h is None:
h = w * im.height / im.width
b64 = base64.b64encode(open(p, "rb").read()).decode()
return '<image x="%.2f" y="%.2f" width="%.2f" height="%.2f" preserveAspectRatio="none" xlink:href="data:image/png;base64,%s"/>' % (x, y, w, h, b64), h
def anchors(name):
return json.load(open(os.path.join(IMG, name + ".json")))
def text(x, y, s, size=3.2, anchor="start", weight="normal", color=INK, font=FONT, rot=0):
tr = ' transform="rotate(%g %.2f %.2f)"' % (rot, x, y) if rot else ""
return '<text x="%.2f" y="%.2f" font-family="%s" font-size="%.2f" font-weight="%s" fill="%s" text-anchor="%s"%s>%s</text>' % (
x, y, font, size, weight, color, anchor, tr, s)
def arrow(x, y, ang_deg, size=1.8, color=INK):
import math
a = math.radians(ang_deg)
p1 = (x - size * math.cos(a) + 0.6 * math.sin(a), y - size * math.sin(a) - 0.6 * math.cos(a))
p2 = (x - size * math.cos(a) - 0.6 * math.sin(a), y - size * math.sin(a) + 0.6 * math.cos(a))
return '<polygon points="%.2f,%.2f %.2f,%.2f %.2f,%.2f" fill="%s"/>' % (x, y, p1[0], p1[1], p2[0], p2[1], color)
def dim_h(x1, x2, y_obj, y_dim, label, color=BLU):
s = ['<g stroke="%s" stroke-width="0.18" fill="none">' % color,
'<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f"/>' % (x1, y_obj, x1, y_dim + (1.5 if y_dim > y_obj else -1.5)),
'<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f"/>' % (x2, y_obj, x2, y_dim + (1.5 if y_dim > y_obj else -1.5)),
'<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f"/>' % (x1, y_dim, x2, y_dim), "</g>",
arrow(x1, y_dim, 180, color=color), arrow(x2, y_dim, 0, color=color),
text((x1 + x2) / 2, y_dim - 1.0, label, 2.8, "middle", color=color, font=MONO)]
return "\n".join(s)
def dim_v(y1, y2, x_obj, x_dim, label, color=BLU, side="left"):
s = ['<g stroke="%s" stroke-width="0.18" fill="none">' % color,
'<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f"/>' % (x_obj, y1, x_dim + (-1.5 if x_dim < x_obj else 1.5), y1),
'<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f"/>' % (x_obj, y2, x_dim + (-1.5 if x_dim < x_obj else 1.5), y2),
'<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f"/>' % (x_dim, y1, x_dim, y2), "</g>",
arrow(x_dim, y1, -90 if y1 < y2 else 90, color=color), arrow(x_dim, y2, 90 if y1 < y2 else -90, color=color),
text(x_dim - 1.0, (y1 + y2) / 2, label, 2.8, "middle", color=color, font=MONO, rot=-90)]
return "\n".join(s)
def balloon(n, bx, by, ax, ay, r=3.2):
return "\n".join(['<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f" stroke="%s" stroke-width="0.25"/>' % (ax, ay, bx, by, INK),
'<circle cx="%.2f" cy="%.2f" r="0.7" fill="%s"/>' % (ax, ay, INK),
'<circle cx="%.2f" cy="%.2f" r="%.2f" fill="white" stroke="%s" stroke-width="0.45"/>' % (bx, by, r, ACC),
text(bx, by + 1.25, str(n), 3.4, "middle", "bold", ACC)])
def label(s, bx, by, ax, ay, anchor="start"):
return "\n".join(['<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f" stroke="%s" stroke-width="0.22"/>' % (ax, ay, bx, by, INK),
'<circle cx="%.2f" cy="%.2f" r="0.6" fill="%s"/>' % (ax, ay, INK),
text(bx + (1 if anchor == "start" else -1), by + 1.0, s, 2.9, anchor, "bold")])
def frame(title, sheet, scale):
s = ['<rect x="0" y="0" width="%g" height="%g" fill="white"/>' % (W, H),
'<rect x="8" y="8" width="%g" height="%g" fill="none" stroke="%s" stroke-width="0.7"/>' % (W - 16, H - 16, INK),
'<rect x="10" y="10" width="%g" height="%g" fill="none" stroke="%s" stroke-width="0.25"/>' % (W - 20, H - 20, INK)]
# cabeçalho estilo manual
s += ['<rect x="10" y="10" width="%g" height="14" fill="%s"/>' % (W - 20, INK),
text(16, 20.2, "ROBÔ MÓVEL DE CARGA", 7.0, weight="bold", color="white"),
text(118, 20.2, "· " + title.upper(), 5.0, color=ACC, weight="bold"),
text(W - 16, 20.2, "PRANCHA %s" % sheet, 4.2, "end", "bold", "white", MONO)]
# carimbo
x0, y0, w, h = W - 128, H - 38, 118, 28
s += ['<rect x="%g" y="%g" width="%g" height="%g" fill="white" stroke="%s" stroke-width="0.4"/>' % (x0, y0, w, h, INK),
'<line x1="%g" y1="%g" x2="%g" y2="%g" stroke="%s" stroke-width="0.25"/>' % (x0, y0 + 10, x0 + w, y0 + 10, INK),
'<line x1="%g" y1="%g" x2="%g" y2="%g" stroke="%s" stroke-width="0.25"/>' % (x0, y0 + 19, x0 + w, y0 + 19, INK),
'<line x1="%g" y1="%g" x2="%g" y2="%g" stroke="%s" stroke-width="0.25"/>' % (x0 + 60, y0 + 10, x0 + 60, y0 + h, INK),
text(x0 + 3, y0 + 4.2, "PROJETO 4 · ROBÓTICA INCLUSIVA · UNICAP", 2.5, weight="bold"),
text(x0 + 3, y0 + 8.3, "Robô móvel de carga — base mecanum + estante MDF", 2.4),
text(x0 + 3, y0 + 13.5, "ESCALA", 2.0, color="#777", font=MONO), text(x0 + 3, y0 + 17.4, scale, 3.2, weight="bold", font=MONO),
text(x0 + 63, y0 + 13.5, "UNIDADES", 2.0, color="#777", font=MONO), text(x0 + 63, y0 + 17.4, "mm", 3.2, weight="bold", font=MONO),
text(x0 + 3, y0 + 22.5, "DATA", 2.0, color="#777", font=MONO), text(x0 + 3, y0 + 26.4, "24/09/2026", 3.0, weight="bold", font=MONO),
text(x0 + 63, y0 + 22.5, "FONTE", 2.0, color="#777", font=MONO), text(x0 + 63, y0 + 26.4, "FreeCAD 1.1 · Blender 5.2", 2.6, weight="bold", font=MONO)]
return s
def svg(content, name):
doc = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="%gmm" height="%gmm" viewBox="0 0 %g %g">\n%s\n</svg>' % (W, H, W, H, "\n".join(content))
p = os.path.join(D, name + ".svg")
open(p, "w").write(doc)
subprocess.run(["inkscape", p, "--export-type=pdf", "--export-filename=" + os.path.join(D, name + ".pdf")], capture_output=True)
subprocess.run(["inkscape", p, "--export-type=png", "--export-dpi=150", "--export-filename=" + os.path.join(D, name + ".png")], capture_output=True)
return p
# ======================================================================== prancha 1
def prancha1():
s = frame("Vistas gerais", "1/3", "1:10")
k = 0.1 # 1 px = 1 mm -> 1:10
fx, fy = 22, 44 # frente (700 x 1200 px)
lx, ly = 112, 44 # lado
tx, ty = 202, 44 # topo (700 x 700)
t1, _ = img_tag("frente.png", fx, fy, 70, 120)
t2, _ = img_tag("lado.png", lx, ly, 70, 120)
t3, _ = img_tag("topo.png", tx, ty, 70, 70)
s += [t1, t2, t3]
Z = lambda z: fy + (600 - (z - 530)) * k # z (mm) -> y da folha
X = lambda x0, v: x0 + (350 + v) * k # coordenada lateral -> x da folha
# frente: largura total e alturas
s.append(dim_h(X(fx, -250), X(fx, 250), Z(0), Z(0) + 6, "500"))
for z, lab, off in ((1060, "1060", 6), (1020, "1020", 11.5), (580, "580", 17), (141, "141", 22.5)):
s.append(dim_v(Z(0), Z(z), X(fx, -250), X(fx, -250) - off, lab))
s.append(text(fx + 35, fy + 128, "VISTA FRONTAL", 3.4, "middle", "bold"))
# lado: entre-eixos 370 e profundidade 500
s.append(dim_h(X(lx, -185), X(lx, 185), Z(30), Z(0) + 6, "370 (entre-eixos)"))
s.append(dim_h(X(lx, -250), X(lx, 250), Z(1060), Z(1060) - 5, "500"))
s.append(text(lx + 35, ly + 128, "VISTA LATERAL DIREITA", 3.4, "middle", "bold"))
# topo: 500 x 500, barras a 456
TY = lambda y: ty + (350 - y) * k
s.append(dim_h(X(tx, -250), X(tx, 250), TY(-250), TY(-250) + 6, "500"))
s.append(dim_h(X(tx, -228), X(tx, 228), TY(228), TY(250) - 5, "456 (barras M8)"))
s.append(dim_v(TY(-250), TY(250), X(tx, 250), X(tx, 250) + 5, "500"))
s.append(text(tx + 35, ty + 78, "VISTA SUPERIOR", 3.4, "middle", "bold"))
# isométrica (sem escala)
t4, h4 = img_tag("iso.png", 290, 34, 105)
s += [t4, text(342, 34 + h4 + 3, "PERSPECTIVA ISOMÉTRICA (sem escala)", 3.2, "middle", "bold")]
# notas
notas = ["NOTAS", "1. MDF cru 3 mm, cortado a laser; encaixes colados com PVA.",
"2. Colunas: 4 barras roscadas M8 x 1000 (DIN 975) usadas inteiras.",
"3. Prateleiras presas por porca M8 (baixo) e porca borboleta M8 (cima).",
"4. Rodas mecanum 60 mm em \"X\" vistas de cima; vão livre 8,8 mm.",
"5. Massa estimada ~7,2 kg sem carga."]
for i, n in enumerate(notas):
s.append(text(202, 132 + i * 5.2, n, 3.0 if i else 3.4, weight="bold" if i == 0 else "normal"))
return svg(s, "prancha_1_vistas_gerais")
# ======================================================================== prancha 2
PECAS = [
(1, "base", "Chassi: caixa MDF 3 mm (base, 4 paredes, 3 nervuras)", "1 conj."),
(2, "tampo", "Tampo MDF 3 mm 500 x 500 (1º nível de carga)", "1"),
(3, "prat_meio", "Prateleira do meio — placa MDF 3 mm (face a 580 mm)", "1"),
(4, "prat_topo", "Prateleira de cima — placa MDF 3 mm (face a 1020 mm)", "1"),
(5, "borda", "Borda 40 mm MDF 3 mm (encaixe por espigas)", "8"),
(6, "nervura", "Nervura inferior em cruz (meia-madeira)", "4"),
(7, "barra", "Barra roscada M8 x 1000 DIN 975 zincada", "4"),
(8, "borboleta", "Porca borboleta M8 + arruela larga Ø24 (sobre prateleira)", "8 + 8"),
(9, "porca_base", "Porca M8 c/ nylon + arruela larga Ø24 (base)", "8 + 16"),
(10, "roda", "Roda mecanum 60 mm (2 direitas + 2 esquerdas)", "4"),
(11, "motor", "Motor de passo NEMA17 17HS4401S", "4"),
(12, "suporte", "Suporte L NEMA17 + 4 parafusos M3x6", "4"),
(13, "calco", "Calço MDF 4 x 3 mm + 2 parafusos M4x25", "4"),
]
def prancha2():
s = frame("Vista explodida — montagem", "2/3", "S/ ESCALA")
a = anchors("explodida.png")
rw, rh = a["res"]
x0, y0, hh = 16, 28, 258
ww = hh * rw / rh
t, _ = img_tag("explodida.png", x0, y0, ww, hh)
s.append(t)
k = hh / rh
# balões: à esquerda e à direita da figura, ordenados pela altura da âncora
items = [(n, a["anchors"][key]) for n, key, _, _ in PECAS if key in a["anchors"]]
left = sorted([it for it in items if it[1][0] < rw * 0.5], key=lambda t: t[1][1])
right = sorted([it for it in items if it[1][0] >= rw * 0.5], key=lambda t: t[1][1])
for side, lst in (("L", left), ("R", right)):
bx = x0 + 6 if side == "L" else x0 + ww - 6
n = len(lst)
for i, (num, (px, py)) in enumerate(lst):
ay = y0 + py * k
by = y0 + 14 + i * (hh - 28) / max(1, n - 1) if n > 1 else ay
s.append(balloon(num, bx, by, x0 + px * k, ay))
# lista de peças
tx, ty = x0 + ww + 12, 34
s.append(text(tx, ty, "LISTA DE PEÇAS", 5.0, weight="bold"))
s.append('<line x1="%g" y1="%g" x2="%g" y2="%g" stroke="%s" stroke-width="0.6"/>' % (tx, ty + 2.5, W - 14, ty + 2.5, ACC))
for i, (n, key, desc, q) in enumerate(PECAS):
y = ty + 10 + i * 9.3
s.append('<circle cx="%g" cy="%g" r="3.0" fill="white" stroke="%s" stroke-width="0.45"/>' % (tx + 3, y - 1.1, ACC))
s.append(text(tx + 3, y + 0.1, str(n), 3.1, "middle", "bold", ACC))
s.append(text(tx + 9, y + 0.1, desc, 3.0))
s.append(text(W - 16, y + 0.1, q, 3.0, "end", "bold", font=MONO))
y = ty + 10 + len(PECAS) * 9.3 + 4
passos = ["SEQUÊNCIA DE MONTAGEM",
"A. Colar calços (4 camadas) sob a base; montar a caixa (dedos + espigas).",
"B. Fixar suportes + motores (M4x25 / M3x6); encaixar as rodas no eixo Ø5.",
"C. Passar as 4 barras M8 pelos cantos; travar a caixa (porca + arruela).",
"D. Instalar eletrônica e fiação (prancha 3); fechar com o tampo.",
"E. Rosquear porcas de apoio na altura; prateleiras + borboletas."]
for i, p in enumerate(passos):
s.append(text(tx, y + i * 5.4, p, 3.3 if i == 0 else 2.75, weight="bold" if i == 0 else "normal"))
return svg(s, "prancha_2_vista_explodida")
# ======================================================================== prancha 3
def prancha3():
s = frame("Layout interno da base", "3/3", "1:2,5")
a = anchors("interno.png")
rw, rh = a["res"] # 2240 px = 560 mm
size = 560 / 2.5 # 224 mm
x0, y0 = 18, 34
t, _ = img_tag("interno.png", x0, y0, size, size)
s.append(t)
k = size / rw
P = lambda key: (x0 + a["anchors"][key][0] * k, y0 + a["anchors"][key][1] * k)
rot = [("cam", "ESP32-CAM frontal (navegação)", "R"), ("pb1", "Protoboard 1 — divisor 1k/2k, C 100 µF", "R"),
("arduino", "Arduino UNO + CNC Shield V3 + 4x A4988", "R"), ("pb2", "Protoboard 2 — barramento 5 V", "R"),
("bateria", "Bateria Li-ion 4S 14,8 V 2600 mAh", "L"), ("lm", "LM2596 (5,0 V)", "R"),
("wago", "Wagos (+/−) de distribuição", "R"), ("xt60", "XT60 (desconexão da bateria)", "L"),
("fusivel", "Fusível lâmina 5 A", "L")]
itens = [(key, lab) for key, lab, _ in rot if key in a["anchors"]]
itens.sort(key=lambda it: P(it[0])[1]) # ordena pela altura -> linhas não se cruzam
n = len(itens)
for i, (key, lab) in enumerate(itens):
ax, ay = P(key)
ly = y0 + 8 + i * (size - 16) / max(1, n - 1)
s.append(label(lab, x0 + size + 8, ly, ax, ay))
s.append(text(x0 + size / 2, y0 + size + 7, "VISTA SUPERIOR SEM TAMPO — FRENTE PARA CIMA", 3.4, "middle", "bold"))
# legenda de ligações
tx, ty = 334, 40
lig = ["LIGAÇÕES",
"Potência (18 AWG):", " bateria → XT60 → fusível 5 A →", " chave → Wago(+); bateria(−) →", " Wago(−); Wagos → borne 12-36 V", " da shield e entrada do LM2596.", "",
"5 V (22 AWG):", " LM2596 → PB2 → pino 5V/GND", " da shield (Arduino) e → PB1 →", " ESP32-CAM.", "",
"Serial (SoftwareSerial):", " ESP U0T → A1 (Hold)", " A0 (Abort) → 1k → nó → U0R", " nó → 2k → GND", "",
"Motores (CNC Shield):", " X tras. dir. · Y diant. dir.", " Z tras. esq. · A diant. esq.", "",
"Não aparecem no desenho:", " XT60, fusível e fiação."]
for i, l in enumerate(lig):
bold = i == 0 or (l and not l.startswith(" "))
s.append(text(tx, ty + i * 4.6, l, 3.3 if i == 0 else 2.55, weight="bold" if bold else "normal"))
return svg(s, "prancha_3_layout_interno")
if __name__ == "__main__":
import sys
for f in (sys.argv[1:] or ["1", "2", "3"]):
print({"1": prancha1, "2": prancha2, "3": prancha3}[f]())