FreeCAD-macros
/
GenevaWheelGUI.py
201 строка · 5.8 Кб
1# see http://www.freecadweb.org/wiki/Macro_Geneva_Wheel_GUI
2
3#Creation of a Geneva Wheel with Parametric values By: Isaac Ayala (drei) & Mark Stephen (quick61)
4#This Macro creates the main parts of a Geneva Wheel Mechanism
5
6#It depends on six values that must be altered in the following code
7#The variables are a, b, n, p, t and h.
8
9#Definition for each variable
10# Input
11#a = Drive Crank Radius
12#b = Geneva Wheel Radius
13#p = Drive Pin Radius
14#t = Geneva Wheel Tolerance
15#h = Geneva Wheel Height
16#n = Driven Slot Quantity
17# Output
18#c = Distance Between Centers
19#s = Slot Center Width
20#w = Slot Width
21#y = Stop Arc Radius
22#z = Stop Disc Radius
23#v = Clearance Arc
24
25#Please note that you can alter the code so it depends on five values exclusively
26#Just replace c, and either a or b with the following
27# Keep value for a
28#c = a/math.sin(math.pi/n)
29#b = math.sqrt((math.pow(c,2))-(math.pow(a,2)))
30# Keep value for b
31#c = b/math.cos(math.pi/n)
32#a = math.sqrt((math.pow(c,2))-(math.pow(b,2)))
33
34from __future__ import division
35import math
36from FreeCAD import Base
37from PySide import QtGui, QtCore
38from PySide.QtGui import QApplication, QDialog, QMainWindow
39import Part
40import Draft
41class p():
42
43
44def Ggear(self):
45
46try:
47#Inputs
48a = float(self.dCr.text())
49#b = float(self.gWr.text())
50p = float(self.dPd.text())
51t = float(self.gWt.text())
52h = float(self.gWh.text())
53n = float(self.gWn.text())
54
55#Outputs
56#c = math.sqrt(pow(a,2) + pow(b,2))
57c = a/math.sin(math.pi/n)
58b = math.sqrt((math.pow(c,2))-(math.pow(a,2)))
59s = a + b - c
60w = p + t
61y = a - (3 * p)
62z = y - t
63v = (b * z)/a
64m = math.sqrt((v**2)+(z**2)) # Solves for location of clearance cut axis
65
66# Create the Drive Crank (Will be placed on the origin)
67driveCrank = Part.makeCylinder(z, h)
68#driveCrank.translate(Base.Vector(0,0,0))
69
70#genevaWheelClearanceCut = Part.makeCylinder(b, h)
71#genevaWheelClearanceCut.translate(Base.Vector(-c,0,0))
72
73genevaWheelClearanceCut = Part.makeCylinder(v, h)
74genevaWheelClearanceCut.translate(Base.Vector(-m,0,0))
75
76driveCrank = driveCrank.cut(genevaWheelClearanceCut)
77
78driveCrankBase = Part.makeCylinder((a+(2*p)), h)
79driveCrankBase.translate(Base.Vector(0,0,-h))
80
81driveCrank = driveCrank.fuse(driveCrankBase)
82
83drivePin = Part.makeCylinder(p,h)
84drivePin.translate(Base.Vector(-a,0,0))
85
86driveCrank = driveCrank.fuse(drivePin)
87
88# Create the Geneva Wheel (Will be placed on the x-axis on the left side)
89genevaWheel = Part.makeCylinder(b,h)
90genevaWheel.translate(Base.Vector(-c,0,0))
91
92stopArc = Part.makeCylinder(y, h)
93stopArc.rotate(Base.Vector(-c,0,0),Base.Vector(0,0,1),(180/n))
94
95for i in range(int(n)):
96stopArc.rotate(Base.Vector(-c,0,0),Base.Vector(0,0,1),(360/n))
97genevaWheel = genevaWheel.cut(stopArc)
98
99slotLength = Part.makeBox(s,(2*w),h)
100slotLength.translate(Base.Vector(-a,-w,0))
101
102slotRadius = Part.makeCylinder(w,h)
103slotRadius.translate(Base.Vector(-a,0,0))
104
105slot=slotLength.fuse(slotRadius)
106
107for i in range(int(n)):
108slot.rotate(Base.Vector(-c,0,0),Base.Vector(0,0,1),(360/n))
109genevaWheel = genevaWheel.cut(slot)
110
111# Display Result
112
113Part.show(driveCrank)
114Part.show(genevaWheel)
115
116except:
117FreeCAD.Console.PrintError("Unable to complete task. Please recheck your data entries.")
118
119self.close()
120
121def close(self):
122self.dialog.hide()
123
124def __init__(self):
125self.dialog = None
126
127self.dialog = QtGui.QDialog()
128self.dialog.resize(240,100)
129
130self.dialog.setWindowTitle("Geneva Wheel Macro")
131la = QtGui.QVBoxLayout(self.dialog)
132
133DCR = QtGui.QLabel("Drive Crank Radius ( A )")
134la.addWidget(DCR)
135self.dCr = QtGui.QLineEdit()
136la.addWidget(self.dCr)
137
138#GWR = QtGui.QLabel("Geneva Wheel Radius ( B )")
139#la.addWidget(GWR)
140#self.gWr = QtGui.QLineEdit()
141#la.addWidget(self.gWr)
142
143DPD = QtGui.QLabel("Drive Pin Radius ( C )")
144la.addWidget(DPD)
145self.dPd = QtGui.QLineEdit()
146la.addWidget(self.dPd)
147
148GWT = QtGui.QLabel("Geneva Wheel Tolerance ( D )")
149la.addWidget(GWT)
150self.gWt = QtGui.QLineEdit()
151la.addWidget(self.gWt)
152
153GWH = QtGui.QLabel("Geneva Wheel Height")
154la.addWidget(GWH)
155self.gWh = QtGui.QLineEdit()
156la.addWidget(self.gWh)
157
158GWN = QtGui.QLabel("Driven Slot Quantity")
159la.addWidget(GWN)
160self.gWn = QtGui.QLineEdit()
161la.addWidget(self.gWn)
162
163#
164# - Include graphic image in dialog window -
165#
166# Insure that image is in the same directory as this Macro.
167# Image should be available from same source as Macro.
168#
169
170import os
171macro_dir='/tmp'
172try:
173macro_dir = os.path.dirname(__file__)
174except:
175pass
176self.PiX = QtGui.QLabel()
177self.PiX.setPixmap(os.path.join(macro_dir, "GW_Dim.png"))
178
179hbox = QtGui.QHBoxLayout()
180hbox.addStretch()
181hbox.addWidget(self.PiX)
182hbox.addStretch()
183
184la.addSpacing(15)
185la.addLayout(hbox)
186la.addSpacing(15)
187
188# - End Image layout -
189
190okbox = QtGui.QDialogButtonBox(self.dialog)
191okbox.setOrientation(QtCore.Qt.Horizontal)
192okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
193la.addWidget(okbox)
194QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.Ggear)
195QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
196QtCore.QMetaObject.connectSlotsByName(self.dialog)
197self.dialog.show()
198self.dialog.exec_()
199
200
201p()
202