[PartDesign] Linting and cleaning superfluous whitespace (#4851)
* [PartDesign] Linted Mod/PartDesign/Scripts for pep8 compliance * [PartDesign] Fix superfluous whitespace in WizardShaft/ * Added spaces per @chennes's feedback
This commit is contained in:
@@ -13,108 +13,120 @@ import math
|
||||
|
||||
# 3d vector class
|
||||
class Vector:
|
||||
def __init__(self,x,y,z):
|
||||
self.x=x
|
||||
self.y=y
|
||||
self.z=z
|
||||
def add(self,vec):
|
||||
return Vector(self.x+vec.x,self.y+vec.y,self.z+vec.z)
|
||||
def sub(self,vec):
|
||||
return Vector(self.x-vec.x,self.y-vec.y,self.z-vec.z)
|
||||
def dot(self,vec):
|
||||
return self.x*vec.x+self.y*vec.y+self.z*vec.z
|
||||
def mult(self,s):
|
||||
return Vector(self.x*s,self.y*s,self.z*s)
|
||||
def cross(self,vec):
|
||||
return Vector(
|
||||
self.y * vec.z - self.z * vec.y,
|
||||
self.z * vec.x - self.x * vec.z,
|
||||
self.x * vec.y - self.y * vec.x)
|
||||
def length(self):
|
||||
return math.sqrt(self.x*self.x+self.y*self.y+self.z*self.z)
|
||||
def norm(self):
|
||||
l = self.length()
|
||||
if l > 0:
|
||||
self.x /= l
|
||||
self.y /= l
|
||||
self.z /= l
|
||||
def __repr__(self):
|
||||
return "(%f,%f,%f)" % (self.x,self.y,self.z)
|
||||
def __init__(self, x, y, z):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.z = z
|
||||
|
||||
def add(self, vec):
|
||||
return Vector(self.x+vec.x, self.y+vec.y, self.z+vec.z)
|
||||
|
||||
def sub(self, vec):
|
||||
return Vector(self.x-vec.x, self.y-vec.y, self.z-vec.z)
|
||||
|
||||
def dot(self, vec):
|
||||
return self.x*vec.x+self.y*vec.y+self.z*vec.z
|
||||
|
||||
def mult(self, s):
|
||||
return Vector(self.x*s, self.y*s, self.z*s)
|
||||
|
||||
def cross(self,vec):
|
||||
return Vector(
|
||||
self.y * vec.z - self.z * vec.y,
|
||||
self.z * vec.x - self.x * vec.z,
|
||||
self.x * vec.y - self.y * vec.x)
|
||||
|
||||
def length(self):
|
||||
return math.sqrt(self.x*self.x+self.y*self.y+self.z*self.z)
|
||||
|
||||
def norm(self):
|
||||
l = self.length()
|
||||
if l > 0:
|
||||
self.x /= l
|
||||
self.y /= l
|
||||
self.z /= l
|
||||
|
||||
def __repr__(self):
|
||||
return "(%f,%f,%f)" % (self.x, self.y, self.z)
|
||||
|
||||
|
||||
# A signum function
|
||||
def sgn(val):
|
||||
if val > 0:
|
||||
return 1
|
||||
elif val < 0:
|
||||
return -1
|
||||
else:
|
||||
return 0
|
||||
if val > 0:
|
||||
return 1
|
||||
elif val < 0:
|
||||
return -1
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
# M1 ... is the center of the arc
|
||||
# P ... is the end point of the arc and start point of the line
|
||||
# Q .. is a second point on the line
|
||||
# N ... is the normal of the plane where the arc and the line lie on, usually N=(0,0,1)
|
||||
# N ... is the normal of the plane where the arc and the line lie on, usually N=(0,0,1)
|
||||
# r2 ... the fillet radius
|
||||
# ccw ... counter-clockwise means which part of the arc is given. ccw must be either True or False
|
||||
# ccw ... counter-clockwise means which part of the arc is given. ccw must be either True or False
|
||||
|
||||
|
||||
def makeFilletArc(M1,P,Q,N,r2,ccw):
|
||||
u = Q.sub(P)
|
||||
v = P.sub(M1)
|
||||
if ccw:
|
||||
b = u.cross(N)
|
||||
else:
|
||||
b = N.cross(u)
|
||||
b.norm()
|
||||
|
||||
uu = u.dot(u)
|
||||
uv = u.dot(v)
|
||||
r1 = v.length()
|
||||
u = Q.sub(P)
|
||||
v = P.sub(M1)
|
||||
if ccw:
|
||||
b = u.cross(N)
|
||||
else:
|
||||
b = N.cross(u)
|
||||
b.norm()
|
||||
|
||||
uu = u.dot(u)
|
||||
uv = u.dot(v)
|
||||
r1 = v.length()
|
||||
|
||||
# distinguish between internal and external fillets
|
||||
r2 *= sgn(uv)
|
||||
|
||||
cc = 2.0 * r2 * (b.dot(v)-r1)
|
||||
dd = uv * uv - uu * cc
|
||||
if dd < 0:
|
||||
raise RuntimeError("Unable to calculate intersection points")
|
||||
t1 = (-uv + math.sqrt(dd)) / uu
|
||||
t2 = (-uv - math.sqrt(dd)) / uu
|
||||
|
||||
if (abs(t1) < abs(t2)):
|
||||
t = t1
|
||||
else:
|
||||
t = t2
|
||||
|
||||
br2 = b.mult(r2)
|
||||
print(br2)
|
||||
ut = u.mult(t)
|
||||
print(ut)
|
||||
M2 = P.add(ut).add(br2)
|
||||
S1 = M1.mult(r2/(r1+r2)).add(M2.mult(r1/(r1+r2)))
|
||||
S2 = M2.sub(br2)
|
||||
|
||||
return (S1, S2, M2)
|
||||
|
||||
# distinguish between internal and external fillets
|
||||
r2 *= sgn(uv);
|
||||
|
||||
cc = 2.0 * r2 * (b.dot(v)-r1)
|
||||
dd = uv * uv - uu * cc
|
||||
if dd < 0:
|
||||
raise RuntimeError("Unable to calculate intersection points")
|
||||
t1 = (-uv + math.sqrt(dd)) / uu
|
||||
t2 = (-uv - math.sqrt(dd)) / uu
|
||||
|
||||
if (abs(t1) < abs(t2)):
|
||||
t = t1
|
||||
else:
|
||||
t = t2
|
||||
|
||||
br2 = b.mult(r2)
|
||||
print(br2)
|
||||
ut = u.mult(t)
|
||||
print(ut)
|
||||
M2 = P.add(ut).add(br2)
|
||||
S1 = M1.mult(r2/(r1+r2)).add(M2.mult(r1/(r1+r2)))
|
||||
S2 = M2.sub(br2)
|
||||
|
||||
return (S1,S2,M2)
|
||||
|
||||
|
||||
|
||||
def test():
|
||||
from FreeCAD import Base
|
||||
import Part
|
||||
from FreeCAD import Base
|
||||
import Part
|
||||
|
||||
P1=Base.Vector(1,-5,0)
|
||||
P2=Base.Vector(-5,2,0)
|
||||
P3=Base.Vector(1,5,0)
|
||||
#Q=Base.Vector(5,10,0)
|
||||
#Q=Base.Vector(5,11,0)
|
||||
Q=Base.Vector(5,0,0)
|
||||
r2=3.0
|
||||
axis=Base.Vector(0,0,1)
|
||||
ccw=False
|
||||
P1 = Base.Vector(1, -5, 0)
|
||||
P2 = Base.Vector(-5, 2, 0)
|
||||
P3 = Base.Vector(1, 5, 0)
|
||||
# Q = Base.Vector(5, 10, 0)
|
||||
# Q = Base.Vector(5, 11, 0)
|
||||
Q = Base.Vector(5, 0, 0)
|
||||
r2 = 3.0
|
||||
axis = Base.Vector(0, 0, 1)
|
||||
ccw = False
|
||||
|
||||
arc=Part.ArcOfCircle(P1,P2,P3)
|
||||
C=arc.Center
|
||||
Part.show(Part.makeLine(P3,Q))
|
||||
Part.show(arc.toShape())
|
||||
arc = Part.ArcOfCircle(P1, P2, P3)
|
||||
C = arc.Center
|
||||
Part.show(Part.makeLine(P3, Q))
|
||||
Part.show(arc.toShape())
|
||||
|
||||
(S1,S2,M2) = makeArc(Vector(C.x,C.y,C.z),Vector(P3.x,P3.y,P3.z),Vector(Q.x,Q.y,Q.z),Vector(axis.x,axis.y,axis.z),r2,ccw)
|
||||
circle=Part.Circle(Base.Vector(M2.x,M2.y,M2.z), Base.Vector(0,0,1), math.fabs(r2))
|
||||
Part.show(circle.toShape())
|
||||
(S1, S2, M2) = makeArc(Vector(C.x,C.y,C.z), Vector(P3.x,P3.y,P3.z), Vector(Q.x, Q.y, Q.z), Vector(axis.x, axis.y, axis.z), r2, ccw)
|
||||
circle = Part.Circle(Base.Vector(M2.x, M2.y, M2.z), Base.Vector(0, 0, 1), math.fabs(r2))
|
||||
Part.show(circle.toShape())
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
#Involute Gears Generation Script
|
||||
#by Marcin Wanczyk (dj_who)
|
||||
#(c) 2011 LGPL
|
||||
# Involute Gears Generation Script
|
||||
# by Marcin Wanczyk (dj_who)
|
||||
# (c) 2011 LGPL
|
||||
|
||||
|
||||
import FreeCAD, FreeCADGui, Part, Draft, math, MeshPart, Mesh
|
||||
from PySide import QtGui,QtCore
|
||||
App=FreeCAD
|
||||
Gui=FreeCADGui
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
import Part
|
||||
import Draft
|
||||
import MeshPart
|
||||
import Mesh
|
||||
import math
|
||||
from PySide import QtGui, QtCore
|
||||
|
||||
App = FreeCAD
|
||||
Gui = FreeCADGui
|
||||
|
||||
|
||||
def proceed():
|
||||
try:
|
||||
@@ -15,150 +23,150 @@ def proceed():
|
||||
hide()
|
||||
QtGui.QApplication.restoreOverrideCursor()
|
||||
|
||||
def compute():
|
||||
|
||||
def compute():
|
||||
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
|
||||
if FreeCAD.ActiveDocument is None:
|
||||
FreeCAD.newDocument("Gear")
|
||||
|
||||
oldDocumentObjects=App.ActiveDocument.Objects
|
||||
oldDocumentObjects = App.ActiveDocument.Objects
|
||||
|
||||
try:
|
||||
N = int(l1.text())
|
||||
N = int(l1.text())
|
||||
p = float(l2.text())
|
||||
alfa = int(l3.text())
|
||||
y = float(l4.text()) #standard value y<1 for gear drives y>1 for Gear pumps
|
||||
m=p/math.pi #standard value 0.06, 0.12, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 60 (polish norm)
|
||||
c = float(l5.text())*m #standard value 0,1*m - 0,3*m
|
||||
j = float(l6.text())*m #standard value 0,015 - 0,04*m
|
||||
width = float(l7.text()) #gear width
|
||||
y = float(l4.text()) # standard value y<1 for gear drives y>1 for Gear pumps
|
||||
m = p/math.pi # standard value 0.06, 0.12, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 60 (polish norm)
|
||||
c = float(l5.text())*m # standard value 0,1*m - 0,3*m
|
||||
j = float(l6.text())*m # standard value 0,015 - 0,04*m
|
||||
width = float(l7.text()) # gear width
|
||||
except ValueError:
|
||||
FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
|
||||
|
||||
|
||||
#tooth height
|
||||
h=2*y*m+c
|
||||
|
||||
#pitch diameter
|
||||
d=N*m
|
||||
|
||||
#root diameter
|
||||
df=d - 2*y*m - 2*c #df=d-2hf where and hf=y*m+c
|
||||
# tooth height
|
||||
h = 2*y*m+c
|
||||
|
||||
#addendum diameter
|
||||
da=d + 2*y*m #da=d+2ha where ha=y*m
|
||||
# pitch diameter
|
||||
d = N*m
|
||||
|
||||
#base diameter for involute
|
||||
db=d * math.cos(math.radians(alfa))
|
||||
# root diameter
|
||||
df = d - 2*y*m - 2*c # df=d-2hf where and hf=y*m+c
|
||||
|
||||
# addendum diameter
|
||||
da = d + 2*y*m # da=d+2ha where ha=y*m
|
||||
|
||||
# base diameter for involute
|
||||
db = d * math.cos(math.radians(alfa))
|
||||
|
||||
|
||||
#Base circle
|
||||
baseCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","BaseCircle")
|
||||
baseCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "BaseCircle")
|
||||
Draft._Circle(baseCircle)
|
||||
Draft._ViewProviderDraft(baseCircle.ViewObject)
|
||||
baseCircle.Radius = db/2
|
||||
baseCircle.FirstAngle=0.0
|
||||
baseCircle.LastAngle=0.0
|
||||
|
||||
#Root circle
|
||||
rootCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","RootCircle")
|
||||
baseCircle.FirstAngle = 0.0
|
||||
baseCircle.LastAngle = 0.0
|
||||
|
||||
# Root circle
|
||||
rootCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "RootCircle")
|
||||
Draft._Circle(rootCircle)
|
||||
Draft._ViewProviderDraft(rootCircle.ViewObject)
|
||||
rootCircle.Radius = df/2
|
||||
rootCircle.FirstAngle=0.0
|
||||
rootCircle.LastAngle=0.0
|
||||
rootCircle.FirstAngle = 0.0
|
||||
rootCircle.LastAngle = 0.0
|
||||
|
||||
#Addendum circle
|
||||
addendumCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","AddendumCircle")
|
||||
# Addendum circle
|
||||
addendumCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "AddendumCircle")
|
||||
Draft._Circle(addendumCircle)
|
||||
Draft._ViewProviderDraft(addendumCircle.ViewObject)
|
||||
addendumCircle.Radius = da/2
|
||||
addendumCircle.FirstAngle=0.0
|
||||
addendumCircle.LastAngle=0.0
|
||||
addendumCircle.FirstAngle = 0.0
|
||||
addendumCircle.LastAngle = 0.0
|
||||
|
||||
#Pitch circle
|
||||
pitchCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","PitchCircle")
|
||||
# Pitch circle
|
||||
pitchCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "PitchCircle")
|
||||
Draft._Circle(pitchCircle)
|
||||
Draft._ViewProviderDraft(pitchCircle.ViewObject)
|
||||
pitchCircle.Radius = d/2
|
||||
pitchCircle.FirstAngle=0.0
|
||||
pitchCircle.LastAngle=0.0
|
||||
pitchCircle.FirstAngle = 0.0
|
||||
pitchCircle.LastAngle = 0.0
|
||||
|
||||
#************ Calculating right sides of teeth
|
||||
#Involute of base circle
|
||||
involute=[]
|
||||
involutee=[]
|
||||
involutesav=[]
|
||||
# Involute of base circle
|
||||
involute = []
|
||||
involutee = []
|
||||
involutesav = []
|
||||
|
||||
for t in range(0,60,1):
|
||||
x=db/2*(math.cos(math.radians(t))+math.radians(t)*math.sin(math.radians(t)))
|
||||
y=db/2*(math.sin(math.radians(t))-math.radians(t)*math.cos(math.radians(t)))
|
||||
involute.append(Part.Vertex(x,y,0).Point)
|
||||
for t in range(0, 60, 1):
|
||||
x = db/2*(math.cos(math.radians(t))+math.radians(t)*math.sin(math.radians(t)))
|
||||
y = db/2*(math.sin(math.radians(t))-math.radians(t)*math.cos(math.radians(t)))
|
||||
involute.append(Part.Vertex(x, y, 0).Point)
|
||||
|
||||
#************ Drawing right sides of teeth
|
||||
#************ Drawing right sides of teeth
|
||||
involutesav.extend(involute)
|
||||
involutee.extend(involute)
|
||||
|
||||
for angle in range(1,N+1,1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature","InvoluteL"+str(angle))
|
||||
involutee.insert(0,(0,0,0))
|
||||
involuteshape = Part.makePolygon(involutee)
|
||||
for angle in range(1, N+1, 1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature", "InvoluteL" + str(angle))
|
||||
involutee.insert(0, (0, 0, 0))
|
||||
involuteshape = Part.makePolygon(involutee)
|
||||
involuteobj.Shape=involuteshape
|
||||
involutee=[]
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
involutee = []
|
||||
for num in range(0, 60, 1):
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
involute.extend(involutesav)
|
||||
involutee=[]
|
||||
|
||||
involutee = []
|
||||
|
||||
#************ Calculating difference between tooth spacing on BaseCircle and PitchCircle
|
||||
|
||||
pc=App.ActiveDocument.getObject("PitchCircle")
|
||||
inv=App.ActiveDocument.getObject("InvoluteL1")
|
||||
cut=inv.Shape.cut(pc.Shape)
|
||||
pc = App.ActiveDocument.getObject("PitchCircle")
|
||||
inv = App.ActiveDocument.getObject("InvoluteL1")
|
||||
cut = inv.Shape.cut(pc.Shape)
|
||||
# FreeCAD.ActiveDocument.addObject("Part::Feature","CutInv").Shape=cut
|
||||
invPoint=cut.Vertexes[0].Point
|
||||
invPoint = cut.Vertexes[0].Point
|
||||
|
||||
|
||||
diff=invPoint.y*2 # instead of making axial symmetry and calculating point distance.
|
||||
anglediff=2*math.asin(diff/d)
|
||||
diff = invPoint.y*2 # instead of making axial symmetry and calculating point distance.
|
||||
anglediff = 2*math.asin(diff/d)
|
||||
|
||||
#************ Calculating left sides of teeth
|
||||
|
||||
#************ Inversing Involute
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x,point.y*-1,0).Point
|
||||
involutee.insert(0,pointt)
|
||||
for num in range(0, 60, 1):
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x, point.y*-1, 0).Point
|
||||
involutee.insert(0, pointt)
|
||||
involute.extend(involutee)
|
||||
involutee=[]
|
||||
involutee = []
|
||||
|
||||
#Normal tooth size calculated as: 0,5* p - j j=m * 0,1 below are calculations
|
||||
#Normal tooth size calculated as: 0,5* p - j j = m * 0,1 below are calculations
|
||||
# 0,5* p - m * 0,1
|
||||
# 0,5* p - p /pi * 0,1
|
||||
# 0,5*360/N - ((360/N)/pi)* 0,1
|
||||
# 0,5*360/N - (360/N)*((1/pi)*0,1) j=(p/pi)*0,1
|
||||
# 0,5*360/N - (360/N)*((1/pi)*0,1) j = (p/pi)*0,1
|
||||
# 0,5*360/N - (360/N)*((p/pi)*0,1)/p
|
||||
# 0,5*360/N - (360/N)*( j )/p
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff) - point.y*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff),point.x*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff) + point.y*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
for num in range(0, 60, 1):
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff) - point.y*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff),point.x*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff) + point.y*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff),0).Point
|
||||
involutee.insert(0, pointt)
|
||||
involute.extend(involutee)
|
||||
involutesav=[]
|
||||
involutesav = []
|
||||
involutesav.extend(involute)
|
||||
|
||||
#************ Drawing left sides of teeth
|
||||
for angle in range(1,N+1,1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature","InvoluteR"+str(angle))
|
||||
involutee.insert(0,(0,0,0))
|
||||
for angle in range(1, N+1, 1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature", "InvoluteR" + str(angle))
|
||||
involutee.insert(0, (0, 0, 0))
|
||||
involuteshape = Part.makePolygon(involutee)
|
||||
involuteobj.Shape=involuteshape
|
||||
involutee=[]
|
||||
involuteobj.Shape = involuteshape
|
||||
involutee = []
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
point = involute.pop()
|
||||
pointt = Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
involute.extend(involutesav)
|
||||
|
||||
@@ -166,56 +174,56 @@ def compute():
|
||||
|
||||
#************ Forming teeth
|
||||
|
||||
cutCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","CutCircle")
|
||||
cutCircle = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "CutCircle")
|
||||
Draft._Circle(cutCircle)
|
||||
Draft._ViewProviderDraft(cutCircle.ViewObject)
|
||||
cutCircle.Radius = da # da because must be bigger than addendumCircle and bigger than whole construction da is right for this but it not has to be.
|
||||
cutCircle.FirstAngle=0.0
|
||||
cutCircle.LastAngle=0.0
|
||||
cutCircle.Radius = da # da because must be bigger than addendumCircle and bigger than whole construction da is right for this but it not has to be.
|
||||
cutCircle.FirstAngle = 0.0
|
||||
cutCircle.LastAngle = 0.0
|
||||
|
||||
|
||||
cutTool=cutCircle.Shape.cut(addendumCircle.Shape)
|
||||
#cutshape=Part.show(cutTool)
|
||||
|
||||
gearShape=rootCircle.Shape
|
||||
|
||||
for invNum in range(1,N+1,1):
|
||||
invL=App.ActiveDocument.getObject("InvoluteL"+str(invNum))
|
||||
invR=App.ActiveDocument.getObject("InvoluteR"+str(invNum))
|
||||
cutL=invL.Shape.cut(cutTool)
|
||||
cutR=invR.Shape.cut(cutTool)
|
||||
pointL=cutL.Vertexes.pop().Point
|
||||
pointR=cutR.Vertexes.pop().Point
|
||||
faceEdge=Part.makeLine(pointL,pointR)
|
||||
|
||||
toothWhole=cutL.fuse(cutR)
|
||||
toothWhole=toothWhole.fuse(faceEdge)
|
||||
toothWire=Part.Wire(toothWhole.Edges)
|
||||
toothShape=Part.Face(toothWire)
|
||||
# tooth=App.ActiveDocument.addObject("Part::Feature","Tooth"+str(invNum))
|
||||
cutTool = cutCircle.Shape.cut(addendumCircle.Shape)
|
||||
# cutshape = Part.show(cutTool)
|
||||
|
||||
gearShape = rootCircle.Shape
|
||||
|
||||
for invNum in range(1, N+1, 1):
|
||||
invL = App.ActiveDocument.getObject("InvoluteL" + str(invNum))
|
||||
invR = App.ActiveDocument.getObject("InvoluteR" + str(invNum))
|
||||
cutL = invL.Shape.cut(cutTool)
|
||||
cutR = invR.Shape.cut(cutTool)
|
||||
pointL = cutL.Vertexes.pop().Point
|
||||
pointR = cutR.Vertexes.pop().Point
|
||||
faceEdge = Part.makeLine(pointL, pointR)
|
||||
|
||||
toothWhole = cutL.fuse(cutR)
|
||||
toothWhole = toothWhole.fuse(faceEdge)
|
||||
toothWire = Part.Wire(toothWhole.Edges)
|
||||
toothShape = Part.Face(toothWire)
|
||||
# tooth = App.ActiveDocument.addObject("Part::Feature", "Tooth" +str(invNum))
|
||||
# tooth.Shape=toothShape
|
||||
gearShape=gearShape.fuse(toothShape)
|
||||
gearShape = gearShape.fuse(toothShape)
|
||||
|
||||
|
||||
for o in App.ActiveDocument.Objects:
|
||||
if oldDocumentObjects.count(o)==0:
|
||||
if oldDocumentObjects.count(o) == 0:
|
||||
App.ActiveDocument.removeObject(o.Name)
|
||||
|
||||
gearFlat=App.ActiveDocument.addObject("Part::Feature","GearFlat")
|
||||
gearFlat.Shape=gearShape
|
||||
Gui.ActiveDocument.getObject(gearFlat.Name).Visibility=False
|
||||
gearFlat = App.ActiveDocument.addObject("Part::Feature", "GearFlat")
|
||||
gearFlat.Shape = gearShape
|
||||
Gui.ActiveDocument.getObject(gearFlat.Name).Visibility = False
|
||||
|
||||
gear=App.ActiveDocument.addObject("Part::Extrusion","Gear3D")
|
||||
gear.Base=gearFlat
|
||||
gear.Dir=(0,0,width)
|
||||
gear = App.ActiveDocument.addObject("Part::Extrusion", "Gear3D")
|
||||
gear.Base = gearFlat
|
||||
gear.Dir = (0, 0, width)
|
||||
App.ActiveDocument.recompute()
|
||||
|
||||
|
||||
|
||||
if c1.isChecked()==True:
|
||||
gearMesh=App.ActiveDocument.addObject("Mesh::Feature","Gear3D-mesh")
|
||||
gearMesh = App.ActiveDocument.addObject("Mesh::Feature", "Gear3D-mesh")
|
||||
|
||||
faces = []
|
||||
triangles = gear.Shape.tessellate(1) # the number represents the precision of the tessellation)
|
||||
triangles = gear.Shape.tessellate(1) # the number represents the precision of the tessellation)
|
||||
for tri in triangles[1]:
|
||||
face = []
|
||||
for i in range(3):
|
||||
@@ -224,16 +232,16 @@ def compute():
|
||||
faces.append(face)
|
||||
mesh = Mesh.Mesh(faces)
|
||||
|
||||
gearMesh.Mesh=mesh
|
||||
gearMesh.Mesh = mesh
|
||||
App.ActiveDocument.removeObject(gear.Name)
|
||||
App.ActiveDocument.removeObject(gearFlat.Name)
|
||||
|
||||
|
||||
App.ActiveDocument.recompute()
|
||||
Gui.SendMsgToActiveView("ViewFit")
|
||||
|
||||
|
||||
QtGui.QApplication.restoreOverrideCursor()
|
||||
|
||||
|
||||
|
||||
hide()
|
||||
|
||||
@@ -259,22 +267,22 @@ la.addWidget(t3)
|
||||
l3 = QtGui.QLineEdit()
|
||||
l3.setText("20")
|
||||
la.addWidget(l3)
|
||||
t4 = QtGui.QLabel("Tooth height factor (y)")
|
||||
t4 = QtGui.QLabel("Tooth height factor (y)")
|
||||
la.addWidget(t4)
|
||||
l4 = QtGui.QLineEdit()
|
||||
l4.setText("1.0")
|
||||
la.addWidget(l4)
|
||||
t5 = QtGui.QLabel("Tooth clearance (c)")
|
||||
t5 = QtGui.QLabel("Tooth clearance (c)")
|
||||
la.addWidget(t5)
|
||||
l5 = QtGui.QLineEdit()
|
||||
l5.setText("0.1")
|
||||
la.addWidget(l5)
|
||||
t6 = QtGui.QLabel("Tooth lateral clearance (j)")
|
||||
t6 = QtGui.QLabel("Tooth lateral clearance (j)")
|
||||
la.addWidget(t6)
|
||||
l6 = QtGui.QLineEdit()
|
||||
l6.setText("0.04")
|
||||
la.addWidget(l6)
|
||||
t7 = QtGui.QLabel("Gear width")
|
||||
t7 = QtGui.QLabel("Gear width")
|
||||
la.addWidget(t7)
|
||||
l7 = QtGui.QLineEdit()
|
||||
l7.setText("6.0")
|
||||
@@ -282,7 +290,7 @@ la.addWidget(l7)
|
||||
c1 = QtGui.QCheckBox("Create as a Mesh")
|
||||
la.addWidget(c1)
|
||||
e1 = QtGui.QLabel("(for faster rendering)")
|
||||
commentFont=QtGui.QFont("Times",8,True)
|
||||
commentFont = QtGui.QFont("Times", 8, True)
|
||||
e1.setFont(commentFont)
|
||||
la.addWidget(e1)
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ from FreeCAD import Base
|
||||
class MySpring:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Pitch, Diameter, Height, BarDiameter '''
|
||||
obj.addProperty("App::PropertyLength","Pitch","MySpring","Pitch of the helix").Pitch=5.0
|
||||
obj.addProperty("App::PropertyLength","Diameter","MySpring","Diameter of the helix").Diameter=6.0
|
||||
obj.addProperty("App::PropertyLength","Height","MySpring","Height of the helix").Height=30.0
|
||||
obj.addProperty("App::PropertyLength","BarDiameter","MySpring","Diameter of the bar").BarDiameter=3.0
|
||||
obj.addProperty("App::PropertyLength", "Pitch", "MySpring", "Pitch of the helix").Pitch = 5.0
|
||||
obj.addProperty("App::PropertyLength", "Diameter", "MySpring", "Diameter of the helix").Diameter = 6.0
|
||||
obj.addProperty("App::PropertyLength", "Height", "MySpring", "Height of the helix").Height = 30.0
|
||||
obj.addProperty("App::PropertyLength", "BarDiameter", "MySpring", "Diameter of the bar").BarDiameter = 3.0
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
@@ -24,28 +24,29 @@ class MySpring:
|
||||
radius = fp.Diameter/2
|
||||
height = fp.Height
|
||||
barradius = fp.BarDiameter/2
|
||||
myhelix=Part.makeHelix(pitch,height,radius)
|
||||
g=myhelix.Edges[0].Curve
|
||||
c=Part.Circle()
|
||||
c.Center=g.value(0) # start point of the helix
|
||||
c.Axis=(0,1,0)
|
||||
c.Radius=barradius
|
||||
p=c.toShape()
|
||||
myhelix = Part.makeHelix(pitch, height, radius)
|
||||
g = myhelix.Edges[0].Curve
|
||||
c = Part.Circle()
|
||||
c.Center = g.value(0) # start point of the helix
|
||||
c.Axis = (0, 1, 0)
|
||||
c.Radius = barradius
|
||||
p = c.toShape()
|
||||
section = Part.Wire([p])
|
||||
makeSolid=1 #change to 1 to make a solid
|
||||
isFrenet=1
|
||||
myspring=Part.Wire(myhelix).makePipeShell([section],makeSolid,isFrenet)
|
||||
makeSolid = 1 # change to 1 to make a solid
|
||||
isFrenet = 1
|
||||
myspring = Part.Wire(myhelix).makePipeShell([section], makeSolid, isFrenet)
|
||||
fp.Shape = myspring
|
||||
|
||||
def makeMySpring():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc is None:
|
||||
doc = FreeCAD.newDocument()
|
||||
spring=doc.addObject("Part::FeaturePython","My_Spring")
|
||||
spring = doc.addObject("Part::FeaturePython", "My_Spring")
|
||||
spring.Label = "My Spring"
|
||||
MySpring(spring)
|
||||
spring.ViewObject.Proxy=0
|
||||
spring.ViewObject.Proxy = 0
|
||||
doc.recompute()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
makeMySpring()
|
||||
|
||||
Reference in New Issue
Block a user