Skip to content

Commit 9f1e87b

Browse files
jbaehrlooooo
authored andcommitted
Calculate pitch diameter and angular backlash via expressions
Using expressions instead of filling these values in the `execute` method has the advantage that the values can be used in other expressions on the same object. First, the expressions are evaluated, then the feature is "executed". Previously, the changed values are only available after the execution and thus had no effect if e.g. used in calculating the placement of the very same gear (until another recompute happens).
1 parent 7c4723c commit 9f1e87b

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

freecad/gears/features.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,13 @@ def add_computed_properties(self, obj):
188188
"computed", "outside diameter", 1)
189189
obj.addProperty("App::PropertyLength", "df",
190190
"computed", "root diameter", 1)
191-
obj.addProperty("App::PropertyLength", "dw",
192-
"computed", "pitch diameter", 1)
191+
obj.addProperty("App::PropertyLength", "dw", "computed", "The pitch diameter.")
192+
obj.setExpression('dw', 'teeth * module') # calculate via expression to ease usage for placement
193+
obj.setEditorMode('dw', 1) # set read-only after setting the expression, else it won't be visible. bug?
194+
obj.addProperty("App::PropertyAngle", "angular_backlash", "computed",
195+
"The angle by which this gear can turn without moving the mating gear.")
196+
obj.setExpression('angular_backlash', 'backlash / dw * 360° / pi') # calculate via expression to ease usage for placement
197+
obj.setEditorMode('angular_backlash', 1) # set read-only after setting the expression, else it won't be visible. bug?
193198
obj.addProperty("App::PropertyLength", "transverse_pitch",
194199
"computed", "transverse_pitch", 1)
195200

@@ -225,7 +230,6 @@ def generate_gear_shape(self, fp):
225230
fp.gear._update()
226231

227232
# computed properties
228-
fp.dw = "{}mm".format(fp.gear.dw)
229233
fp.transverse_pitch = "{}mm".format(fp.gear.pitch)
230234
fp.da = "{}mm".format(fp.gear.da)
231235
fp.df = "{}mm".format(fp.gear.df)
@@ -350,7 +354,13 @@ def add_limiting_diameter_properties(self, obj):
350354
"computed", "root diameter", 1)
351355

352356
def add_computed_properties(self, obj):
353-
obj.addProperty("App::PropertyLength", "dw", "computed", "pitch diameter", 1)
357+
obj.addProperty("App::PropertyLength", "dw", "computed", "The pitch diameter.")
358+
obj.setExpression('dw', 'teeth * module') # calculate via expression to ease usage for placement
359+
obj.setEditorMode('dw', 1) # set read-only after setting the expression, else it won't be visible. bug?
360+
obj.addProperty("App::PropertyAngle", "angular_backlash", "computed",
361+
"The angle by which this gear can turn without moving the mating gear.")
362+
obj.setExpression('angular_backlash', 'backlash / dw * 360° / pi') # calculate via expression to ease usage for placement
363+
obj.setEditorMode('angular_backlash', 1) # set read-only after setting the expression, else it won't be visible. bug?
354364
obj.addProperty("App::PropertyLength", "transverse_pitch", "computed", "transverse_pitch", 1)
355365
obj.addProperty("App::PropertyLength", "outside_diameter", "computed", "Outside diameter", 1)
356366

@@ -394,7 +404,6 @@ def generate_gear_shape(self, fp):
394404
fp.gear._update()
395405

396406
# computed properties
397-
fp.dw = "{}mm".format(fp.gear.dw)
398407
fp.transverse_pitch = "{}mm".format(fp.gear.pitch)
399408
fp.outside_diameter = fp.dw + 2 * fp.thickness
400409
# checksbackwardcompatibility:
@@ -876,7 +885,6 @@ def __init__(self, obj):
876885
obj.head = 0
877886
obj.head_fillet = 0
878887
obj.root_fillet = 0
879-
obj.dw = obj.module * obj.teeth
880888
obj.Proxy = self
881889

882890
def add_helical_properties(self, obj):
@@ -898,7 +906,13 @@ def add_cycloid_properties(self, obj):
898906
obj.addProperty("App::PropertyFloat", "outer_diameter", "cycloid", "outer_diameter divided by module (epicycloid)")
899907

900908
def add_computed_properties(self, obj):
901-
obj.addProperty("App::PropertyLength", "dw", "computed", "pitch diameter", 1)
909+
obj.addProperty("App::PropertyLength", "dw", "computed", "The pitch diameter.")
910+
obj.setExpression('dw', 'teeth * module') # calculate via expression to ease usage for placement
911+
obj.setEditorMode('dw', 1) # set read-only after setting the expression, else it won't be visible. bug?
912+
obj.addProperty("App::PropertyAngle", "angular_backlash", "computed",
913+
"The angle by which this gear can turn without moving the mating gear.")
914+
obj.setExpression('angular_backlash', 'backlash / dw * 360° / pi') # calculate via expression to ease usage for placement
915+
obj.setEditorMode('angular_backlash', 1) # set read-only after setting the expression, else it won't be visible. bug?
902916

903917
def generate_gear_shape(self, fp):
904918
fp.gear.m = fp.module.Value
@@ -976,6 +990,13 @@ def __init__(self, obj):
976990
"The arc length on the pitch circle by which the tooth thicknes is reduced.")
977991
obj.addProperty("App::PropertyPythonObject", "gear", "base", "test")
978992
obj.addProperty("App::PropertyAngle", "beta","helical", "angle used for spiral bevel-gears")
993+
obj.addProperty("App::PropertyLength", "dw", "computed", "The pitch diameter.")
994+
obj.setExpression('dw', 'teeth * module') # calculate via expression to ease usage for placement
995+
obj.setEditorMode('dw', 1) # set read-only after setting the expression, else it won't be visible. bug?
996+
obj.addProperty("App::PropertyAngle", "angular_backlash", "computed",
997+
"The angle by which this gear can turn without moving the mating gear.")
998+
obj.setExpression('angular_backlash', 'backlash / dw * 360° / pi') # calculate via expression to ease usage for placement
999+
obj.setEditorMode('angular_backlash', 1) # set read-only after setting the expression, else it won't be visible. bug?
9791000
obj.gear = self.bevel_tooth
9801001
obj.module = '1. mm'
9811002
obj.teeth = 15

0 commit comments

Comments
 (0)