Compare commits
10 Commits
ca2236c614
...
2022
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1c80bd963 | ||
|
|
109df352a9 | ||
|
|
165f1a0aea | ||
|
|
8258477645 | ||
|
|
6ce203ea8f | ||
|
|
69ff30d65e | ||
|
|
3c86d12dc7 | ||
|
|
d489dfb841 | ||
|
|
1b19d16264 | ||
|
|
d5e12ef116 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -59,3 +59,6 @@ target/
|
||||
.ipynb_checkpoints/
|
||||
results/
|
||||
*.vtk
|
||||
|
||||
# VIM
|
||||
*.swp
|
||||
|
||||
@@ -41,10 +41,13 @@ class BaseCommand(object):
|
||||
return True
|
||||
|
||||
def Activated(self):
|
||||
doc = FreeCAD.ActiveDocument
|
||||
Gui.doCommandGui("import freecad.gears.commands")
|
||||
doc.openTransaction(self.ToolTip)
|
||||
Gui.doCommandGui("freecad.gears.commands.{}.create()".format(
|
||||
self.__class__.__name__))
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
doc.commitTransaction()
|
||||
doc.recompute()
|
||||
Gui.SendMsgToActiveView("ViewFit")
|
||||
|
||||
@classmethod
|
||||
@@ -63,7 +66,7 @@ class BaseCommand(object):
|
||||
cls.GEAR_FUNCTION(obj)
|
||||
|
||||
if body:
|
||||
body.Group += [obj]
|
||||
body.addObject(obj)
|
||||
elif part:
|
||||
part.Group += [obj]
|
||||
else:
|
||||
|
||||
@@ -87,12 +87,29 @@ class BaseGear(object):
|
||||
obj.addExtension('Part::AttachExtensionPython')
|
||||
else:
|
||||
obj.addExtension('Part::AttachExtensionPython', obj)
|
||||
# unveil the "Placement" property, which seems hidden by default in PartDesign
|
||||
obj.setEditorMode('Placement', 0) #non-readonly non-hidden
|
||||
|
||||
def execute(self, fp):
|
||||
# checksbackwardcompatibility:
|
||||
if not hasattr(fp, "positionBySupport"):
|
||||
self.make_attachable(fp)
|
||||
fp.positionBySupport()
|
||||
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
|
||||
gear_shape.Placement = fp.Placement # ensure the gear is placed correctly before fusing
|
||||
result_shape = fp.BaseFeature.Shape.fuse(gear_shape)
|
||||
result_shape.transformShape(fp.Placement.inverse().toMatrix(), True) # account for setting fp.Shape below moves the shape to fp.Placement, ignoring its previous placement
|
||||
fp.Shape = result_shape
|
||||
else:
|
||||
fp.Shape = gear_shape
|
||||
|
||||
def generate_gear_shape(self, fp):
|
||||
"""
|
||||
This method has to return the TopoShape of the gear.
|
||||
"""
|
||||
raise NotImplementedError("generate_gear_shape not implemented")
|
||||
|
||||
class InvoluteGear(BaseGear):
|
||||
|
||||
@@ -165,8 +182,7 @@ class InvoluteGear(BaseGear):
|
||||
obj.addProperty("App::PropertyLength", "df",
|
||||
"computed", "root diameter", 1)
|
||||
|
||||
def execute(self, fp):
|
||||
super(InvoluteGear, self).execute(fp)
|
||||
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
|
||||
@@ -182,6 +198,16 @@ class InvoluteGear(BaseGear):
|
||||
if "properties_from_tool" in fp.PropertiesList:
|
||||
fp.gear.properties_from_tool = fp.properties_from_tool
|
||||
fp.gear._update()
|
||||
|
||||
# computed properties
|
||||
fp.dw = "{}mm".format(fp.gear.dw)
|
||||
fp.transverse_pitch = "{}mm".format(fp.gear.pitch)
|
||||
# checksbackwardcompatibility:
|
||||
if not "da" in fp.PropertiesList:
|
||||
self.add_limiting_diameter_properties(fp)
|
||||
fp.da = "{}mm".format(fp.gear.da)
|
||||
fp.df = "{}mm".format(fp.gear.df)
|
||||
|
||||
pts = fp.gear.points(num=fp.numpoints)
|
||||
rotated_pts = pts
|
||||
rot = rotation(-fp.gear.phipart)
|
||||
@@ -198,25 +224,16 @@ class InvoluteGear(BaseGear):
|
||||
wi.append(out.toShape())
|
||||
wi = Wire(wi)
|
||||
if fp.height.Value == 0:
|
||||
fp.Shape = wi
|
||||
return wi
|
||||
elif fp.beta.Value == 0:
|
||||
sh = Face(wi)
|
||||
fp.Shape = sh.extrude(App.Vector(0, 0, fp.height.Value))
|
||||
return sh.extrude(App.Vector(0, 0, fp.height.Value))
|
||||
else:
|
||||
fp.Shape = helicalextrusion(
|
||||
return helicalextrusion(
|
||||
wi, fp.height.Value, fp.height.Value * np.tan(fp.gear.beta) * 2 / fp.gear.d, fp.double_helix)
|
||||
else:
|
||||
rw = fp.gear.dw / 2
|
||||
fp.Shape = Part.makeCylinder(rw, fp.height.Value)
|
||||
|
||||
# computed properties
|
||||
fp.dw = "{}mm".format(fp.gear.dw)
|
||||
fp.transverse_pitch = "{}mm".format(fp.gear.pitch)
|
||||
# checksbackwardcompatibility:
|
||||
if not "da" in fp.PropertiesList:
|
||||
self.add_limiting_diameter_properties(fp)
|
||||
fp.da = "{}mm".format(fp.gear.da)
|
||||
fp.df = "{}mm".format(fp.gear.df)
|
||||
return Part.makeCylinder(rw, fp.height.Value)
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@@ -270,14 +287,13 @@ class InvoluteGearRack(BaseGear):
|
||||
obj.beta = '0. deg'
|
||||
obj.clearance = 0.25
|
||||
obj.head = 0.
|
||||
obj.properties_from_tool = True
|
||||
obj.properties_from_tool = False
|
||||
obj.add_endings = True
|
||||
obj.simplified = False
|
||||
self.obj = obj
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
super(InvoluteGearRack, self).execute(fp)
|
||||
def generate_gear_shape(self, fp):
|
||||
fp.rack.m = fp.module.Value
|
||||
fp.rack.z = fp.teeth
|
||||
fp.rack.pressure_angle = fp.pressure_angle.Value * np.pi / 180.
|
||||
@@ -294,13 +310,18 @@ class InvoluteGearRack(BaseGear):
|
||||
if "simplified" in fp.PropertiesList:
|
||||
fp.rack.simplified = fp.simplified
|
||||
fp.rack._update()
|
||||
|
||||
# computed properties
|
||||
if "transverse_pitch" in fp.PropertiesList:
|
||||
fp.transverse_pitch = "{} mm".format(fp.rack.compute_properties()[2])
|
||||
|
||||
pts = fp.rack.points()
|
||||
pol = Wire(makePolygon(list(map(fcvec, pts))))
|
||||
if fp.height.Value == 0:
|
||||
fp.Shape = pol
|
||||
return pol
|
||||
elif fp.beta.Value == 0:
|
||||
face = Face(Wire(pol))
|
||||
fp.Shape = face.extrude(fcvec([0., 0., fp.height.Value]))
|
||||
return face.extrude(fcvec([0., 0., fp.height.Value]))
|
||||
elif fp.double_helix:
|
||||
beta = fp.beta.Value * np.pi / 180.
|
||||
pol2 = Part.Wire(pol)
|
||||
@@ -308,16 +329,13 @@ class InvoluteGearRack(BaseGear):
|
||||
fcvec([0., np.tan(beta) * fp.height.Value / 2, fp.height.Value / 2]))
|
||||
pol3 = Part.Wire(pol)
|
||||
pol3.translate(fcvec([0., 0., fp.height.Value]))
|
||||
fp.Shape = makeLoft([pol, pol2, pol3], True, True)
|
||||
return makeLoft([pol, pol2, pol3], True, True)
|
||||
else:
|
||||
beta = fp.beta.Value * np.pi / 180.
|
||||
pol2 = Part.Wire(pol)
|
||||
pol2.translate(
|
||||
fcvec([0., np.tan(beta) * fp.height.Value, fp.height.Value]))
|
||||
fp.Shape = makeLoft([pol, pol2], True)
|
||||
# computed properties
|
||||
if "transverse_pitch" in fp.PropertiesList:
|
||||
fp.transverse_pitch = "{} mm".format(fp.rack.compute_properties()[2])
|
||||
return makeLoft([pol, pol2], True)
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@@ -396,8 +414,7 @@ class CrownGear(BaseGear):
|
||||
pts.append(pts[0])
|
||||
return pts
|
||||
|
||||
def execute(self, fp):
|
||||
super(CrownGear, self).execute(fp)
|
||||
def generate_gear_shape(self, fp):
|
||||
inner_diameter = fp.module.Value * fp.teeth
|
||||
outer_diameter = inner_diameter + fp.height.Value * 2
|
||||
inner_circle = Part.Wire(Part.makeCircle(inner_diameter / 2.))
|
||||
@@ -405,6 +422,8 @@ class CrownGear(BaseGear):
|
||||
inner_circle.reverse()
|
||||
face = Part.Face([outer_circle, inner_circle])
|
||||
solid = face.extrude(App.Vector([0., 0., -fp.thickness.Value]))
|
||||
if fp.preview_mode:
|
||||
return solid
|
||||
|
||||
# cutting obj
|
||||
alpha_w = np.deg2rad(fp.pressure_angle.Value)
|
||||
@@ -426,17 +445,11 @@ class CrownGear(BaseGear):
|
||||
loft = makeLoft(polies, True)
|
||||
rot = App.Matrix()
|
||||
rot.rotateZ(2 * np.pi / t)
|
||||
if fp.preview_mode:
|
||||
cut_shapes = [solid]
|
||||
for _ in range(t):
|
||||
loft = loft.transformGeometry(rot)
|
||||
cut_shapes.append(loft)
|
||||
fp.Shape = Part.Compound(cut_shapes)
|
||||
else:
|
||||
for i in range(t):
|
||||
loft = loft.transformGeometry(rot)
|
||||
solid = solid.cut(loft)
|
||||
fp.Shape = solid
|
||||
cut_shapes = []
|
||||
for _ in range(t):
|
||||
loft = loft.transformGeometry(rot)
|
||||
cut_shapes.append(loft)
|
||||
return solid.cut(cut_shapes)
|
||||
|
||||
def __getstate__(self):
|
||||
pass
|
||||
@@ -465,6 +478,7 @@ class CycloidGear(BaseGear):
|
||||
"App::PropertyBool", "double_helix", "gear_parameter", "double helix")
|
||||
obj.addProperty(
|
||||
"App::PropertyFloat", "clearance", "gear_parameter", "clearance")
|
||||
self._add_head_property(obj)
|
||||
obj.addProperty("App::PropertyInteger", "numpoints",
|
||||
"precision", "number of points for spline")
|
||||
obj.addProperty("App::PropertyAngle", "beta", "gear_parameter", "beta")
|
||||
@@ -485,15 +499,24 @@ class CycloidGear(BaseGear):
|
||||
obj.double_helix = False
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
super(CycloidGear, self).execute(fp)
|
||||
def _add_head_property(self, obj):
|
||||
obj.addProperty("App::PropertyFloat", "head", "gear_parameter",
|
||||
"head * modul = additional length of addendum")
|
||||
obj.head = 0.0
|
||||
|
||||
def generate_gear_shape(self, fp):
|
||||
fp.gear.m = fp.module.Value
|
||||
fp.gear.z = fp.teeth
|
||||
fp.gear.z1 = fp.inner_diameter.Value
|
||||
fp.gear.z2 = fp.outer_diameter.Value
|
||||
fp.gear.clearance = fp.clearance
|
||||
# check backward compatibility:
|
||||
if not "head" in fp.PropertiesList:
|
||||
self._add_head_property(fp)
|
||||
fp.gear.head = fp.head
|
||||
fp.gear.backlash = fp.backlash.Value
|
||||
fp.gear._update()
|
||||
|
||||
pts = fp.gear.points(num=fp.numpoints)
|
||||
rotated_pts = pts
|
||||
rot = rotation(-fp.gear.phipart)
|
||||
@@ -509,12 +532,12 @@ class CycloidGear(BaseGear):
|
||||
wi.append(out.toShape())
|
||||
wi = Wire(wi)
|
||||
if fp.height.Value == 0:
|
||||
fp.Shape = wi
|
||||
return wi
|
||||
elif fp.beta.Value == 0:
|
||||
sh = Face(wi)
|
||||
fp.Shape = sh.extrude(App.Vector(0, 0, fp.height.Value))
|
||||
return sh.extrude(App.Vector(0, 0, fp.height.Value))
|
||||
else:
|
||||
fp.Shape = helicalextrusion(
|
||||
return helicalextrusion(
|
||||
wi, fp.height.Value, fp.height.Value * np.tan(fp.beta.Value * np.pi / 180) * 2 / fp.gear.d, fp.double_helix)
|
||||
|
||||
def __getstate__(self):
|
||||
@@ -569,8 +592,7 @@ class BevelGear(BaseGear):
|
||||
self.obj = obj
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
super(BevelGear, self).execute(fp)
|
||||
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.
|
||||
@@ -618,8 +640,8 @@ class BevelGear(BaseGear):
|
||||
mat.A33 = -1
|
||||
mat.move(fcvec([0, 0, scale_1]))
|
||||
shape = shape.transformGeometry(mat)
|
||||
fp.Shape = shape
|
||||
# fp.Shape = self.create_teeth(pts, pos1, fp.teeth)
|
||||
return shape
|
||||
# return self.create_teeth(pts, pos1, fp.teeth)
|
||||
|
||||
def create_tooth(self):
|
||||
w = []
|
||||
@@ -692,8 +714,7 @@ class WormGear(BaseGear):
|
||||
self.obj = obj
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
super(WormGear, self).execute(fp)
|
||||
def generate_gear_shape(self, fp):
|
||||
m = fp.module.Value
|
||||
d = fp.diameter.Value
|
||||
t = fp.teeth
|
||||
@@ -761,12 +782,12 @@ class WormGear(BaseGear):
|
||||
|
||||
full_wire = Part.Wire(Part.Wire(w_all))
|
||||
if h == 0:
|
||||
fp.Shape = full_wire
|
||||
return full_wire
|
||||
else:
|
||||
shape = helicalextrusion(full_wire,
|
||||
h,
|
||||
h * np.tan(beta) * 2 / d)
|
||||
fp.Shape = shape
|
||||
return shape
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@@ -823,8 +844,7 @@ class TimingGear(BaseGear):
|
||||
self.obj = obj
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
super(TimingGear, self).execute(fp)
|
||||
def generate_gear_shape(self, fp):
|
||||
# m ... center of arc/circle
|
||||
# r ... radius of arc/circle
|
||||
# x ... end-point of arc
|
||||
@@ -902,9 +922,9 @@ class TimingGear(BaseGear):
|
||||
|
||||
wi = Part.Wire(wires)
|
||||
if fp.height.Value == 0:
|
||||
fp.Shape = wi
|
||||
return wi
|
||||
else:
|
||||
fp.Shape = Part.Face(wi).extrude(App.Vector(0, 0, fp.height))
|
||||
return Part.Face(wi).extrude(App.Vector(0, 0, fp.height))
|
||||
|
||||
def __getstate__(self):
|
||||
pass
|
||||
@@ -939,8 +959,7 @@ class LanternGear(BaseGear):
|
||||
self.obj = obj
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, fp):
|
||||
super(LanternGear, self).execute(fp)
|
||||
def generate_gear_shape(self, fp):
|
||||
m = fp.module.Value
|
||||
teeth = fp.teeth
|
||||
r_r = fp.bolt_radius.Value
|
||||
@@ -995,9 +1014,9 @@ class LanternGear(BaseGear):
|
||||
|
||||
wi = Part.Wire(wires)
|
||||
if fp.height.Value == 0:
|
||||
fp.Shape = wi
|
||||
return wi
|
||||
else:
|
||||
fp.Shape = Part.Face(wi).extrude(App.Vector(0, 0, fp.height))
|
||||
return Part.Face(wi).extrude(App.Vector(0, 0, fp.height))
|
||||
|
||||
def __getstate__(self):
|
||||
pass
|
||||
@@ -1090,8 +1109,7 @@ class HypoCycloidGear(BaseGear):
|
||||
x, y = self.to_rect(r, a)
|
||||
return x, y
|
||||
|
||||
def execute(self,fp):
|
||||
super(HypoCycloidGear, self).execute(fp)
|
||||
def generate_gear_shape(self, fp):
|
||||
b = fp.pin_circle_radius
|
||||
d = fp.roller_diameter
|
||||
e = fp.eccentricity
|
||||
@@ -1198,7 +1216,7 @@ class HypoCycloidGear(BaseGear):
|
||||
to_be_fused.append(pins);
|
||||
|
||||
if to_be_fused:
|
||||
fp.Shape = Part.makeCompound(to_be_fused)
|
||||
return Part.makeCompound(to_be_fused)
|
||||
|
||||
def __getstate__(self):
|
||||
pass
|
||||
|
||||
25
package.xml
Normal file
25
package.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<package format="1" xmlns="https://wiki.freecad.org/Package_Metadata">
|
||||
<name>freecad.gears workbench</name>
|
||||
<description>A gear workbench for FreeCAD</description>
|
||||
<version>1.0</version>
|
||||
<date>2022-02-07</date>
|
||||
<maintainer email="sppedflyer@gmail.com">looooo</maintainer>
|
||||
<license file="LICENSE">GPL 3</license>
|
||||
<dep>scipy</dep>
|
||||
<url type="repository" branch="develop">https://github.com/looooo/freecad.gears</url>
|
||||
<url type="bugtracker">https://github.com/looooo/freecad.gears/issues</url>
|
||||
<url type="documentation">https://wiki.freecad.org/FCGear_Workbench</url>
|
||||
<icon>freecad/gears/icons/gearworkbench.svg</icon>
|
||||
|
||||
<content>
|
||||
<workbench>
|
||||
<classname>GearWorkbench</classname>
|
||||
<subdirectory>./</subdirectory>
|
||||
<freecadmin>0.19</freecadmin>
|
||||
<tag>gear</tag>
|
||||
<tag>gears</tag>
|
||||
</workbench>
|
||||
</content>
|
||||
|
||||
</package>
|
||||
@@ -25,10 +25,11 @@ from ._functions import rotation, reflection
|
||||
|
||||
|
||||
class CycloidTooth():
|
||||
def __init__(self, z1=5, z2=5, z=14, m=5, clearance=0.12, backlash=0.00):
|
||||
def __init__(self, z1=5, z2=5, z=14, m=5, clearance=0.12, backlash=0.00, head=0.0):
|
||||
self.m = m
|
||||
self.z = z
|
||||
self.clearance = clearance
|
||||
self.head = head
|
||||
self.backlash = backlash
|
||||
self.z1 = z1
|
||||
self.z2 = z2
|
||||
@@ -39,7 +40,7 @@ class CycloidTooth():
|
||||
self.d2 = self.z2 * self.m
|
||||
self.phi = self.m * pi
|
||||
self.d = self.z * self.m
|
||||
self.da = self.d + 2*self.m
|
||||
self.da = self.d + 2*self.m + self.head * self.m
|
||||
self.di = self.d - 2*self.m - self.clearance * self.m
|
||||
self.phipart = 2 * pi / self.z
|
||||
|
||||
@@ -103,5 +104,5 @@ class CycloidTooth():
|
||||
|
||||
def _update(self):
|
||||
self.__init__(m=self.m, z=self.z, z1=self.z1, z2=self.z2,
|
||||
clearance=self.clearance, backlash=self.backlash)
|
||||
clearance=self.clearance, backlash=self.backlash, head=self.head)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user