Skip to content

Commit

Permalink
Rename teeth property to num_teeth
Browse files Browse the repository at this point in the history
  • Loading branch information
hasecilu authored and looooo committed Oct 5, 2024
1 parent a7f6d06 commit da3c851
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 67 deletions.
6 changes: 3 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#TODO:
# TODO

## refactoring

- [ ] fp.gear.z -> fp.gear.num_teeth
- [ ] fp.teeth -> fp.gear.num_teeth
- [X] fp.gear.z -> fp.gear.num_teeth
- [X] fp.teeth -> fp.gear.num_teeth
17 changes: 17 additions & 0 deletions freecad/gears/basegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ def execute(self, fp):
if not hasattr(fp, "positionBySupport"):
self.make_attachable(fp)
fp.positionBySupport()

# Backward compatibility for old files
if hasattr(fp, "teeth"):
fp.addProperty(
"App::PropertyInteger",
"num_teeth",
"base",
"number of teeth",
)
app.Console.PrintLog(
app.Qt.translate(
"Log", "Migrating 'teeth' property to 'num_teeth' on {} part\n"
).format(fp.Name)
)
fp.num_teeth = fp.teeth # Copy old value to new property
fp.removeProperty("teeth") # Remove the old property

gear_shape = self.generate_gear_shape(fp)
if hasattr(fp, "BaseFeature") and fp.BaseFeature != None:
# we're inside a PartDesign Body, thus need to fuse with the base feature
Expand Down
26 changes: 14 additions & 12 deletions freecad/gears/bevelgear.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


class BevelGear(BaseGear):

