Skip to content

Commit 7a0793c

Browse files
autopep8 ctd
1 parent 7d7cb06 commit 7a0793c

File tree

4 files changed

+555
-486
lines changed

4 files changed

+555
-486
lines changed

solid/screw_thread.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ def thread(outline_pts, inner_rad, pitch, length, external=True, segments_per_ro
109109

110110
# create new points
111111
for p in euc_points:
112-
pt = (
113-
p + elev_vec).rotate_around(axis=euc_up, theta=radians(angle))
112+
pt = (p + elev_vec).rotate_around(axis=euc_up, theta=radians(angle))
114113
all_points.append(pt.as_arr())
115114

116115
# Add the connectivity information
@@ -119,10 +118,8 @@ def thread(outline_pts, inner_rad, pitch, length, external=True, segments_per_ro
119118
for j in range(ind, ind + poly_sides - 1):
120119
all_tris.append([j, j + 1, j + poly_sides])
121120
all_tris.append([j + 1, j + poly_sides + 1, j + poly_sides])
122-
all_tris.append(
123-
[ind, ind + poly_sides - 1 + poly_sides, ind + poly_sides - 1])
124-
all_tris.append(
125-
[ind, ind + poly_sides, ind + poly_sides - 1 + poly_sides])
121+
all_tris.append([ind, ind + poly_sides - 1 + poly_sides, ind + poly_sides - 1])
122+
all_tris.append([ind, ind + poly_sides, ind + poly_sides - 1 + poly_sides])
126123

127124
# End triangle fans for beginning and end
128125
last_loop = len(all_points) - poly_sides
@@ -136,8 +133,7 @@ def thread(outline_pts, inner_rad, pitch, length, external=True, segments_per_ro
136133
if external:
137134
# Intersect with a cylindrical tube to make sure we fit into
138135
# the correct dimensions
139-
tube = cylinder(
140-
r=inner_rad + outline_w + EPSILON, h=length, segments=segments_per_rot)
136+
tube = cylinder(r=inner_rad + outline_w + EPSILON, h=length, segments=segments_per_rot)
141137
tube -= cylinder(r=inner_rad, h=length, segments=segments_per_rot)
142138
else:
143139
# If the threading is internal, intersect with a central cylinder

solid/solidpython.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,7 @@ def parse_scad_callables(scad_code_str):
780780
else:
781781
args.append(arg_name)
782782

783-
callables.append(
784-
{'name': callable_name, 'args': args, 'kwargs': kwargs})
783+
callables.append({'name': callable_name, 'args': args, 'kwargs': kwargs})
785784

786785
return callables
787786

@@ -792,7 +791,6 @@ def parse_scad_callables(scad_code_str):
792791
if sym_dict['name'] in builtin_literals:
793792
class_str = builtin_literals[sym_dict['name']]
794793
else:
795-
class_str = new_openscad_class_str(
796-
sym_dict['name'], sym_dict['args'], sym_dict['kwargs'])
794+
class_str = new_openscad_class_str(sym_dict['name'], sym_dict['args'], sym_dict['kwargs'])
797795

798796
exec(class_str)

solid/t_slots.py

Lines changed: 91 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#! /usr/bin/env python
22
# -*- coding: utf-8 -*-
33
from __future__ import division
4-
import os, sys, re
4+
import os
5+
import sys
6+
import re
57

68
# Assumes SolidPython is in site-packages or elsewhwere in sys.path
79
from solid import *
@@ -10,7 +12,7 @@
1012
SEGMENTS = 24
1113

1214
# FIXME: ought to be 5
13-
DFM = 5 # Default Material thickness
15+
DFM = 5 # Default Material thickness
1416

1517
tab_width = 5
1618
tab_offset = 4
@@ -21,162 +23,171 @@
2123
# It might be easier to have the edges NOT overlap at all and then have tabs
2224
# for the slots added programmatically. -ETJ 06 Mar 2013
2325

24-
def t_slot_holes(poly, point=None, edge_vec=RIGHT_VEC, screw_vec=DOWN_VEC, screw_type='m3', screw_length=16, material_thickness=DFM, kerf=0 ):
26+
27+
def t_slot_holes(poly, point=None, edge_vec=RIGHT_VEC, screw_vec=DOWN_VEC, screw_type='m3', screw_length=16, material_thickness=DFM, kerf=0):
2528
'''
2629
Cuts a screw hole and two notches in poly so they'll
2730
interface with the features cut by t_slot()
28-
31+
2932
Returns a copy of poly with holes removed
30-
33+
3134
-- material_thickness is the thickness of the material *that will
3235
be attached** to the t-slot, NOT necessarily the material that poly
3336
will be cut on.
34-
37+
3538
-- screw_vec is the direction the screw through poly will face; normal to poly
3639
-- edge_vec orients the holes to the edge they run parallel to
37-
40+
3841
TODO: add kerf calculations
3942
'''
4043
point = point if point else ORIGIN
41-
point = euclidify(point, Point3)
44+
point = euclidify(point, Point3)
4245
screw_vec = euclidify(screw_vec, Vector3)
43-
edge_vec = euclidify(edge_vec, Vector3)
44-
45-
src_up = screw_vec.cross(edge_vec)
46-
47-
48-
a_hole = square( [tab_width, material_thickness], center=True)
49-
move_hole = tab_offset + tab_width/2
50-
tab_holes = left(move_hole)(a_hole) + right(move_hole)(a_hole)
51-
52-
46+
edge_vec = euclidify(edge_vec, Vector3)
47+
48+
src_up = screw_vec.cross(edge_vec)
49+
50+
a_hole = square([tab_width, material_thickness], center=True)
51+
move_hole = tab_offset + tab_width / 2
52+
tab_holes = left(move_hole)(a_hole) + right(move_hole)(a_hole)
53+
5354
# Only valid for m3-m5 screws now
5455
screw_dict = screw_dimensions.get(screw_type.lower())
5556
if screw_dict:
5657
screw_w = screw_dict['screw_outer_diam']
5758
else:
58-
raise ValueError( "Don't have screw dimensions for requested screw size %s"%screw_type)
59-
59+
raise ValueError(
60+
"Don't have screw dimensions for requested screw size %s" % screw_type)
61+
6062
# add the screw hole
61-
tab_holes += circle(screw_w/2) # NOTE: needs any extra space?
62-
63-
tab_holes = transform_to_point(tab_holes, point, dest_normal=screw_vec, src_normal=UP_VEC, src_up=src_up)
64-
63+
tab_holes += circle(screw_w / 2) # NOTE: needs any extra space?
64+
65+
tab_holes = transform_to_point(
66+
tab_holes, point, dest_normal=screw_vec, src_normal=UP_VEC, src_up=src_up)
67+
6568
return poly - tab_holes
6669

67-
def t_slot( poly, point=None, screw_vec=DOWN_VEC, face_normal=UP_VEC, screw_type='m3', screw_length=16, material_thickness=DFM, kerf=0 ):
70+
71+
def t_slot(poly, point=None, screw_vec=DOWN_VEC, face_normal=UP_VEC, screw_type='m3', screw_length=16, material_thickness=DFM, kerf=0):
6872
'''
6973
Cuts a t-shaped shot in poly and adds two tabs
7074
on the outside edge of poly.
71-
75+
7276
Needs to be combined with t_slot_holes() on another
7377
poly to make a valid t-slot connection
74-
78+
7579
-- material_thickness is the thickness of the material *that will
7680
be attached** to the t-slot, NOT necessarily the material that poly
7781
will be cut on.
78-
82+
7983
-- This method will align the t-slots where you tell them to go,
8084
using point, screw_vec (the direction the screw will be inserted), and
8185
face_normal, a vector normal to the face being altered. To avoid confusion,
8286
it's often easiest to work on the XY plane.
83-
84-
87+
88+
8589
TODO: include kerf in calculations
8690
'''
8791
point = point if point else ORIGIN
8892
point = euclidify(point, Point3)
89-
screw_vec = euclidify(screw_vec, Vector3)
93+
screw_vec = euclidify(screw_vec, Vector3)
9094
face_normal = euclidify(face_normal, Vector3)
9195

9296
tab = tab_poly(material_thickness=material_thickness)
93-
slot = nut_trap_slot(screw_type, screw_length, material_thickness=material_thickness)
94-
97+
slot = nut_trap_slot(
98+
screw_type, screw_length, material_thickness=material_thickness)
99+
95100
# NOTE: dest_normal & src_normal are the same. This should matter, right?
96-
tab = transform_to_point(tab, point, dest_normal=face_normal, src_normal=face_normal, src_up=-screw_vec)
97-
slot = transform_to_point(slot, point, dest_normal=face_normal, src_normal=face_normal, src_up=-screw_vec)
98-
101+
tab = transform_to_point(
102+
tab, point, dest_normal=face_normal, src_normal=face_normal, src_up=-screw_vec)
103+
slot = transform_to_point(
104+
slot, point, dest_normal=face_normal, src_normal=face_normal, src_up=-screw_vec)
105+
99106
return poly + tab - slot
100-
107+
108+
101109
def tab_poly(material_thickness=DFM):
102-
103-
r = [ [ tab_width + tab_offset, -EPSILON],
104-
[ tab_offset, -EPSILON],
105-
[ tab_offset, material_thickness],
106-
[ tab_width + tab_offset, material_thickness],]
107-
108-
l = [ [-rp[0], rp[1]] for rp in r]
110+
111+
r = [[tab_width + tab_offset, -EPSILON],
112+
[tab_offset, -EPSILON],
113+
[tab_offset, material_thickness],
114+
[tab_width + tab_offset, material_thickness], ]
115+
116+
l = [[-rp[0], rp[1]] for rp in r]
109117
tab_pts = l + r
110118

111-
tab_faces = [[0,1,2,3], [4,5,6,7]]
119+
tab_faces = [[0, 1, 2, 3], [4, 5, 6, 7]]
112120
tab = polygon(tab_pts, tab_faces)
113-
121+
114122
# Round off the top points so tabs slide in more easily
115123
round_tabs = False
116124
if round_tabs:
117-
points_to_round = [ [r[1], r[2], r[3]],
118-
[r[2], r[3], r[0]],
119-
[l[1], l[2], l[3]],
120-
[l[2], l[3], l[0]],
121-
]
122-
tab = fillet_2d(three_point_sets=points_to_round, orig_poly=tab,
123-
fillet_rad=1, remove_material=True)
124-
125+
points_to_round = [[r[1], r[2], r[3]],
126+
[r[2], r[3], r[0]],
127+
[l[1], l[2], l[3]],
128+
[l[2], l[3], l[0]],
129+
]
130+
tab = fillet_2d(three_point_sets=points_to_round, orig_poly=tab,
131+
fillet_rad=1, remove_material=True)
132+
125133
return tab
126134

127135

128136
def nut_trap_slot(screw_type='m3', screw_length=16, material_thickness=DFM):
129137
# This shape has a couple uses.
130138
# 1) Right angle joint between two pieces of material.
131-
# A bolt goes through the second piece and into the first.
132-
133-
# 2) Set-screw for attaching to motor spindles.
139+
# A bolt goes through the second piece and into the first.
140+
141+
# 2) Set-screw for attaching to motor spindles.
134142
# Bolt goes full length into a sheet of material. Set material_thickness
135-
# to something small (1-2 mm) to make sure there's adequate room to
143+
# to something small (1-2 mm) to make sure there's adequate room to
136144
# tighten onto the shaft
137-
138-
145+
139146
# Only valid for m3-m5 screws now
140147
screw_dict = screw_dimensions.get(screw_type.lower())
141148
if screw_dict:
142149
screw_w = screw_dict['screw_outer_diam']
143-
screw_w2 = screw_w/2
144-
nut_hole_x = (screw_dict[ 'nut_inner_diam'] + 0.2)/2 # NOTE: How are these tolerances?
150+
screw_w2 = screw_w / 2
151+
# NOTE: How are these tolerances?
152+
nut_hole_x = (screw_dict['nut_inner_diam'] + 0.2) / 2
145153
nut_hole_h = screw_dict['nut_thickness'] + 0.5
146154
slot_depth = material_thickness - screw_length - 0.5
147155
# If a nut isn't far enough into the material, the sections
148156
# that hold the nut in may break off. Make sure it's at least
149157
# half a centimeter. More would be better, actually
150158
nut_loc = -5
151159
else:
152-
raise ValueError( "Don't have screw dimensions for requested screw size %s"%screw_type)
153-
154-
slot_pts = [[ screw_w2, EPSILON ],
155-
[ screw_w2, nut_loc],
156-
[ nut_hole_x, nut_loc],
157-
[ nut_hole_x, nut_loc - nut_hole_h],
158-
[ screw_w2, nut_loc - nut_hole_h],
159-
[ screw_w2, slot_depth],
160+
raise ValueError(
161+
"Don't have screw dimensions for requested screw size %s" % screw_type)
162+
163+
slot_pts = [[screw_w2, EPSILON],
164+
[screw_w2, nut_loc],
165+
[nut_hole_x, nut_loc],
166+
[nut_hole_x, nut_loc - nut_hole_h],
167+
[screw_w2, nut_loc - nut_hole_h],
168+
[screw_w2, slot_depth],
160169
]
161170
# mirror the slot points on the left
162-
slot_pts += [[-x, y] for x,y in slot_pts][ -1::-1]
163-
171+
slot_pts += [[-x, y] for x, y in slot_pts][-1::-1]
172+
164173
# TODO: round off top corners of slot
165-
174+
166175
# Add circles around t edges to prevent acrylic breakage
167176
slot = polygon(slot_pts)
168177
slot = union()(
169-
slot,
170-
translate( [nut_hole_x, nut_loc])(circle(tab_curve_rad)),
171-
translate( [-nut_hole_x, nut_loc])(circle(tab_curve_rad))
172-
)
178+
slot,
179+
translate([nut_hole_x, nut_loc])(circle(tab_curve_rad)),
180+
translate([-nut_hole_x, nut_loc])(circle(tab_curve_rad))
181+
)
173182
return render()(slot)
174183

184+
175185
def assembly():
176186
a = union()
177-
187+
178188
return a
179189

180190
if __name__ == '__main__':
181-
a = assembly()
182-
scad_render_to_file(a, file_header='$fn = %s;'%SEGMENTS, include_orig_code=True)
191+
a = assembly()
192+
scad_render_to_file(a, file_header='$fn = %s;' %
193+
SEGMENTS, include_orig_code=True)

0 commit comments

Comments
 (0)