From da3c851d2cf0b2f676c822ddf9efee7892b8aa51 Mon Sep 17 00:00:00 2001 From: hasecilu Date: Thu, 12 Sep 2024 16:07:20 -0600 Subject: [PATCH] Rename `teeth` property to `num_teeth` --- TODO.md | 6 +++--- freecad/gears/basegear.py | 17 +++++++++++++++++ freecad/gears/bevelgear.py | 26 ++++++++++++++------------ freecad/gears/crowngear.py | 8 ++++---- freecad/gears/cycloidgear.py | 15 +++++++-------- freecad/gears/cycloidgearrack.py | 11 +++++------ freecad/gears/internalinvolutegear.py | 7 +++---- freecad/gears/involutegear.py | 8 +++----- freecad/gears/involutegearrack.py | 13 ++++++------- freecad/gears/lanterngear.py | 6 +++--- freecad/gears/timinggear.py | 16 ++++++++-------- freecad/gears/timinggear_t.py | 6 +++--- freecad/gears/wormgear.py | 7 +++---- 13 files changed, 79 insertions(+), 67 deletions(-) diff --git a/TODO.md b/TODO.md index 2b9fa56..23e3e70 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ -#TODO: +# TODO ## refactoring -- [ ] fp.gear.z -> fp.gear.num_teeth -- [ ] fp.teeth -> fp.gear.num_teeth \ No newline at end of file +- [X] fp.gear.z -> fp.gear.num_teeth +- [X] fp.teeth -> fp.gear.num_teeth diff --git a/freecad/gears/basegear.py b/freecad/gears/basegear.py index b488056..4623a36 100644 --- a/freecad/gears/basegear.py +++ b/freecad/gears/basegear.py @@ -124,6 +124,23 @@ class BaseGear: 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 diff --git a/freecad/gears/bevelgear.py b/freecad/gears/bevelgear.py index 23fee4f..48d1bf3 100644 --- a/freecad/gears/bevelgear.py +++ b/freecad/gears/bevelgear.py @@ -28,7 +28,6 @@ from .basegear import BaseGear, fcvec, make_bspline_wire class BevelGear(BaseGear): - """parameters: pressure_angle: pressureangle, 10-30° pitch_angle: cone angle, 0 < pitch_angle < pi/4 @@ -39,7 +38,7 @@ class BevelGear(BaseGear): self.bevel_tooth = BevelTooth() obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("BevelGear", "number of teeth"), ) @@ -116,7 +115,7 @@ class BevelGear(BaseGear): 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 @@ -136,9 +135,10 @@ class BevelGear(BaseGear): 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" @@ -151,28 +151,30 @@ class BevelGear(BaseGear): 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 @@ -211,20 +213,20 @@ class BevelGear(BaseGear): 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 diff --git a/freecad/gears/crowngear.py b/freecad/gears/crowngear.py index 888da35..8903207 100644 --- a/freecad/gears/crowngear.py +++ b/freecad/gears/crowngear.py @@ -38,7 +38,7 @@ class CrownGear(BaseGear): super(CrownGear, self).__init__(obj) obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("CrownGear", "number of teeth"), ) @@ -73,7 +73,7 @@ class CrownGear(BaseGear): 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" @@ -135,7 +135,7 @@ class CrownGear(BaseGear): 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)) @@ -148,7 +148,7 @@ class CrownGear(BaseGear): # 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 diff --git a/freecad/gears/cycloidgear.py b/freecad/gears/cycloidgear.py index 27c16cc..4e93d97 100644 --- a/freecad/gears/cycloidgear.py +++ b/freecad/gears/cycloidgear.py @@ -41,7 +41,7 @@ class CycloidGear(BaseGear): self.cycloid_tooth = CycloidTooth() obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("CycloidGear", "number of teeth"), ) @@ -76,11 +76,11 @@ class CycloidGear(BaseGear): 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" @@ -174,7 +174,7 @@ class CycloidGear(BaseGear): 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 @@ -197,8 +197,7 @@ class CycloidGear(BaseGear): 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 @@ -232,7 +231,7 @@ class CycloidGear(BaseGear): 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) diff --git a/freecad/gears/cycloidgearrack.py b/freecad/gears/cycloidgearrack.py index cedd664..8f68f62 100644 --- a/freecad/gears/cycloidgearrack.py +++ b/freecad/gears/cycloidgearrack.py @@ -30,14 +30,13 @@ from .basegear import BaseGear, fcvec, points_to_wire, insert_fillet 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"), ) @@ -81,7 +80,7 @@ class CycloidGearRack(BaseGear): 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 @@ -124,7 +123,7 @@ class CycloidGearRack(BaseGear): "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", ), ) @@ -224,7 +223,7 @@ class CycloidGearRack(BaseGear): 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) @@ -234,7 +233,7 @@ class CycloidGearRack(BaseGear): 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]) diff --git a/freecad/gears/internalinvolutegear.py b/freecad/gears/internalinvolutegear.py index 05d1aa8..44ec10a 100644 --- a/freecad/gears/internalinvolutegear.py +++ b/freecad/gears/internalinvolutegear.py @@ -52,7 +52,7 @@ class InternalInvoluteGear(BaseGear): ) obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("InternalInvoluteGear", "number of teeth"), ) @@ -99,7 +99,7 @@ class InternalInvoluteGear(BaseGear): 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" @@ -263,7 +263,6 @@ class InternalInvoluteGear(BaseGear): 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 @@ -327,7 +326,7 @@ class InternalInvoluteGear(BaseGear): 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]) diff --git a/freecad/gears/involutegear.py b/freecad/gears/involutegear.py index ac8b25c..4c5ac49 100644 --- a/freecad/gears/involutegear.py +++ b/freecad/gears/involutegear.py @@ -36,7 +36,6 @@ from .basegear import ( class InvoluteGear(BaseGear): - """FreeCAD gear""" def __init__(self, obj): @@ -60,7 +59,7 @@ class InvoluteGear(BaseGear): 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" @@ -82,7 +81,7 @@ class InvoluteGear(BaseGear): def add_gear_properties(self, obj): obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("InvoluteGear", "number of teeth"), ) @@ -280,7 +279,6 @@ class InvoluteGear(BaseGear): 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 @@ -337,7 +335,7 @@ class InvoluteGear(BaseGear): 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 diff --git a/freecad/gears/involutegearrack.py b/freecad/gears/involutegearrack.py index 94b2322..b831a73 100644 --- a/freecad/gears/involutegearrack.py +++ b/freecad/gears/involutegearrack.py @@ -27,7 +27,6 @@ from .basegear import BaseGear, fcvec, points_to_wire, insert_fillet class InvoluteGearRack(BaseGear): - """FreeCAD gear rack""" def __init__(self, obj): @@ -35,7 +34,7 @@ class InvoluteGearRack(BaseGear): self.involute_rack = InvoluteRack() obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("InvoluteGearRack", "number of teeth"), ) @@ -79,7 +78,7 @@ class InvoluteGearRack(BaseGear): self.add_involute_properties(obj) self.add_fillet_properties(obj) obj.rack = self.involute_rack - obj.teeth = 15 + obj.num_teeth = 15 obj.module = "1. mm" obj.pressure_angle = "20. deg" obj.height = "5. mm" @@ -130,7 +129,7 @@ class InvoluteGearRack(BaseGear): "base", translate( "InvoluteGearRack", - "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", ), ) @@ -180,7 +179,7 @@ class InvoluteGearRack(BaseGear): def generate_gear_shape(self, obj): obj.rack.m = obj.module.Value - obj.rack.z = obj.teeth + obj.rack.z = obj.num_teeth obj.rack.pressure_angle = obj.pressure_angle.Value * np.pi / 180.0 obj.rack.thickness = obj.thickness.Value obj.rack.beta = obj.beta.Value * np.pi / 180.0 @@ -242,7 +241,7 @@ class InvoluteGearRack(BaseGear): 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) @@ -252,7 +251,7 @@ class InvoluteGearRack(BaseGear): 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]) diff --git a/freecad/gears/lanterngear.py b/freecad/gears/lanterngear.py index 64376d8..9ddc66c 100644 --- a/freecad/gears/lanterngear.py +++ b/freecad/gears/lanterngear.py @@ -34,7 +34,7 @@ class LanternGear(BaseGear): super(LanternGear, self).__init__(obj) obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "gear_parameter", translate("LanternGear", "number of teeth"), ) @@ -69,7 +69,7 @@ class LanternGear(BaseGear): translate("LanternGear", "head * module = additional length of head"), ) - obj.teeth = 15 + obj.num_teeth = 15 obj.module = "1. mm" obj.bolt_radius = "1 mm" @@ -81,7 +81,7 @@ class LanternGear(BaseGear): def generate_gear_shape(self, fp): m = fp.module.Value - teeth = fp.teeth + teeth = fp.num_teeth r_r = fp.bolt_radius.Value r_0 = m * teeth / 2 r_max = r_0 + r_r + fp.head * m diff --git a/freecad/gears/timinggear.py b/freecad/gears/timinggear.py index bb0ba35..f31b4bc 100644 --- a/freecad/gears/timinggear.py +++ b/freecad/gears/timinggear.py @@ -106,7 +106,7 @@ class TimingGear(BaseGear): super(TimingGear, self).__init__(obj) obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("TimingGear", "number of teeth"), ) @@ -174,7 +174,7 @@ class TimingGear(BaseGear): translate("TimingGear", "x-offset of second arc-midpoint"), 1, ) - obj.teeth = 15 + obj.num_teeth = 15 obj.type = ["gt2", "gt3", "gt5", "gt8", "htd3", "htd5", "htd8"] obj.height = "5. mm" @@ -198,9 +198,9 @@ class TimingGear(BaseGear): arcs = [] if offset == 0.0: - phi5 = np.pi / fp.teeth + phi5 = np.pi / fp.num_teeth ref = reflection(-phi5 - np.pi / 2.0) - rp = pitch * fp.teeth / np.pi / 2.0 - u + rp = pitch * fp.num_teeth / np.pi / 2.0 - u m_34 = np.array([-(r_12 + r_34), rp - h + r_12]) x2 = np.array([-r_12, m_34[1]]) @@ -227,7 +227,7 @@ class TimingGear(BaseGear): else: phi_12 = np.arctan(np.sqrt(1.0 / (((r_12 - r_23) / offset) ** 2 - 1))) - rp = pitch * fp.teeth / np.pi / 2.0 + rp = pitch * fp.num_teeth / np.pi / 2.0 r4 = r5 = rp - u m_12 = np.array([0.0, r5 - h + r_12]) @@ -282,7 +282,7 @@ class TimingGear(BaseGear): ) ) - phi5 = np.pi / fp.teeth + phi5 = np.pi / fp.num_teeth m_34 = (r5 - r_34) * np.array([-np.sin(phi4), np.cos(phi4)]) @@ -312,8 +312,8 @@ class TimingGear(BaseGear): wire = part.Wire(arcs) wires = [wire] rot = app.Matrix() - rot.rotateZ(np.pi * 2 / fp.teeth) - for _ in range(fp.teeth - 1): + rot.rotateZ(np.pi * 2 / fp.num_teeth) + for _ in range(fp.num_teeth - 1): wire = wire.transformGeometry(rot) wires.append(wire) diff --git a/freecad/gears/timinggear_t.py b/freecad/gears/timinggear_t.py index d42a639..382e92c 100644 --- a/freecad/gears/timinggear_t.py +++ b/freecad/gears/timinggear_t.py @@ -40,7 +40,7 @@ class TimingGearT(BaseGear): ) obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("TimingGearT", "number of teeth"), ) @@ -96,7 +96,7 @@ class TimingGearT(BaseGear): translate("TimingGearT", "extrusion height"), ) obj.pitch = "5. mm" - obj.teeth = 15 + obj.num_teeth = 15 obj.tooth_height = "1.2 mm" obj.u = "0.6 mm" obj.alpha = "40. deg" @@ -109,7 +109,7 @@ class TimingGearT(BaseGear): def generate_gear_shape(self, obj): pitch = obj.pitch.Value - teeth = obj.teeth + teeth = obj.num_teeth u = obj.u.Value tooth_height = obj.tooth_height.Value alpha = obj.alpha.Value / 180.0 * np.pi # we need radiant diff --git a/freecad/gears/wormgear.py b/freecad/gears/wormgear.py index 21dd46f..c851919 100644 --- a/freecad/gears/wormgear.py +++ b/freecad/gears/wormgear.py @@ -29,14 +29,13 @@ from .basegear import BaseGear, helical_extrusion, fcvec class WormGear(BaseGear): - """FreeCAD gear rack""" def __init__(self, obj): super(WormGear, self).__init__(obj) obj.addProperty( "App::PropertyInteger", - "teeth", + "num_teeth", "base", translate("WormGear", "number of teeth"), ) @@ -89,7 +88,7 @@ class WormGear(BaseGear): "tolerance", translate("WormGear", "clearance * module = additional length of root"), ) - obj.teeth = 3 + obj.num_teeth = 3 obj.module = "1. mm" obj.pressure_angle = "20. deg" obj.height = "5. mm" @@ -104,7 +103,7 @@ class WormGear(BaseGear): def generate_gear_shape(self, fp): m = fp.module.Value d = fp.diameter.Value - t = fp.teeth + t = fp.num_teeth h = fp.height clearance = fp.clearance