"""parameters:
pressure_angle: pressureangle, 10-30°
pitch_angle: cone angle, 0 < pitch_angle < pi/4
Expand All @@ -39,7 +38,7 @@ def __init__(self, obj):
self.bevel_tooth = BevelTooth()
obj.addProperty(
"App::PropertyInteger",
"teeth",
"num_teeth",
"base",
translate("BevelGear", "number of teeth"),
)
Expand Down Expand Up @@ -116,7 +115,7 @@ def __init__(self, obj):
translate("BevelGear", "The pitch diameter."),
)
obj.setExpression(
"dw", "teeth * module"
"dw", "num_teeth * module"
) # calculate via expression to ease usage for placement
obj.setEditorMode(
"dw", 1
Expand All @@ -136,9 +135,10 @@ def __init__(self, obj):
obj.setEditorMode(
"angular_backlash", 1
) # set read-only after setting the expression, else it won't be visible. bug?

obj.gear = self.bevel_tooth
obj.module = "1. mm"
obj.teeth = 15
obj.num_teeth = 15
obj.pressure_angle = "20. deg"
obj.pitch_angle = "45. deg"
obj.height = "5. mm"
Expand All @@ -151,28 +151,30 @@ def __init__(self, obj):
obj.Proxy = self

def generate_gear_shape(self, fp):
fp.gear.z = fp.teeth
fp.gear.module = fp.module.Value
fp.gear.pressure_angle = (90 - fp.pressure_angle.Value) * np.pi / 180.0
fp.gear.pitch_angle = fp.pitch_angle.Value * np.pi / 180
max_height = fp.gear.module * fp.teeth / 2 / np.tan(fp.gear.pitch_angle)
max_height = fp.gear.module * fp.num_teeth / 2 / np.tan(fp.gear.pitch_angle)
if fp.height >= max_height:
app.Console.PrintWarning(
"height must be smaller than {}".format(max_height)
)
fp.gear.backlash = fp.backlash.Value
scale = (
fp.module.Value * fp.gear.z / 2 / np.tan(fp.pitch_angle.Value * np.pi / 180)
fp.module.Value
* fp.num_teeth
/ 2
/ np.tan(fp.pitch_angle.Value * np.pi / 180)
)
fp.gear.clearance = fp.clearance / scale
fp.gear._update()
pts = list(fp.gear.points(num=fp.numpoints))
rot = rotation3D(-2 * np.pi / fp.teeth)
rot = rotation3D(-2 * np.pi / fp.num_teeth)
# if fp.beta.Value != 0:
# pts = [np.array([self.spherical_rot(j, fp.beta.Value * np.pi / 180.) for j in i]) for i in pts]

rotated_pts = pts
for i in range(fp.gear.z - 1):
for i in range(fp.num_teeth - 1):
rotated_pts = list(map(rot, rotated_pts))
pts.append(np.array([pts[-1][-1], rotated_pts[0][0]]))
pts += rotated_pts
Expand Down Expand Up @@ -211,20 +213,20 @@ def generate_gear_shape(self, fp):
mat.move(fcvec([0, 0, scale_1]))
shape = shape.transformGeometry(mat)
return shape
# return self.create_teeth(pts, pos1, fp.teeth)
# return self.create_teeth(pts, pos1, fp.num_teeth)

def create_tooth(self):
w = []
scal1 = (
self.obj.m.Value
* self.obj.gear.z
* self.obj.num_teeth
/ 2
/ np.tan(self.obj.pitch_angle.Value * np.pi / 180)
- self.obj.height.Value / 2
)
scal2 = (
self.obj.m.Value
* self.obj.gear.z
* self.obj.num_teeth
/ 2
/ np.tan(self.obj.pitch_angle.Value * np.pi / 180)
+ self.obj.height.Value / 2
Expand Down
8 changes: 4 additions & 4 deletions freecad/gears/crowngear.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, obj):
super(CrownGear, self).__init__(obj)
obj.addProperty(
"App::PropertyInteger",
"teeth",
"num_teeth",
"base",
translate("CrownGear", "number of teeth"),
)
Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(self, obj):
translate("CrownGear", "pressure angle"),
)
self.add_accuracy_properties(obj)
obj.teeth = 15
obj.num_teeth = 15
obj.other_teeth = 15
obj.module = "1. mm"
obj.pressure_angle = "20. deg"
Expand Down Expand Up @@ -135,7 +135,7 @@ def profile(self, m, r, r0, t_c, t_i, alpha_w, y0, y1, y2):
return pts

def generate_gear_shape(self, fp):
inner_diameter = fp.module.Value * fp.teeth
inner_diameter = fp.module.Value * fp.num_teeth
outer_diameter = inner_diameter + fp.height.Value * 2
inner_circle = part.Wire(part.makeCircle(inner_diameter / 2.0))
outer_circle = part.Wire(part.makeCircle(outer_diameter / 2.0))
Expand All @@ -148,7 +148,7 @@ def generate_gear_shape(self, fp):
# cutting obj
alpha_w = np.deg2rad(fp.pressure_angle.Value)
m = fp.module.Value
t = fp.teeth
t = fp.num_teeth
t_c = t
t_i = fp.other_teeth
rm = inner_diameter / 2
Expand Down
15 changes: 7 additions & 8 deletions freecad/gears/cycloidgear.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, obj):
self.cycloid_tooth = CycloidTooth()
obj.addProperty(
"App::PropertyInteger",
"teeth",
"num_teeth",
"base",
translate("CycloidGear", "number of teeth"),
)
Expand Down Expand Up @@ -76,11 +76,11 @@ def __init__(self, obj):
self.add_cycloid_properties(obj)
self.add_computed_properties(obj)
obj.gear = self.cycloid_tooth
obj.teeth = 15
obj.num_teeth = 15
obj.module = "1. mm"
obj.setExpression(
"inner_diameter", "teeth / 2"
) # teeth/2 makes the hypocycloid a straight line to the center
"inner_diameter", "num_teeth / 2"
) # num_teeth/2 makes the hypocycloid a straight line to the center
obj.outer_diameter = 7.5 # we don't know the mating gear, so we just set the default to mesh with our default
obj.beta = "0. deg"
obj.height = "5. mm"
Expand Down Expand Up @@ -174,7 +174,7 @@ def add_computed_properties(self, obj):
translate("CycloidGear", "The pitch diameter."),
)
obj.setExpression(
"dw", "teeth * module"
"dw", "num_teeth * module"
) # calculate via expression to ease usage for placement
obj.setEditorMode(
"dw", 1
Expand All @@ -197,8 +197,7 @@ def add_computed_properties(self, obj):

def generate_gear_shape(self, fp):
fp.gear.m = fp.module.Value
fp.gear.z = fp.teeth
fp.dw = fp.module * fp.teeth
fp.dw = fp.module * fp.num_teeth
fp.gear.z1 = fp.inner_diameter
fp.gear.z2 = fp.outer_diameter
fp.gear.clearance = fp.clearance
Expand Down Expand Up @@ -232,7 +231,7 @@ def generate_gear_shape(self, fp):

tooth = part.Wire(edges)

profile = rotate_tooth(tooth, fp.teeth)
profile = rotate_tooth(tooth, fp.num_teeth)
if fp.height.Value == 0:
return profile
base = part.Face(profile)
Expand Down
11 changes: 5 additions & 6 deletions freecad/gears/cycloidgearrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@


class CycloidGearRack(BaseGear):

"""FreeCAD gear rack"""

def __init__(self, obj):
super(CycloidGearRack, self).__init__(obj)
obj.addProperty(
"App::PropertyInteger",
"teeth",
"num_teeth",
"base",
translate("CycloidGearRack", "number of teeth"),
)
Expand Down Expand Up @@ -81,7 +80,7 @@ def __init__(self, obj):
self.add_tolerance_properties(obj)
self.add_cycloid_properties(obj)
self.add_fillet_properties(obj)
obj.teeth = 15
obj.num_teeth = 15
obj.module = "1. mm"
obj.inner_diameter = 7.5
obj.outer_diameter = 7.5
Expand Down Expand Up @@ -124,7 +123,7 @@ def add_computed_properties(self, obj):
"base",
translate(
"CycloidGearRack",
"if enabled the total length of the rack is teeth x pitch, otherwise the rack starts with a tooth-flank",
"if enabled the total length of the rack is num_teeth x pitch, otherwise the rack starts with a tooth-flank",
),
)

Expand Down Expand Up @@ -224,7 +223,7 @@ def generate_gear_shape(self, obj):
tooth = part.Wire(tooth_edges[1:-1] + edge)
teeth = [tooth]

for i in range(obj.teeth - 1):
for i in range(obj.num_teeth - 1):
tooth = tooth.copy()
tooth.translate(app.Vector(0, np.pi * m, 0))
teeth.append(tooth)
Expand All @@ -234,7 +233,7 @@ def generate_gear_shape(self, obj):
if obj.add_endings:
teeth = [part.Wire(tooth_edges[0])] + teeth
last_edge = tooth_edges[-1]
last_edge.translate(app.Vector(0, np.pi * m * (obj.teeth - 1), 0))
last_edge.translate(app.Vector(0, np.pi * m * (obj.num_teeth - 1), 0))
teeth = teeth + [part.Wire(last_edge)]

p_start = np.array(teeth[0].Edges[0].firstVertex().Point[:-1])
Expand Down
7 changes: 3 additions & 4 deletions freecad/gears/internalinvolutegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, obj):
)
obj.addProperty(
"App::PropertyInteger",
"teeth",
"num_teeth",
"base",
translate("InternalInvoluteGear", "number of teeth"),
)
Expand Down Expand Up @@ -99,7 +99,7 @@ def __init__(self, obj):

obj.gear = self.involute_tooth
obj.simple = False
obj.teeth = 15
obj.num_teeth = 15
obj.module = "1. mm"
obj.shift = 0.0
obj.pressure_angle = "20. deg"
Expand Down Expand Up @@ -263,7 +263,6 @@ def add_helical_properties(self, obj):
def generate_gear_shape(self, fp):
fp.gear.double_helix = fp.double_helix
fp.gear.m_n = fp.module.Value
fp.gear.z = fp.teeth
fp.gear.undercut = False # no undercut for internal gears
fp.gear.shift = fp.shift
fp.gear.pressure_angle = fp.pressure_angle.Value * np.pi / 180.0
Expand Down Expand Up @@ -327,7 +326,7 @@ def generate_gear_shape(self, fp):
edges = [e for e in edges if e is not None]

tooth = part.Wire(edges)
profile = rotate_tooth(tooth, fp.teeth)
profile = rotate_tooth(tooth, fp.num_teeth)
if fp.height.Value == 0:
return part.makeCompound([outer_circle, profile])
base = part.Face([outer_circle, profile])
Expand Down
8 changes: 3 additions & 5 deletions freecad/gears/involutegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@


class InvoluteGear(BaseGear):

"""FreeCAD gear"""

def __init__(self, obj):
Expand All @@ -60,7 +59,7 @@ def __init__(self, obj):
obj.gear = self.involute_tooth
obj.simple = False
obj.undercut = False
obj.teeth = 15
obj.num_teeth = 15
obj.module = "1. mm"
obj.shift = 0.0
obj.pressure_angle = "20. deg"
Expand All @@ -82,7 +81,7 @@ def __init__(self, obj):
def add_gear_properties(self, obj):
obj.addProperty(
"App::PropertyInteger",
"teeth",
"num_teeth",
"base",
translate("InvoluteGear", "number of teeth"),
)
Expand Down Expand Up @@ -280,7 +279,6 @@ def compute_traverse_properties(self, obj):
def generate_gear_shape(self, obj):
obj.gear.double_helix = obj.double_helix
obj.gear.m_n = obj.module.Value
obj.gear.z = obj.teeth
obj.gear.undercut = obj.undercut
obj.gear.shift = obj.shift
obj.gear.pressure_angle = obj.pressure_angle.Value * np.pi / 180.0
Expand Down Expand Up @@ -337,7 +335,7 @@ def generate_gear_shape(self, obj):
edges = [e for e in edges if e is not None]

tooth = part.Wire(edges)
profile = rotate_tooth(tooth, obj.teeth)
profile = rotate_tooth(tooth, obj.num_teeth)

if obj.height.Value == 0:
return profile
Expand Down
Loading

0 comments on commit da3c851

Please sign in to comment.