forked from shaise/FreeCAD_FastenersWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FSScrewCalc.py
214 lines (188 loc) · 8.47 KB
/
FSScrewCalc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# -*- coding: utf-8 -*-
###################################################################################
#
# ScrewCalc.py
# A calculator utility to calculate needed hole sizes for selected fasteners
#
# Copyright 2015 Shai Seger <shaise at gmail dot com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
###################################################################################
###################################################################################
# replace below with generated code from pyuic4
###################################################################################
from PySide import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_DockWidget(object):
def setupUi(self, DockWidget):
DockWidget.setObjectName(_fromUtf8("DockWidget"))
DockWidget.resize(267, 136)
DockWidget.setFloating(True)
self.dockWidgetContents = QtGui.QWidget()
self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents"))
self.gridLayout = QtGui.QGridLayout(self.dockWidgetContents)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label = QtGui.QLabel(self.dockWidgetContents)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout.addWidget(self.label)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.comboFastenerType = QtGui.QComboBox(self.dockWidgetContents)
self.comboFastenerType.setObjectName(_fromUtf8("comboFastenerType"))
self.horizontalLayout.addWidget(self.comboFastenerType)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.label_2 = QtGui.QLabel(self.dockWidgetContents)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.horizontalLayout_2.addWidget(self.label_2)
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem1)
self.comboDiameter = QtGui.QComboBox(self.dockWidgetContents)
self.comboDiameter.setObjectName(_fromUtf8("comboDiameter"))
self.horizontalLayout_2.addWidget(self.comboDiameter)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtGui.QHBoxLayout()
self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
self.labelHoleSize = QtGui.QLabel(self.dockWidgetContents)
self.labelHoleSize.setObjectName(_fromUtf8("labelHoleSize"))
self.horizontalLayout_3.addWidget(self.labelHoleSize)
spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_3.addItem(spacerItem2)
self.textHole = QtGui.QLineEdit(self.dockWidgetContents)
self.textHole.setReadOnly(True)
self.textHole.setObjectName(_fromUtf8("textHole"))
self.horizontalLayout_3.addWidget(self.textHole)
self.verticalLayout.addLayout(self.horizontalLayout_3)
spacerItem3 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem3)
self.gridLayout.addLayout(self.verticalLayout, 1, 0, 1, 1)
DockWidget.setWidget(self.dockWidgetContents)
self.retranslateUi(DockWidget)
QtCore.QMetaObject.connectSlotsByName(DockWidget)
def retranslateUi(self, DockWidget):
DockWidget.setWindowTitle(_translate("DockWidget", "Screw hole calculator", None))
self.label.setText(_translate("DockWidget", "Fastener type:", None))
self.label_2.setText(_translate("DockWidget", "Screw Diameter:", None))
self.labelHoleSize.setText(_translate("DockWidget", "Suggested Hole diameter (mm):", None))
###################################################################################
# End position for generated code from pyuic4
###################################################################################
def fillScrewTypes(self):
self.comboFastenerType.currentIndexChanged.connect(self.onTypeChange)
self.comboDiameter.currentIndexChanged.connect(self.onDiameterChange)
self.comboFastenerType.clear()
for type in FSCScrewTypes:
icon, name, table = type
self.comboFastenerType.addItem(QtGui.QIcon(os.path.join(iconPath , icon)), name)
def fillDiameters(self):
self.comboDiameter.clear()
idx = self.comboFastenerType.currentIndex()
table = FSCScrewTypes[idx][2]
for diam in table:
self.comboDiameter.addItem(diam[0])
def onDiameterChange(self, diamindex):
idx = self.comboFastenerType.currentIndex()
table = FSCScrewTypes[idx][2]
self.textHole.setText(str(table[diamindex][1]))
def onTypeChange(self, typeindex):
self.fillDiameters()
from FreeCAD import Gui
from FreeCAD import Base
import FreeCAD, FreeCADGui, Part, os, math
__dir__ = os.path.dirname(__file__)
iconPath = os.path.join( __dir__, 'Icons' )
import FastenerBase
from FastenerBase import FSBaseObject
import ScrewMaker
screwMaker = ScrewMaker.Instance()
FSCPEMPressNutHoleChart = (
("M2", 4.22),
("M2.5", 4.22),
("M3", 4.22),
("M3.5", 4.75),
("M4", 5.41),
("M5", 6.35),
("M6", 8.75),
("M8", 10.5),
("M10", 14),
("M12", 17)
)
# hole size +0.08
FSCPEMStandOffHoleChart = (
("M3", 4.22),
("3.5M3", 5.41),
("M3.5", 5.41),
("M4", 7.14),
("M5", 7.14)
)
FSCPEMStudHoleChart = (
("M2.5", 2.5),
("M3", 3),
("M3.5", 3.5),
("M4", 4),
("M5", 5),
("M6", 6),
("M8", 8)
)
FSCScrewTypes = (
("ISO7045.svg", "Metric Screw", ScrewMaker.FSCScrewHoleChart),
("PEMPressNut.svg", "PEM Press-nut", FSCPEMPressNutHoleChart),
("PEMBLStandoff.svg", "PEM Stand-off", FSCPEMStudHoleChart),
("PEMStud.svg", "PEM Stud", FSCPEMStudHoleChart)
)
FSScrewCalcDlg = QtGui.QDockWidget()
FSScrewCalcDlg.ui = Ui_DockWidget()
FSScrewCalcDlg.ui.setupUi(FSScrewCalcDlg)
FSScrewCalcDlg.ui.fillScrewTypes()
Gui.getMainWindow().addDockWidget(QtCore.Qt.RightDockWidgetArea, FSScrewCalcDlg)
FSScrewCalcDlg.setFloating(True)
FSScrewCalcDlg.hide()
class FSScrewCalcCommand:
"""Display a calculator for needed screw holes"""
def GetResources(self):
FreeCAD.Console.PrintLog("Getting resources\n")
icon = os.path.join( iconPath , 'IconScrewCalc.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Screw calculator" ,
'ToolTip' : "Show a screw hole calculator"}
def Activated(self):
if FSScrewCalcDlg.isHidden():
FSScrewCalcDlg.show()
else:
FSScrewCalcDlg.hide()
return
def IsActive(self):
return True
Gui.addCommand("FSScrewCalc", FSScrewCalcCommand())
FastenerBase.FSCommands.append("FSScrewCalc", "command")