Skip to content

Commit d77f5c1

Browse files
committed
connector: add support for racks
1 parent 4aa2559 commit d77f5c1

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

freecad/gears/connector.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import numpy as np
2222
import FreeCAD
2323
from pygears import __version__
24-
from .features import InvoluteGear, CycloidGear
24+
from .features import InvoluteGear, CycloidGear, InvoluteGearRack, CycloidGearRack
2525
from pygears.computation import compute_shifted_gears
2626

2727
class ViewProviderGearConnector(object):
@@ -37,9 +37,6 @@ def attach(self, vobj):
3737
def getIcon(self):
3838
return self.icon_fn
3939

40-
def claimChildren(self):
41-
return [self.vobj.Object.master_gear, self.vobj.Object.slave_gear]
42-
4340
def __getstate__(self):
4441
return {"icon_fn": self.icon_fn}
4542

@@ -90,14 +87,33 @@ def onChanged(self, fp, prop):
9087
mat1 = rot * mat0 * rot2 * rot3 * rot4
9188
mat1.move(fp.master_gear.Placement.Base)
9289
fp.slave_gear.Placement = mat1
90+
91+
if ((isinstance(fp.master_gear.Proxy, InvoluteGear) and isinstance(fp.slave_gear.Proxy, InvoluteGearRack))
92+
or (isinstance(fp.master_gear.Proxy, CycloidGear) and isinstance(fp.slave_gear.Proxy, CycloidGearRack))):
93+
fp.master_gear.Placement.Rotation.Angle = np.deg2rad(fp.angle2.Value)
94+
angle_master = fp.master_gear.Placement.Rotation.Angle
95+
dw_master = fp.master_gear.dw.Value
96+
dw_slave = 0
97+
dist = -(dw_master + dw_slave) / 2
98+
mat0 = FreeCAD.Matrix() # unity matrix
99+
mat0.move(FreeCAD.Vector(dist, 0, 0))
100+
mat1 = FreeCAD.Matrix()
101+
mat1.move(FreeCAD.Vector(0, np.deg2rad(fp.angle1.Value) * dw_master / 2, 0))
102+
mat2 = FreeCAD.Matrix()
103+
mat2.move(FreeCAD.Vector(0, -np.deg2rad(fp.angle2.Value) * dw_master / 2, 0))
104+
rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,1), fp.angle1).toMatrix()
105+
mat3 = rot * mat2 *mat1 * mat0
106+
mat3.move(fp.master_gear.Placement.Base)
107+
fp.slave_gear.Placement = mat3
108+
93109
if isinstance(fp.master_gear.Proxy, CycloidGear) and isinstance(fp.slave_gear.Proxy, CycloidGear):
94110
fp.master_gear.Placement.Rotation.Angle = np.deg2rad(fp.angle2.Value)
95111
angle_master = fp.master_gear.Placement.Rotation.Angle
96112
dw_master = fp.master_gear.dw
97113
dw_slave = fp.slave_gear.dw
98114
dist = (dw_master + dw_slave) / 2
99115
mat0 = FreeCAD.Matrix() # unity matrix
100-
trans = FreeCAD.Vector(dist)
116+
trans = FreeCAD.Vector(dist, 0, 0)
101117
mat0.move(trans)
102118
rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,1), fp.angle1).toMatrix()
103119
angle2 = dw_master / dw_slave * fp.angle1.Value
@@ -109,6 +125,7 @@ def onChanged(self, fp, prop):
109125
mat1 = rot * mat0 * rot2 * rot3 * rot4
110126
mat1.move(fp.master_gear.Placement.Base)
111127
fp.slave_gear.Placement = mat1
128+
112129
def execute(self, fp):
113130
self.onChanged(fp, None)
114131

0 commit comments

Comments
 (0)