cadbuildr-frames 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cadbuildr/__init__.py +3 -0
- cadbuildr/frames/__init__.py +78 -0
- cadbuildr/frames/connectors.py +103 -0
- cadbuildr/frames/cut_list.py +99 -0
- cadbuildr/frames/frame.py +493 -0
- cadbuildr/frames/geometry.py +276 -0
- cadbuildr/frames/layout.py +517 -0
- cadbuildr/frames/profiles.py +318 -0
- cadbuildr_frames-0.2.0.dist-info/METADATA +214 -0
- cadbuildr_frames-0.2.0.dist-info/RECORD +12 -0
- cadbuildr_frames-0.2.0.dist-info/WHEEL +4 -0
- cadbuildr_frames-0.2.0.dist-info/licenses/LICENSE +21 -0
cadbuildr/__init__.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Structural and woodworking frames (weldments) on CADbuildr foundation.
|
|
2
|
+
|
|
3
|
+
A ``Frame`` sweeps a profile along a skeleton of line / arc segments, trims
|
|
4
|
+
the corners (miter, butt, coped), adds gussets and end caps, and reports a
|
|
5
|
+
cut list. Each member is its own Part inside the frame Assembly.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .connectors import Connection, ConnectorRule, Placed
|
|
9
|
+
from .cut_list import CutListItem
|
|
10
|
+
from .frame import (
|
|
11
|
+
EndCap,
|
|
12
|
+
EndCapPlate,
|
|
13
|
+
Frame,
|
|
14
|
+
FrameMember,
|
|
15
|
+
Gusset,
|
|
16
|
+
GussetPlate,
|
|
17
|
+
basis_transform,
|
|
18
|
+
)
|
|
19
|
+
from .geometry import Arc3D, Line3D, box_edges, polyline, rectangle
|
|
20
|
+
from .layout import (
|
|
21
|
+
DEFAULT_UP,
|
|
22
|
+
FALLBACK_UP,
|
|
23
|
+
FrameLayout,
|
|
24
|
+
Junction,
|
|
25
|
+
JunctionEnd,
|
|
26
|
+
MemberLayout,
|
|
27
|
+
solve_layout,
|
|
28
|
+
)
|
|
29
|
+
from .profiles import (
|
|
30
|
+
LUMBER_SIZES_IN,
|
|
31
|
+
Angle,
|
|
32
|
+
Channel,
|
|
33
|
+
IBeam,
|
|
34
|
+
Lumber,
|
|
35
|
+
Profile,
|
|
36
|
+
RectBar,
|
|
37
|
+
RectTube,
|
|
38
|
+
RoundBar,
|
|
39
|
+
RoundTube,
|
|
40
|
+
SquareTube,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"Angle",
|
|
45
|
+
"Arc3D",
|
|
46
|
+
"Channel",
|
|
47
|
+
"Connection",
|
|
48
|
+
"ConnectorRule",
|
|
49
|
+
"CutListItem",
|
|
50
|
+
"DEFAULT_UP",
|
|
51
|
+
"EndCap",
|
|
52
|
+
"EndCapPlate",
|
|
53
|
+
"FALLBACK_UP",
|
|
54
|
+
"Frame",
|
|
55
|
+
"FrameLayout",
|
|
56
|
+
"FrameMember",
|
|
57
|
+
"Gusset",
|
|
58
|
+
"GussetPlate",
|
|
59
|
+
"IBeam",
|
|
60
|
+
"Junction",
|
|
61
|
+
"JunctionEnd",
|
|
62
|
+
"LUMBER_SIZES_IN",
|
|
63
|
+
"Line3D",
|
|
64
|
+
"Lumber",
|
|
65
|
+
"MemberLayout",
|
|
66
|
+
"Placed",
|
|
67
|
+
"Profile",
|
|
68
|
+
"RectBar",
|
|
69
|
+
"RectTube",
|
|
70
|
+
"RoundBar",
|
|
71
|
+
"RoundTube",
|
|
72
|
+
"SquareTube",
|
|
73
|
+
"basis_transform",
|
|
74
|
+
"box_edges",
|
|
75
|
+
"polyline",
|
|
76
|
+
"rectangle",
|
|
77
|
+
"solve_layout",
|
|
78
|
+
]
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""The frame connector hook: one extension point that lets a library put
|
|
2
|
+
joint hardware (brackets, fasteners, end caps…) on every junction of a
|
|
3
|
+
``Frame``, and machine the members for it.
|
|
4
|
+
|
|
5
|
+
A connector is either a plain callable ``connector(junction) -> Connection |
|
|
6
|
+
None`` or a :class:`ConnectorRule`, which can also choose which member runs
|
|
7
|
+
through a butt node and prepare every member (add anchors, holes) before it
|
|
8
|
+
is placed. The frame calls it once per :class:`~cadbuildr.frames.layout.Junction`
|
|
9
|
+
(free ends included), after the layout is solved and before any member Part
|
|
10
|
+
is added to the assembly — so machining requested by a connection lands on
|
|
11
|
+
the member geometry.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence, Union
|
|
18
|
+
|
|
19
|
+
from .geometry import Vec
|
|
20
|
+
from .layout import FrameLayout, Junction, JunctionEnd, MemberLayout
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
23
|
+
from .frame import FrameMember
|
|
24
|
+
|
|
25
|
+
# A member operation requested by a connection: called with the member's
|
|
26
|
+
# FrameMember Part (local coordinates: start at the origin, +X along the
|
|
27
|
+
# member, profile u / v = +Y / +Z) before the Part is added to the frame.
|
|
28
|
+
Machining = Callable[["FrameMember"], None]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class Placed:
|
|
33
|
+
"""A component and its placement in frame coordinates (a 4x4 matrix /
|
|
34
|
+
transform dict / translation accepted by ``Assembly.add_component``;
|
|
35
|
+
``None`` = the component's own origin)."""
|
|
36
|
+
|
|
37
|
+
component: Any
|
|
38
|
+
tf: Any = None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class Connection:
|
|
43
|
+
"""What a connector adds at one junction: ``components`` (``Placed`` or
|
|
44
|
+
bare components) and ``machining`` — ``(member, fn)`` pairs, ``member``
|
|
45
|
+
being a ``MemberLayout``, a ``JunctionEnd`` or a member index."""
|
|
46
|
+
|
|
47
|
+
components: Sequence[Union[Placed, Any]] = ()
|
|
48
|
+
machining: Sequence[tuple[Any, Machining]] = field(default_factory=tuple)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ConnectorRule:
|
|
52
|
+
"""Base class for connector rules; override what you need.
|
|
53
|
+
|
|
54
|
+
- ``choose_through(node, ends)``: index (into ``ends``) of the member that
|
|
55
|
+
runs through a butt / coped / multi node, or ``None`` for the frame's
|
|
56
|
+
default (arc, then longest, then first).
|
|
57
|
+
- ``prepare_member(part)``: called once per ``FrameMember`` before it is
|
|
58
|
+
placed (e.g. add slot anchors).
|
|
59
|
+
- ``connect(junction, layout)``: the hardware for one junction.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def choose_through(self, node: Vec, ends: Sequence[JunctionEnd]) -> Optional[int]:
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
def prepare_member(self, part: "FrameMember") -> None:
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
def connect(self, junction: Junction, layout: FrameLayout) -> Optional[Connection]:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
ConnectorLike = Union[ConnectorRule, Callable[[Junction], Optional[Connection]]]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class _CallableRule(ConnectorRule):
|
|
76
|
+
def __init__(self, fn: Callable[[Junction], Optional[Connection]]):
|
|
77
|
+
self.fn = fn
|
|
78
|
+
|
|
79
|
+
def connect(self, junction, layout):
|
|
80
|
+
return self.fn(junction)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def as_rule(connector: ConnectorLike | None) -> ConnectorRule | None:
|
|
84
|
+
if connector is None or isinstance(connector, ConnectorRule):
|
|
85
|
+
return connector
|
|
86
|
+
if callable(connector):
|
|
87
|
+
return _CallableRule(connector)
|
|
88
|
+
raise TypeError(
|
|
89
|
+
"connector must be a ConnectorRule or a callable(junction) -> Connection, "
|
|
90
|
+
f"got {type(connector).__name__}"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def member_index(ref: Any) -> int:
|
|
95
|
+
if isinstance(ref, JunctionEnd):
|
|
96
|
+
return ref.member.index
|
|
97
|
+
if isinstance(ref, MemberLayout):
|
|
98
|
+
return ref.index
|
|
99
|
+
if isinstance(ref, int):
|
|
100
|
+
return ref
|
|
101
|
+
raise TypeError(
|
|
102
|
+
f"machining target must be a MemberLayout, JunctionEnd or index, got {ref!r}"
|
|
103
|
+
)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Cut list: frame members grouped into identical cut pieces."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Sequence
|
|
7
|
+
|
|
8
|
+
from .geometry import Arc3D
|
|
9
|
+
from .layout import MemberLayout
|
|
10
|
+
|
|
11
|
+
# Lengths / angles are grouped after rounding to these.
|
|
12
|
+
LENGTH_DECIMALS = 1
|
|
13
|
+
ANGLE_DECIMALS = 1
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class CutListItem:
|
|
18
|
+
"""One cut-list row: ``count`` identical pieces of ``profile``.
|
|
19
|
+
|
|
20
|
+
``length`` is the overall (long-point to long-point) stock length in mm;
|
|
21
|
+
``end_angles`` the cut angle of each end from square, in degrees (0 =
|
|
22
|
+
square, 45 = a 90-degree corner miter); ``end_cuts`` how each end is
|
|
23
|
+
cut (``free``, ``miter``, ``butt``, ``through``, ``coped``,
|
|
24
|
+
``continuous``); ``bend_radius`` is set for bent (arc) members.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
item: int
|
|
28
|
+
profile: str
|
|
29
|
+
length: float
|
|
30
|
+
end_angles: tuple[float, float]
|
|
31
|
+
end_cuts: tuple[str, str]
|
|
32
|
+
count: int
|
|
33
|
+
members: tuple[str, ...]
|
|
34
|
+
bend_radius: float | None = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _row_key(m: MemberLayout):
|
|
38
|
+
ends = sorted(
|
|
39
|
+
[
|
|
40
|
+
(round(m.start.angle_deg, ANGLE_DECIMALS), m.start.kind),
|
|
41
|
+
(round(m.end.angle_deg, ANGLE_DECIMALS), m.end.kind),
|
|
42
|
+
]
|
|
43
|
+
)
|
|
44
|
+
radius = (
|
|
45
|
+
round(m.segment.radius, LENGTH_DECIMALS)
|
|
46
|
+
if isinstance(m.segment, Arc3D)
|
|
47
|
+
else None
|
|
48
|
+
)
|
|
49
|
+
return (
|
|
50
|
+
m.profile.designation,
|
|
51
|
+
round(m.cut_length, LENGTH_DECIMALS),
|
|
52
|
+
tuple(ends),
|
|
53
|
+
radius,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def cut_list(members: Sequence[MemberLayout]) -> list[CutListItem]:
|
|
58
|
+
groups: dict[tuple, list[MemberLayout]] = {}
|
|
59
|
+
for m in members:
|
|
60
|
+
groups.setdefault(_row_key(m), []).append(m)
|
|
61
|
+
rows = []
|
|
62
|
+
for i, (key, ms) in enumerate(groups.items()):
|
|
63
|
+
designation, length, ends, radius = key
|
|
64
|
+
rows.append(
|
|
65
|
+
CutListItem(
|
|
66
|
+
item=i + 1,
|
|
67
|
+
profile=designation,
|
|
68
|
+
length=length,
|
|
69
|
+
end_angles=(ends[0][0], ends[1][0]),
|
|
70
|
+
end_cuts=(ends[0][1], ends[1][1]),
|
|
71
|
+
count=len(ms),
|
|
72
|
+
members=tuple(m.name for m in ms),
|
|
73
|
+
bend_radius=radius,
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
return rows
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def format_cut_list(rows: Sequence[CutListItem]) -> str:
|
|
80
|
+
header = ("Item", "Qty", "Profile", "Length", "Angle 1", "Angle 2", "Ends")
|
|
81
|
+
lines = [header] + [
|
|
82
|
+
(
|
|
83
|
+
str(r.item),
|
|
84
|
+
str(r.count),
|
|
85
|
+
r.profile + (f" (bent R{r.bend_radius:g})" if r.bend_radius else ""),
|
|
86
|
+
f"{r.length:.1f}",
|
|
87
|
+
f"{r.end_angles[0]:.1f}",
|
|
88
|
+
f"{r.end_angles[1]:.1f}",
|
|
89
|
+
"/".join(r.end_cuts),
|
|
90
|
+
)
|
|
91
|
+
for r in rows
|
|
92
|
+
]
|
|
93
|
+
widths = [max(len(row[c]) for row in lines) for c in range(len(header))]
|
|
94
|
+
out = [
|
|
95
|
+
" ".join(cell.ljust(w) for cell, w in zip(row, widths)).rstrip()
|
|
96
|
+
for row in lines
|
|
97
|
+
]
|
|
98
|
+
out.insert(1, " ".join("-" * w for w in widths))
|
|
99
|
+
return "\n".join(out)
|