99
1010from . import utils
1111
12+ unitmm = fc .Units .Quantity ("1 mm" )
1213
13- def _crush_ribs (
14- radius : fc .Units .Quantity ,
15- depth : fc .Units .Quantity ,
16- * ,
17- n : int ,
18- beta : float ,
19- ) -> Part .Shape :
20- """Make crush ribs inner shape.
14+
15+ def _crush_ribs (radius : fc .Units .Quantity , * , n : int , beta : float ) -> tuple [Part .Face , float ]:
16+ """Make crush ribs inner face.
2117
2218 Args:
2319 radius (fc.Units.Quantity): Inner radius.
24- depth (fc.Units.Quantity): Depth.
2520 n (int): Number of ribs.
2621 beta (float): Waviness of the ribs. It is the angle at wich inner at outer arcs meet.
2722 A value of 0 would result in a perfect circle.
@@ -52,14 +47,10 @@ def get_midpoint(beta: float) -> float:
5247 math .degrees ((i + 0.5 ) / len (lines ) * 2 * math .pi ),
5348 )
5449 arc .rotate (placement )
55- wire = utils .curve_to_wire (lines )
56- face = Part .Face (wire )
57- shape = face .extrude (fc .Vector (0 , 0 , depth ))
58-
59- return shape
50+ return utils .curve_to_face (lines ), r3 - r1
6051
6152
62- def _hex_shape (radius : fc .Units .Quantity , depth : fc . Units . Quantity ) -> Part .Shape :
53+ def _hex_shape (radius : fc .Units .Quantity ) -> Part .Shape :
6354 # Ratio of 2/sqrt(3) converts from inscribed circle radius to circumscribed
6455 # circle radius
6556 radius = 2 * radius / math .sqrt (3 )
@@ -70,7 +61,7 @@ def _hex_shape(radius: fc.Units.Quantity, depth: fc.Units.Quantity) -> Part.Shap
7061 p .recompute ()
7162
7263 p_wire : Part .Wire = p .Shape
73- shape = Part .Face (p_wire ). extrude ( fc . Vector ( 0 , 0 , depth ))
64+ shape = Part .Face (p_wire )
7465 fc .ActiveDocument .removeObject (p .Name )
7566 return shape
7667
@@ -83,25 +74,31 @@ def from_obj(obj: fc.DocumentObject) -> Part.Shape:
8374 hole_shape = obj .MagnetHolesShape
8475 radius = obj .MagnetHoleDiameter / 2
8576 depth = obj .MagnetHoleDepth
77+ chamfer_depth = depth / 8
8678
8779 if hole_shape == "Hex" :
88- shape = _hex_shape (radius , depth )
80+ shape = _hex_shape (radius )
81+ chamfer_width = (2 / math .sqrt (3 ) - 1 ) * radius
8982 elif hole_shape == "Crush ribs" :
90- shape = _crush_ribs (radius , depth , n = 8 , beta = 0.5 * math .pi / 2 )
83+ shape , ch = _crush_ribs (radius , n = 8 , beta = 0.5 * math .pi / 2 )
84+ chamfer_width = ch * unitmm
9185 elif hole_shape == "Round" :
92- shape = Part .makeCylinder (radius , depth )
93- if obj .Baseplate :
94- chamfer = obj .MagnetChamfer
95- chamfer_shape = utils .round_chamfer (
96- radius ,
97- radius + chamfer ,
98- chamfer ,
99- pPnt = fc .Vector (0 , 0 , depth - chamfer ),
100- )
101- shape = shape .fuse (chamfer_shape )
86+ shape = Part .Face (Part .Wire (Part .makeCircle (radius )))
87+ chamfer_width = chamfer_depth
10288 else :
10389 raise ValueError (f"Unrecognised magnet hole shape { hole_shape :!r} " )
10490
91+ shape = shape .extrude (fc .Vector (0 , 0 , depth ))
92+
93+ if obj .Baseplate :
94+ chamfer_shape = utils .round_chamfer (
95+ radius ,
96+ radius + chamfer_width ,
97+ chamfer_depth ,
98+ pPnt = fc .Vector (0 , 0 , depth - chamfer_depth ),
99+ )
100+ shape = shape .fuse (chamfer_shape )
101+
105102 return shape
106103
107104
@@ -125,8 +122,7 @@ def relief(obj: fc.DocumentObject) -> Part.Shape:
125122 Part .LineSegment (p4 , p5 ),
126123 Part .LineSegment (p5 , p1 ),
127124 ]
128- wire = utils .curve_to_wire (lines )
129- face = Part .Face (wire )
125+ face = utils .curve_to_face (lines )
130126 shape = face .extrude (fc .Vector (0 , 0 , obj .MagnetHoleDepth ))
131127
132128 positions = [
0 commit comments