Skip to content

Commit

Permalink
refactor: beta->helix-angle
Browse files Browse the repository at this point in the history
  • Loading branch information
looooo committed Jan 4, 2025
1 parent 3707c27 commit 7034963
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 33 deletions.
23 changes: 18 additions & 5 deletions freecad/gears/cycloidgear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions freecad/gears/cycloidgearrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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])
Expand All @@ -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])
Expand Down
28 changes: 22 additions & 6 deletions freecad/gears/internalinvolutegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand All @@ -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(
Expand Down Expand Up @@ -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",
Expand All @@ -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",
),
)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 23 additions & 6 deletions freecad/gears/involutegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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"):
Expand All @@ -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"""
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 24 additions & 10 deletions freecad/gears/involutegearrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -93,21 +93,37 @@ 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",
"properties_from_tool",
"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",
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit 7034963

Please sign in to comment.