Skip to content

Commit 1cf83e7

Browse files
committed
gear-rack add fillets
1 parent 39e5ce1 commit 1cf83e7

File tree

2 files changed

+120
-54
lines changed

2 files changed

+120
-54
lines changed

freecad/gears/commands.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -76,91 +76,91 @@ def GetResources(self):
7676

7777

7878
class CreateInvoluteGear(BaseCommand):
79-
NAME = "involutegear"
79+
NAME = "InvoluteGear"
8080
GEAR_FUNCTION = InvoluteGear
8181
Pixmap = os.path.join(BaseCommand.ICONDIR, 'involutegear.svg')
82-
MenuText = 'Involute gear'
82+
MenuText = 'Involute Gear'
8383
ToolTip = 'Create an external involute gear'
8484

8585

8686
class CreateInternalInvoluteGear(BaseCommand):
87-
NAME = "internalinvolutegear"
87+
NAME = "InternalInvoluteGear"
8888
GEAR_FUNCTION = InternalInvoluteGear
8989
Pixmap = os.path.join(BaseCommand.ICONDIR, 'internalinvolutegear.svg')
90-
MenuText = 'Internal involute gear'
90+
MenuText = 'Internal Involute Gear'
9191
ToolTip = 'Create an internal involute gear'
9292

9393

9494
class CreateInvoluteRack(BaseCommand):
95-
NAME = "involuterack"
95+
NAME = "InvoluteRack"
9696
GEAR_FUNCTION = InvoluteGearRack
9797
Pixmap = os.path.join(BaseCommand.ICONDIR, 'involuterack.svg')
98-
MenuText = 'Involute rack'
98+
MenuText = 'Involute Rack'
9999
ToolTip = 'Create an Involute rack'
100100

101101
class CreateCycloidRack(BaseCommand):
102-
NAME = "Cycloidrack"
102+
NAME = "CycloidRack"
103103
GEAR_FUNCTION = CycloidGearRack
104104
Pixmap = os.path.join(BaseCommand.ICONDIR, 'cycloidrack.svg')
105-
MenuText = 'Cycloid rack'
105+
MenuText = 'Cycloid Rack'
106106
ToolTip = 'Create an Cycloid rack'
107107

108108

109109
class CreateCrownGear(BaseCommand):
110-
NAME = "crowngear"
110+
NAME = "CrownGear"
111111
GEAR_FUNCTION = CrownGear
112112
Pixmap = os.path.join(BaseCommand.ICONDIR, 'crowngear.svg')
113-
MenuText = 'Crown gear'
113+
MenuText = 'Crown Gear'
114114
ToolTip = 'Create a Crown gear'
115115

116116

117117
class CreateCycloidGear(BaseCommand):
118-
NAME = "cycloidgear"
118+
NAME = "CycloidGear"
119119
GEAR_FUNCTION = CycloidGear
120120
Pixmap = os.path.join(BaseCommand.ICONDIR, 'cycloidgear.svg')
121-
MenuText = 'Cycloid gear'
121+
MenuText = 'Cycloid Gear'
122122
ToolTip = 'Create a Cycloid gear'
123123

124124

125125
class CreateBevelGear(BaseCommand):
126-
NAME = "bevelgear"
126+
NAME = "BevelGear"
127127
GEAR_FUNCTION = BevelGear
128128
Pixmap = os.path.join(BaseCommand.ICONDIR, 'bevelgear.svg')
129-
MenuText = 'Bevel gear'
129+
MenuText = 'Bevel Gear'
130130
ToolTip = 'Create a Bevel gear'
131131

132132
class CreateHypoCycloidGear(BaseCommand):
133-
NAME = "hypocycloidgear"
133+
NAME = "HypocycloidGear"
134134
GEAR_FUNCTION = HypoCycloidGear
135135
Pixmap = os.path.join(BaseCommand.ICONDIR, 'hypocycloidgear.svg')
136-
MenuText = 'HypoCycloid gear'
136+
MenuText = 'HypoCycloid Gear'
137137
ToolTip = 'Create a HypoCycloid gear with its pins'
138138

139139

140140
class CreateWormGear(BaseCommand):
141-
NAME = "wormgear"
141+
NAME = "WormGear"
142142
GEAR_FUNCTION = WormGear
143143
Pixmap = os.path.join(BaseCommand.ICONDIR, 'wormgear.svg')
144-
MenuText = 'Worm gear'
144+
MenuText = 'Worm Gear'
145145
ToolTip = 'Create a Worm gear'
146146

147147

