-
Notifications
You must be signed in to change notification settings - Fork 1
/
screws.py
51 lines (43 loc) · 1.54 KB
/
screws.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from string import digits
from typing import Optional
from labelfrontend.units import LengthDimension, mm
# Abbreviations from
# https://monsterbolts.com/pages/abbreviations
# https://www.boltdepot.com/fastener-information/Abbreviations.aspx
def drive_svg(name: str) -> Optional[str]:
"""Returns the SVG name for a given drive specification"""
drive_type = name.rstrip(digits + '.')
return {
"PH": "external/screws/phillips.svg",
"SL": "external/screws/slot.svg",
"T": "external/screws/torx.svg",
"TS": "external/screws/torx-tamperproof.svg",
"SQ": "external/screws/robertson.svg",
"H": "external/screws/hex.svg",
"HX": "external/screws/hex-external.svg",
}.get(drive_type, None)
def head_svg(name: str) -> Optional[str]:
"""Returns the SVG name for a given head geometry"""
return {
"PN": "screws/pan.svg",
"BH": "screws/round.svg", # button
"CS": "screws/countersunk90.svg",
"OV": "screws/countersunk-round.svg",
"HX": "screws/hex.svg",
"HXF": "screws/hex-flanged.svg",
"SKT": "screws/socket.svg",
"SetFlat": "screws/set-flat.svg",
"SetCup": "screws/set-cup.svg",
"SetCone": "screws/set-cone.svg",
"SetDog": "screws/set-dog.svg",
}.get(name, None)
def thread_dia(value: str) -> LengthDimension:
if value.startswith("M"):
return float(value[1:]) * mm
else:
raise ValueError(f"unknown thread {value}")
def to_dim(value: str) -> LengthDimension:
if value.endswith("mm"):
return float(value[:-2]) * mm
else:
raise ValueError(f"unknown dimension {value}")