From 703496305039bc6d4ee0f7e8f0facce462a3a03a Mon Sep 17 00:00:00 2001 From: looooo Date: Sat, 4 Jan 2025 12:44:08 +0100 Subject: [PATCH] refactor: beta->helix-angle --- freecad/gears/cycloidgear.py | 23 ++++++++++++++---- freecad/gears/cycloidgearrack.py | 28 +++++++++++++++++----- freecad/gears/internalinvolutegear.py | 28 +++++++++++++++++----- freecad/gears/involutegear.py | 29 ++++++++++++++++++----- freecad/gears/involutegearrack.py | 34 +++++++++++++++++++-------- 5 files changed, 109 insertions(+), 33 deletions(-) diff --git a/freecad/gears/cycloidgear.py b/freecad/gears/cycloidgear.py index ff9c63f..b3cc708 100644 --- a/freecad/gears/cycloidgear.py +++ b/freecad/gears/cycloidgear.py @@ -83,7 +83,7 @@ def __init__(self, obj): "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.helix_angle = "0. deg" obj.height = "5. mm" obj.clearance = 0.25 obj.numpoints = 20 @@ -113,6 +113,18 @@ def onDocumentRestored(self, obj): "angular_backlash", "backlash / pitch_diameter * 360° / pi" ) + # replace beta with helix_angle + if hasattr(obj, "beta"): + helix_angle = getattr(obj, "beta") + obj.addProperty( + "App::PropertyAngle", + "helix_angle", + "helical", + QT_TRANSLATE_NOOP("App::Property", "helix angle"), + ) + obj.helix_angle = helix_angle + obj.removeProperty("beta") + def add_helical_properties(self, obj): obj.addProperty( "App::PropertyBool", @@ -122,9 +134,9 @@ def add_helical_properties(self, obj): ) obj.addProperty( "App::PropertyAngle", - "beta", + "helix_angle", "helical", - QT_TRANSLATE_NOOP("App::Property", "beta"), + QT_TRANSLATE_NOOP("App::Property", "helix angle"), ) def add_fillet_properties(self, obj): @@ -260,11 +272,12 @@ def generate_gear_shape(self, fp): if fp.height.Value == 0: return profile base = part.Face(profile) - if fp.beta.Value == 0: + if fp.helix_angle.Value == 0: return base.extrude(app.Vector(0, 0, fp.height.Value)) else: + beta = fp.helix_angle.Value * np.pi / 180 twist_angle = ( - fp.height.Value * np.tan(fp.beta.Value * np.pi / 180) * 2 / fp.gear.d + fp.height.Value * np.tan(beta) * 2 / fp.gear.d ) return helical_extrusion( base, fp.height.Value, twist_angle, fp.double_helix diff --git a/freecad/gears/cycloidgearrack.py b/freecad/gears/cycloidgearrack.py index 545222f..ce27b9b 100644 --- a/freecad/gears/cycloidgearrack.py +++ b/freecad/gears/cycloidgearrack.py @@ -87,7 +87,7 @@ def __init__(self, obj): obj.outer_diameter = 7.5 obj.height = "5. mm" obj.thickness = "5 mm" - obj.beta = "0. deg" + obj.helix_angle = "0. deg" obj.clearance = 0.25 obj.head = 0.0 obj.add_endings = True @@ -96,12 +96,28 @@ def __init__(self, obj): self.obj = obj obj.Proxy = self + def onDocumentRestored(self, obj): + """ + backward compatibility functions + """ + # replace beta with helix_angle + if hasattr(obj, "beta"): + helix_angle = getattr(obj, "beta") + obj.addProperty( + "App::PropertyAngle", + "helix_angle", + "helical", + QT_TRANSLATE_NOOP("App::Property", "helix angle"), + ) + obj.helix_angle = helix_angle + obj.removeProperty("beta") + def add_helical_properties(self, obj): obj.addProperty( "App::PropertyAngle", - "beta", + "helix_angle", "helical", - QT_TRANSLATE_NOOP("App::Property", "beta"), + QT_TRANSLATE_NOOP("App::Property", "helix angle"), ) obj.addProperty( "App::PropertyBool", @@ -254,11 +270,11 @@ def generate_gear_shape(self, obj): if obj.height.Value == 0: return pol - elif obj.beta.Value == 0: + elif obj.helix_angle.Value == 0: face = part.Face(part.Wire(pol)) return face.extrude(fcvec([0.0, 0.0, obj.height.Value])) elif obj.double_helix: - beta = obj.beta.Value * np.pi / 180.0 + beta = obj.helix_angle.Value * np.pi / 180.0 pol2 = part.Wire(pol) pol2.translate( fcvec([0.0, np.tan(beta) * obj.height.Value / 2, obj.height.Value / 2]) @@ -267,7 +283,7 @@ def generate_gear_shape(self, obj): pol3.translate(fcvec([0.0, 0.0, obj.height.Value])) return part.makeLoft([pol, pol2, pol3], True, True) else: - beta = obj.beta.Value * np.pi / 180.0 + beta = obj.helix_angle.Value * np.pi / 180.0 pol2 = part.Wire(pol) pol2.translate( fcvec([0.0, np.tan(beta) * obj.height.Value, obj.height.Value]) diff --git a/freecad/gears/internalinvolutegear.py b/freecad/gears/internalinvolutegear.py index efa4a26..51671ec 100644 --- a/freecad/gears/internalinvolutegear.py +++ b/freecad/gears/internalinvolutegear.py @@ -105,7 +105,7 @@ def __init__(self, obj): obj.module = "1. mm" obj.shift = 0.0 obj.pressure_angle = "20. deg" - obj.beta = "0. deg" + obj.helix_angle = "0. deg" obj.height = "5. mm" obj.thickness = "5 mm" obj.clearance = 0.25 @@ -149,6 +149,7 @@ def onDocumentRestored(self, obj): 1, ) obj.addendum_diameter = addendum_diameter + obj.removeProperty("da") # replace df with root_diameter if hasattr(obj, "df"): @@ -161,6 +162,21 @@ def onDocumentRestored(self, obj): 1, ) obj.root_diameter = root_diameter + obj.removeProperty("df") + + # replace beta with helix_angle + if hasattr(obj, "beta"): + helix_angle = getattr(obj, "beta") + obj.addProperty( + "App::PropertyAngle", + "helix_angle", + "helical", + QT_TRANSLATE_NOOP("App::Property", "helix angle"), + ) + obj.helix_angle = helix_angle + obj.removeProperty("beta") + + def add_limiting_diameter_properties(self, obj): obj.addProperty( @@ -284,9 +300,9 @@ def add_involute_properties(self, obj): def add_helical_properties(self, obj): obj.addProperty( "App::PropertyAngle", - "beta", + "helix_angle", "helical", - QT_TRANSLATE_NOOP("App::Property", "beta"), + QT_TRANSLATE_NOOP("App::Property", "helix angle"), ) obj.addProperty( "App::PropertyBool", @@ -300,7 +316,7 @@ def add_helical_properties(self, obj): "helical", QT_TRANSLATE_NOOP( "App::Property", - "if beta is given and properties_from_tool is enabled, gear parameters are internally recomputed for the rotated gear", + "if helix_angle is given and properties_from_tool is enabled, gear parameters are internally recomputed for the rotated gear", ), ) @@ -311,7 +327,7 @@ def generate_gear_shape(self, fp): 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 - fp.gear.beta = fp.beta.Value * np.pi / 180 + fp.gear.beta = fp.helix_angle.Value * np.pi / 180 fp.gear.clearance = fp.head # swap head and clearance to become "internal" fp.gear.backlash = ( fp.backlash.Value * (fp.reversed_backlash - 0.5) * 2.0 @@ -375,7 +391,7 @@ def generate_gear_shape(self, fp): if fp.height.Value == 0: return part.makeCompound([outer_circle, profile]) base = part.Face([outer_circle, profile]) - if fp.beta.Value == 0: + if fp.gear.beta == 0: return base.extrude(app.Vector(0, 0, fp.height.Value)) else: twist_angle = fp.height.Value * np.tan(fp.gear.beta) * 2 / fp.gear.d diff --git a/freecad/gears/involutegear.py b/freecad/gears/involutegear.py index 819a13d..6d98c7d 100644 --- a/freecad/gears/involutegear.py +++ b/freecad/gears/involutegear.py @@ -63,7 +63,7 @@ def __init__(self, obj): obj.module = "1. mm" obj.shift = 0.0 obj.pressure_angle = "20. deg" - obj.beta = "0. deg" + obj.helix_angle = "0. deg" obj.height = "5. mm" obj.clearance = 0.25 obj.head = 0.0 @@ -87,6 +87,7 @@ def onDocumentRestored(self, obj): """ backward compatibility functions """ + # replace dw with pitch_diameter if hasattr(obj, "dw"): pitch_diameter = getattr(obj, "dw") obj.addProperty( @@ -112,6 +113,7 @@ def onDocumentRestored(self, obj): 1, ) obj.addendum_diameter = addendum_diameter + obj.removeProperty("da") # replace df with root_diameter if hasattr(obj, "df"): @@ -124,6 +126,21 @@ def onDocumentRestored(self, obj): 1, ) obj.root_diameter = root_diameter + obj.removeProperty("df") + + + # replace beta with helix_angle + if hasattr(obj, "beta"): + helix_angle = getattr(obj, "beta") + obj.addProperty( + "App::PropertyAngle", + "helix_angle", + "helical", + QT_TRANSLATE_NOOP("App::Property", "helix angle"), + ) + obj.helix_angle = helix_angle + obj.removeProperty("beta") + def add_hole_properties(self, obj): """Add properties for the central hole""" @@ -226,14 +243,14 @@ def add_helical_properties(self, obj): "helical", QT_TRANSLATE_NOOP( "App::Property", - "if beta is given and properties_from_tool is enabled, gear parameters are internally recomputed for the rotated gear", + "if helix_angle is given and properties_from_tool is enabled, gear parameters are internally recomputed for the rotated gear", ), ) obj.addProperty( "App::PropertyAngle", - "beta", + "helix_angle", "helical", - QT_TRANSLATE_NOOP("App::Property", "beta"), + QT_TRANSLATE_NOOP("App::Property", "helix angle"), ) obj.addProperty( "App::PropertyBool", @@ -362,7 +379,7 @@ def generate_gear_shape(self, obj): obj.gear.undercut = obj.undercut obj.gear.shift = obj.shift obj.gear.pressure_angle = obj.pressure_angle.Value * np.pi / 180.0 - obj.gear.beta = obj.beta.Value * np.pi / 180 + obj.gear.beta = obj.helix_angle.Value * np.pi / 180 obj.gear.clearance = obj.clearance obj.gear.backlash = obj.backlash.Value * (-obj.reversed_backlash + 0.5) * 2.0 obj.gear.head = obj.head @@ -422,7 +439,7 @@ def generate_gear_shape(self, obj): gear_shape = profile else: base = part.Face(profile) - if obj.beta.Value == 0: + if obj.gear.beta == 0: gear_shape = base.extrude(app.Vector(0, 0, obj.height.Value)) else: twist_angle = obj.height.Value * np.tan(obj.gear.beta) * 2 / obj.gear.d diff --git a/freecad/gears/involutegearrack.py b/freecad/gears/involutegearrack.py index cde7168..8c7078c 100644 --- a/freecad/gears/involutegearrack.py +++ b/freecad/gears/involutegearrack.py @@ -84,7 +84,7 @@ def __init__(self, obj): obj.pressure_angle = "20. deg" obj.height = "5. mm" obj.thickness = "5 mm" - obj.beta = "0. deg" + obj.helix_angle = "0. deg" obj.clearance = 0.25 obj.head = 0.0 obj.properties_from_tool = False @@ -93,6 +93,22 @@ def __init__(self, obj): self.obj = obj obj.Proxy = self + def onDocumentRestored(self, obj): + """ + backward compatibility functions + """ + # replace beta with helix_angle + if hasattr(obj, "beta"): + helix_angle = getattr(obj, "beta") + obj.addProperty( + "App::PropertyAngle", + "helix_angle", + "helical", + QT_TRANSLATE_NOOP("App::Property", "helix angle"), + ) + obj.helix_angle = helix_angle + obj.removeProperty("beta") + def add_helical_properties(self, obj): obj.addProperty( "App::PropertyBool", @@ -100,14 +116,14 @@ def add_helical_properties(self, obj): "helical", QT_TRANSLATE_NOOP( "App::Property", - "if beta is given and properties_from_tool is enabled, gear parameters are internally recomputed for the rotated gear", + "if helix_angle is given and properties_from_tool is enabled, gear parameters are internally recomputed for the rotated gear", ), ) obj.addProperty( "App::PropertyAngle", - "beta", + "helix_angle", "helical", - QT_TRANSLATE_NOOP("App::Property", "beta"), + QT_TRANSLATE_NOOP("App::Property", "helix anglle"), ) obj.addProperty( "App::PropertyBool", @@ -185,7 +201,7 @@ def generate_gear_shape(self, obj): 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 + obj.rack.beta = obj.helix_angle.Value * np.pi / 180.0 obj.rack.head = obj.head # checksbackwardcompatibility: if "clearance" in obj.PropertiesList: @@ -272,22 +288,20 @@ def generate_gear_shape(self, obj): if obj.height.Value == 0: return pol - elif obj.beta.Value == 0: + elif obj.rack.beta == 0: face = part.Face(part.Wire(pol)) return face.extrude(fcvec([0.0, 0.0, obj.height.Value])) elif obj.double_helix: - beta = obj.beta.Value * np.pi / 180.0 pol2 = part.Wire(pol) pol2.translate( - fcvec([0.0, np.tan(beta) * obj.height.Value / 2, obj.height.Value / 2]) + fcvec([0.0, np.tan(obj.rack.beta) * obj.height.Value / 2, obj.height.Value / 2]) ) pol3 = part.Wire(pol) pol3.translate(fcvec([0.0, 0.0, obj.height.Value])) return part.makeLoft([pol, pol2, pol3], True, True) else: - beta = obj.beta.Value * np.pi / 180.0 pol2 = part.Wire(pol) pol2.translate( - fcvec([0.0, np.tan(beta) * obj.height.Value, obj.height.Value]) + fcvec([0.0, np.tan(obj.rack.beta) * obj.height.Value, obj.height.Value]) ) return part.makeLoft([pol, pol2], True)