148148
class CreateTimingGear(BaseCommand):
149-
NAME = "timinggear"
149+
NAME = "TimingGear"
150150
GEAR_FUNCTION = TimingGear
151151
Pixmap = os.path.join(BaseCommand.ICONDIR, 'timinggear.svg')
152-
MenuText = 'Timing gear'
152+
MenuText = 'Timing Gear'
153153
ToolTip = 'Create a Timing gear'
154154

155155
class CreateLanternGear(BaseCommand):
156-
NAME = "lanterngear"
156+
NAME = "LanternGear"
157157
GEAR_FUNCTION = LanternGear
158158
Pixmap = os.path.join(BaseCommand.ICONDIR, 'lanterngear.svg')
159-
MenuText = 'Lantern gear'
159+
MenuText = 'Lantern Gear'
160160
ToolTip = 'Create a Lantern gear'
161161

162162
class CreateGearConnector(BaseCommand):
163-
NAME = "gearconnector"
163+
NAME = "GearConnector"
164164
GEAR_FUNCTION = GearConnector
165165
Pixmap = os.path.join(BaseCommand.ICONDIR, 'gearconnector.svg')
166166
MenuText = 'Combine two gears'

freecad/gears/features.py

+97-31
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ def __init__(self, obj):
499499
self.add_computed_properties(obj)
500500
self.add_tolerance_properties(obj)
501501
self.add_involute_properties(obj)
502+
self.add_fillet_properties(obj)
502503
obj.rack = self.involute_rack
503504
obj.teeth = 15
504505
obj.module = '1. mm'
@@ -543,49 +544,114 @@ def add_fillet_properties(self, obj):
543544
obj.addProperty("App::PropertyFloat", "head_fillet", "fillets", "a fillet for the tooth-head, radius = head_fillet x module")
544545
obj.addProperty("App::PropertyFloat", "root_fillet", "fillets", "a fillet for the tooth-root, radius = root_fillet x module")
545546

546-
def generate_gear_shape(self, fp):
547-
fp.rack.m = fp.module.Value
548-
fp.rack.z = fp.teeth
549-
fp.rack.pressure_angle = fp.pressure_angle.Value * np.pi / 180.
550-
fp.rack.thickness = fp.thickness.Value
551-
fp.rack.beta = fp.beta.Value * np.pi / 180.
552-
fp.rack.head = fp.head
547+
def generate_gear_shape(self, obj):
548+
obj.rack.m = obj.module.Value
549+
obj.rack.z = obj.teeth
550+
obj.rack.pressure_angle = obj.pressure_angle.Value * np.pi / 180.
551+
obj.rack.thickness = obj.thickness.Value
552+
obj.rack.beta = obj.beta.Value * np.pi / 180.
553+
obj.rack.head = obj.head
553554
# checksbackwardcompatibility:
554-
if "clearance" in fp.PropertiesList:
555-
fp.rack.clearance = fp.clearance
556-
if "properties_from_tool" in fp.PropertiesList:
557-
fp.rack.properties_from_tool = fp.properties_from_tool
558-
if "add_endings" in fp.PropertiesList:
559-
fp.rack.add_endings = fp.add_endings
560-
if "simplified" in fp.PropertiesList:
561-
fp.rack.simplified = fp.simplified
562-
fp.rack._update()
555+
if "clearance" in obj.PropertiesList:
556+
obj.rack.clearance = obj.clearance
557+
if "properties_from_tool" in obj.PropertiesList:
558+
obj.rack.properties_from_tool = obj.properties_from_tool
559+
if "add_endings" in obj.PropertiesList:
560+
obj.rack.add_endings = obj.add_endings
561+
if "simplified" in obj.PropertiesList:
562+
obj.rack.simplified = obj.simplified
563+
obj.rack._update()
564+
565+
obj.transverse_pitch = "{} mm".format(obj.module.Value * np.pi)
566+
m = obj.module.Value
567+
t = obj.thickness.Value
568+
c = obj.clearance
569+
h = obj.head
570+
alpha = obj.pressure_angle.Value * np.pi / 180.
571+
head_fillet = obj.head_fillet
572+
root_fillet = obj.root_fillet
573+
x1 = -m * np.pi / 2
574+
y1 = -m * (1 + c)
575+
y2 = y1
576+
x2 = -m * np.pi / 4 + y2 * np.tan(alpha)
577+
y3 = m * (1 + h)
578+
x3 = -m * np.pi / 4 + y3 * np.tan(alpha)
579+
x4 = -x3
580+
x5 = -x2
581+
x6 = -x1
582+
y4 = y3
583+
y5 = y2
584+
y6 = y1
585+
p1 = np.array([y1, x1])
586+
p2 = np.array([y2, x2])
587+
p3 = np.array([y3, x3])
588+
p4 = np.array([y4, x4])
589+
p5 = np.array([y5, x5])
590+
p6 = np.array([y6, x6])
591+
line1 = [p1, p2]
592+
line2 = [p2, p3]
593+
line3 = [p3, p4]
594+
line4 = [p4, p5]
595+
line5 = [p5, p6]
596+
tooth = Wire(points_to_wire([line1, line2, line3, line4, line5]))
597+
edges = tooth.Edges
598+
edges = insert_fillet(edges, 0, m * root_fillet)
599+
edges = insert_fillet(edges, 2, m * head_fillet)
600+
edges = insert_fillet(edges, 4, m * head_fillet)
601+
edges = insert_fillet(edges, 6, m * root_fillet)
602+
603+
tooth_edges = [e for e in edges if e is not None]
604+
p_end = np.array(tooth_edges[-2].lastVertex().Point[:-1])
605+
p_start = np.array(tooth_edges[1].firstVertex().Point[:-1])
606+
p_start += np.array([0, np.pi * m])
607+
edge = points_to_wire([[p_end, p_start]]).Edges
608+
tooth = Wire(tooth_edges[1:-1] + edge)
609+
teeth = [tooth]
563610

