FreeCAD-macros

Форк
0
/
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

34
from __future__ import division
35
import math
36
from FreeCAD import Base
37
from PySide import QtGui, QtCore
38
from PySide.QtGui import QApplication, QDialog, QMainWindow
39
import Part
40
import Draft
41
class p():
42

43

44
   def Ggear(self):
45

46
      try:
47
         #Inputs
48
         a = float(self.dCr.text())
49
         #b = float(self.gWr.text())
50
         p = float(self.dPd.text())
51
         t = float(self.gWt.text())
52
         h = float(self.gWh.text())
53
         n = float(self.gWn.text())
54

55
         #Outputs
56
         #c = math.sqrt(pow(a,2) + pow(b,2))
57
         c = a/math.sin(math.pi/n)
58
         b = math.sqrt((math.pow(c,2))-(math.pow(a,2)))
59
         s = a + b - c
60
         w = p + t
61
         y = a - (3 * p)
62
         z = y - t
63
         v = (b * z)/a
64
         m = 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)
67
         driveCrank = 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

73
         genevaWheelClearanceCut = Part.makeCylinder(v, h)
74
         genevaWheelClearanceCut.translate(Base.Vector(-m,0,0))
75

76
         driveCrank = driveCrank.cut(genevaWheelClearanceCut)
77

78
         driveCrankBase = Part.makeCylinder((a+(2*p)), h)
79
         driveCrankBase.translate(Base.Vector(0,0,-h))
80

81
         driveCrank = driveCrank.fuse(driveCrankBase)
82

83
         drivePin = Part.makeCylinder(p,h)
84
         drivePin.translate(Base.Vector(-a,0,0))
85

86
         driveCrank = driveCrank.fuse(drivePin)
87

88
         #    Create the Geneva  Wheel (Will be placed on the x-axis on the left side)
89
         genevaWheel = Part.makeCylinder(b,h)
90
         genevaWheel.translate(Base.Vector(-c,0,0))
91

92
         stopArc = Part.makeCylinder(y, h)
93
         stopArc.rotate(Base.Vector(-c,0,0),Base.Vector(0,0,1),(180/n))
94

95
         for i in range(int(n)):
96
            stopArc.rotate(Base.Vector(-c,0,0),Base.Vector(0,0,1),(360/n))
97
            genevaWheel = genevaWheel.cut(stopArc)
98

99
         slotLength = Part.makeBox(s,(2*w),h)
100
         slotLength.translate(Base.Vector(-a,-w,0))
101

102
         slotRadius = Part.makeCylinder(w,h)
103
         slotRadius.translate(Base.Vector(-a,0,0))
104

105
         slot=slotLength.fuse(slotRadius)
106

107
         for i in range(int(n)):
108
            slot.rotate(Base.Vector(-c,0,0),Base.Vector(0,0,1),(360/n))
109
            genevaWheel = genevaWheel.cut(slot)
110

111
         #    Display Result
112

113
         Part.show(driveCrank)
114
         Part.show(genevaWheel)
115

116
      except:
117
         FreeCAD.Console.PrintError("Unable to complete task. Please recheck your data entries.")
118

119
      self.close()
120

121
   def close(self):
122
      self.dialog.hide()
123

124
   def __init__(self):
125
      self.dialog = None
126

127
      self.dialog = QtGui.QDialog()
128
      self.dialog.resize(240,100)
129

130
      self.dialog.setWindowTitle("Geneva Wheel Macro")
131
      la = QtGui.QVBoxLayout(self.dialog)
132

133
      DCR = QtGui.QLabel("Drive Crank Radius ( A )")
134
      la.addWidget(DCR)
135
      self.dCr = QtGui.QLineEdit()
136
      la.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

143
      DPD = QtGui.QLabel("Drive Pin Radius ( C )")
144
      la.addWidget(DPD)
145
      self.dPd = QtGui.QLineEdit()
146
      la.addWidget(self.dPd)
147

148
      GWT = QtGui.QLabel("Geneva Wheel Tolerance ( D )")
149
      la.addWidget(GWT)
150
      self.gWt = QtGui.QLineEdit()
151
      la.addWidget(self.gWt)
152

153
      GWH = QtGui.QLabel("Geneva Wheel Height")
154
      la.addWidget(GWH)
155
      self.gWh = QtGui.QLineEdit()
156
      la.addWidget(self.gWh)
157

158
      GWN = QtGui.QLabel("Driven Slot Quantity")
159
      la.addWidget(GWN)
160
      self.gWn = QtGui.QLineEdit()
161
      la.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

170
      import os
171
      macro_dir='/tmp'
172
      try:
173
         macro_dir = os.path.dirname(__file__)
174
      except:
175
         pass
176
      self.PiX = QtGui.QLabel()
177
      self.PiX.setPixmap(os.path.join(macro_dir, "GW_Dim.png"))
178

179
      hbox = QtGui.QHBoxLayout()
180
      hbox.addStretch()
181
      hbox.addWidget(self.PiX)
182
      hbox.addStretch()
183
      
184
      la.addSpacing(15)
185
      la.addLayout(hbox)
186
      la.addSpacing(15)
187

188
      # - End Image layout -
189

190
      okbox = QtGui.QDialogButtonBox(self.dialog)
191
      okbox.setOrientation(QtCore.Qt.Horizontal)
192
      okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
193
      la.addWidget(okbox)
194
      QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.Ggear)
195
      QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
196
      QtCore.QMetaObject.connectSlotsByName(self.dialog)
197
      self.dialog.show()
198
      self.dialog.exec_()
199

200

201
p()
202

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.