|
11 | 11 | @author: jrm |
12 | 12 | """ |
13 | 13 | from math import pi |
14 | | -from typing import Any, ClassVar, Optional |
| 14 | +from typing import Any, ClassVar, Optional, Union |
15 | 15 |
|
16 | 16 | from atom.api import ( |
| 17 | + Atom, |
17 | 18 | Bool, |
18 | 19 | Coerced, |
19 | 20 | Dict, |
| 21 | + Enum, |
20 | 22 | Event, |
21 | 23 | Float, |
22 | 24 | FloatRange, |
@@ -246,6 +248,43 @@ def set_itx(self, itx): |
246 | 248 | raise NotImplementedError |
247 | 249 |
|
248 | 250 |
|
| 251 | +class HoleEdgeStyle(Atom): |
| 252 | + kind = Enum("chamfer", "cone") |
| 253 | + distance = Float(strict=False) |
| 254 | + distance2 = Float(strict=False) |
| 255 | + |
| 256 | + def __init__(self, *args, **kwargs): |
| 257 | + if len(args) == 1 and isinstance(args[0], tuple): |
| 258 | + value = args[0] |
| 259 | + n = len(value) |
| 260 | + if n == 3: |
| 261 | + kind, distance, distance2 = value |
| 262 | + super().__init__(kind=kind, distance=distance, distance2=distance2) |
| 263 | + return |
| 264 | + elif n == 2: |
| 265 | + kind, distance = value |
| 266 | + super().__init__(kind=kind, distance=distance) |
| 267 | + return |
| 268 | + super().__init__(*args, **kwargs) |
| 269 | + |
| 270 | + |
| 271 | +class ProxyHole(ProxyShape): |
| 272 | + #: A reference to the shape declaration. |
| 273 | + declaration = ForwardTyped(lambda: Hole) |
| 274 | + |
| 275 | + def set_diameter(self, diameter: float): |
| 276 | + raise NotImplementedError |
| 277 | + |
| 278 | + def set_depth(self, depth: float): |
| 279 | + raise NotImplementedError |
| 280 | + |
| 281 | + def set_top_edge(self, value: HoleEdgeStyle): |
| 282 | + raise NotImplementedError |
| 283 | + |
| 284 | + def set_bottom_edge(self, value: HoleEdgeStyle): |
| 285 | + raise NotImplementedError |
| 286 | + |
| 287 | + |
249 | 288 | class ProxyRevol(ProxyShape): |
250 | 289 | #: A reference to the shape declaration. |
251 | 290 | declaration = ForwardTyped(lambda: Revol) |
@@ -1045,6 +1084,52 @@ def _update_proxy(self, change: dict[str, Any]): |
1045 | 1084 | super(Wedge, self)._update_proxy(change) |
1046 | 1085 |
|
1047 | 1086 |
|
| 1087 | +class Hole(Shape): |
| 1088 | + """A primitive Hole shape. |
| 1089 | +
|
| 1090 | + Attributes |
| 1091 | + ---------- |
| 1092 | +
|
| 1093 | + diameter: Float |
| 1094 | + The diameter of the hole. |
| 1095 | + depth: Float |
| 1096 | + The depth of the hole. |
| 1097 | + top_edge: Float | Tuple[Float, Float] |
| 1098 | + If negative, add a chamfer to the top of the hole. If positive add a cone. |
| 1099 | + bottom_edge: Float | Tuple[Float, Float] |
| 1100 | + If negative, add a chamfer on the bottom of the hole. If positive add a cone. |
| 1101 | +
|
| 1102 | + Examples |
| 1103 | + -------- |
| 1104 | +
|
| 1105 | + Hole: |
| 1106 | + diameter = 4 |
| 1107 | + depth = 20 |
| 1108 | + top_edge = ('chamfer', 0.5) |
| 1109 | + bottom_edge =('cone', 0.5) |
| 1110 | +
|
| 1111 | + """ |
| 1112 | + |
| 1113 | + #: Proxy shape |
| 1114 | + proxy = Typed(ProxyHole) |
| 1115 | + |
| 1116 | + #: Hole diameter |
| 1117 | + diameter = d_(Float(1, strict=False)).tag(view=True) |
| 1118 | + |
| 1119 | + #: Hole depth |
| 1120 | + depth = d_(Float(1, strict=False)).tag(view=True) |
| 1121 | + |
| 1122 | + #: Top edge style |
| 1123 | + top_edge = d_(Coerced(HoleEdgeStyle)) |
| 1124 | + |
| 1125 | + #: Bottom chamfer of the hole |
| 1126 | + bottom_edge = d_(Coerced(HoleEdgeStyle)) |
| 1127 | + |
| 1128 | + @observe("diameter", "depth", "top_edge", "bottom_edge") |
| 1129 | + def _update_proxy(self, change: dict[str, Any]): |
| 1130 | + super()._update_proxy(change) |
| 1131 | + |
| 1132 | + |
1048 | 1133 | class Revol(Shape): |
1049 | 1134 | """A Revol creates a shape by revolving a profile about an axis. |
1050 | 1135 |
|
|
0 commit comments