564-
# computed properties
565-
if "transverse_pitch" in fp.PropertiesList:
566-
fp.transverse_pitch = "{} mm".format(fp.rack.compute_properties()[2])
611+
for i in range(obj.teeth - 1):
612+
tooth = copy.deepcopy(tooth)
613+
tooth.translate(App.Vector(0, np.pi * m, 0))
614+
teeth.append(tooth)
567615

568-
pts = fp.rack.points()
569-
pol = Wire(makePolygon(list(map(fcvec, pts))))
570-
571-
if fp.height.Value == 0:
616+
teeth[-1] = Wire(teeth[-1].Edges[:-1])
617+
618+
if obj.add_endings:
619+
teeth = [Wire(tooth_edges[0])] + teeth
620+
last_edge = tooth_edges[-1]
621+
last_edge.translate(App.Vector(0, np.pi * m * (obj.teeth - 1), 0))
622+
teeth = teeth + [Wire(last_edge)]
623+
624+
p_start = np.array(teeth[0].Edges[0].firstVertex().Point[:-1])
625+
p_end = np.array(teeth[-1].Edges[-1].lastVertex().Point[:-1])
626+
p_start_1 = p_start - np.array([obj.thickness.Value, 0.])
627+
p_end_1 = p_end - np.array([obj.thickness.Value, 0.])
628+
629+
line6 = [p_start, p_start_1]
630+
line7 = [p_start_1, p_end_1]
631+
line8 = [p_end_1, p_end]
632+
633+
bottom = points_to_wire([line6, line7, line8])
634+
635+
pol = Wire([bottom] + teeth)
636+
637+
if obj.height.Value == 0:
572638
return pol
573-
elif fp.beta.Value == 0:
639+
elif obj.beta.Value == 0:
574640
face = Face(Wire(pol))
575-
return face.extrude(fcvec([0., 0., fp.height.Value]))
576-
elif fp.double_helix:
577-
beta = fp.beta.Value * np.pi / 180.
641+
return face.extrude(fcvec([0., 0., obj.height.Value]))
642+
elif obj.double_helix:
643+
beta = obj.beta.Value * np.pi / 180.
578644
pol2 = Part.Wire(pol)
579645
pol2.translate(
580-
fcvec([0., np.tan(beta) * fp.height.Value / 2, fp.height.Value / 2]))
646+
fcvec([0., np.tan(beta) * obj.height.Value / 2, obj.height.Value / 2]))
581647
pol3 = Part.Wire(pol)
582-
pol3.translate(fcvec([0., 0., fp.height.Value]))
648+
pol3.translate(fcvec([0., 0., obj.height.Value]))
583649
return makeLoft([pol, pol2, pol3], True, True)
584650
else:
585-
beta = fp.beta.Value * np.pi / 180.
651+
beta = obj.beta.Value * np.pi / 180.
586652
pol2 = Part.Wire(pol)
587653
pol2.translate(
588-
fcvec([0., np.tan(beta) * fp.height.Value, fp.height.Value]))
654+
fcvec([0., np.tan(beta) * obj.height.Value, obj.height.Value]))
589655
return makeLoft([pol, pol2], True)
590656

591657
def __getstate__(self):

0 commit comments

Comments
 (0)