Add DB9 CAD reference data

This commit is contained in:
2026-09-21 12:32:19 +02:00
parent 7d76a41540
commit 6406142b21
8 changed files with 46777 additions and 0 deletions
@@ -0,0 +1,46 @@
"""Validate registration and selected face subsets; no board writes."""
import hashlib
import json
from pathlib import Path
import xml.etree.ElementTree as ET
HERE = Path(__file__).resolve().parent
D = json.loads((HERE / 'geometry.json').read_text())
assert len(D) == 15 and all(s['valid'] for s in D)
for source in json.loads((HERE / 'sources.json').read_text()):
assert hashlib.sha256((HERE / source['file']).read_bytes()).hexdigest() == source['sha256']
board = HERE.parent / 'Adafruit RS-232 Full Pinout Level-Shifter Breakout.brd'
assert hashlib.sha256(board.read_bytes()).hexdigest() == '6a7b35ef909f5a2d243c326c34db3957aaa01275bf2aac8e0c749ff18162e870'
root = ET.parse(board).getroot()
b = root.find('drawing/board')
jp = b.find("elements/element[@name='JP2']")
pkg = b.find("libraries/library[@name='microbuilder']/packages/package[@name='1X12_ROUND_76MIL']")
for pad in pkg.findall('pad'):
x, y = float(jp.get('x')) + float(pad.get('x')), float(jp.get('y')) + float(pad.get('y'))
assert any(abs(f.get('radius', 0)-0.5)<1e-8 and abs(f['location'][0]-x)<1e-8 and abs(f['location'][1]-y)<1e-8 for f in D[0]['faces'])
for x in [3.81, 27.94]:
assert any(abs(f.get('radius',0)-1.5)<1e-8 and abs(f['location'][0]-x)<1e-8 and abs(f['location'][1]-11.43)<1e-8 for f in D[0]['faces'])
assert all(abs(a-b)<1e-8 for a,b in zip(D[0]['bounds'], [0,0,0,31.75,29.337,1.57]))
subsets = {
'front_flange_exposed_faces': [8,11,12,13,14],
'shell_straight_outer_surface': list(range(18,26)),
'shell_outer_including_root_and_lip': list(range(18,26))+list(range(81,89))+list(range(103,111)),
'left_front_hex_post': list(range(53,62))+[89],
'right_front_hex_post': list(range(62,71))+[90],
}
result = {}
for name, ids in subsets.items():
faces = [D[11]['faces'][i-1] for i in ids]
assert all(any('Opaque(245,245,246)' in c for c in f['colors']) for f in faces)
bounds = [min(f['bounds'][i] for f in faces) for i in range(3)] + [max(f['bounds'][i] for f in faces) for i in range(3,6)]
result[name] = dict(solid=12, faces=ids, bounds=bounds, dimensions=[bounds[i+3]-bounds[i] for i in range(3)])
left, right = [D[11]['faces'][i-1] for i in [60,69]]
assert abs(right['location'][0]-left['location'][0]-25)<1e-8
assert left['radius'] == right['radius'] == 1.5
result['front_lock_axes'] = [left, right]
(HERE / 'measurements.json').write_text(json.dumps(result,indent=2)+'\n')
print('PASS: source hashes, 15 valid solids, all 12 Eagle header centres, PCB bounds, mounting holes, metal-appearance subsets and front lock cylinders.')
for name, row in result.items():
if isinstance(row,dict):
print(name, [round(v,6) for v in row['bounds']], 'size', [round(v,6) for v in row['dimensions']])