forked from shaise/FreeCAD_FastenersWB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastenersCmd.py
More file actions
843 lines (702 loc) · 32.6 KB
/
Copy pathFastenersCmd.py
File metadata and controls
843 lines (702 loc) · 32.6 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
# -*- coding: utf-8 -*-
###################################################################################
#
# FastenersCmd.py
#
# 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.
#
#
###################################################################################
from FreeCAD import Gui
import FreeCAD, FreeCADGui, Part, os
__dir__ = os.path.dirname(__file__)
iconPath = os.path.join( __dir__, 'Icons' )
import screw_maker
import FastenerBase
from FastenerBase import FSBaseObject
import ScrewMaker
screwMaker = ScrewMaker.Instance()
class FSScrewObject(FSBaseObject):
def __init__(self, obj, type, attachTo):
'''"Add screw type fastener" '''
FSBaseObject.__init__(self, obj, attachTo)
self.itemText = screwMaker.GetTypeName(type)
diameters = screwMaker.GetAllDiams(type)
diameters.insert(0, 'Auto')
self.type = ''
self.diameter = ''
self.matchOuter = ''
self.length = ''
self.customlen = -1
#self.Proxy = obj.Name
obj.addProperty("App::PropertyEnumeration","type","Parameters","Screw type").type = screwMaker.GetAllTypes(self.itemText)
obj.type = type
obj.addProperty("App::PropertyEnumeration","diameter","Parameters","Screw diameter standard").diameter = diameters
self.VerifyMissingAttrs(obj, diameters[1])
if (self.itemText != "Washer"):
obj.addProperty("App::PropertyBool", "thread", "Parameters", "Generate real thread").thread = False
obj.Proxy = self
def inswap(self, inpstr):
if '″' in inpstr:
return inpstr.replace('″', 'in')
else:
return inpstr
def VerifyMissingAttrs(self, obj, diameter):
self.updateProps(obj)
if not (hasattr(obj,'matchOuter')):
obj.addProperty("App::PropertyBool", "matchOuter", "Parameters", "Match outer thread diameter").matchOuter = FastenerBase.FSMatchOuter
if (self.itemText == "Screw" and not hasattr(obj, 'lengthCustom')):
slens = screwMaker.GetAllLengths(obj.type, diameter)
if (hasattr(obj, 'length')):
origLen = obj.length
obj.length = slens
obj.length = origLen
else:
obj.addProperty("App::PropertyEnumeration","length","Parameters","Screw length").length = slens
obj.addProperty("App::PropertyLength","lengthCustom","Parameters","Custom length").lengthCustom = self.inswap(slens[0])
def ActiveLength(self, obj):
if not hasattr(obj,'length'):
return '0'
if obj.length == 'Custom':
return str(float(obj.lengthCustom)).rstrip("0").rstrip('.')
return obj.length
def execute(self, fp):
'''"Print a short message when doing a recomputation, this method is mandatory" '''
try:
baseobj = fp.baseObject[0]
shape = baseobj.Shape.getElement(fp.baseObject[1][0])
except:
baseobj = None
shape = None
# for backward compatibility: add missing attribute if needed
self.VerifyMissingAttrs(fp, fp.diameter)
#FreeCAD.Console.PrintLog("MatchOuter:" + str(fp.matchOuter) + "\n")
typechange = False
if fp.type == "ISO7380":
fp.type = "ISO7380-1" # backward compatibility
if not (hasattr(self,'type')) or fp.type != self.type:
typechange = True
curdiam = fp.diameter
diameters = screwMaker.GetAllDiams(fp.type)
diameters.insert(0, 'Auto')
if not(curdiam in diameters):
curdiam='Auto'
fp.diameter = diameters
fp.diameter = curdiam
diameterchange = False
if not (hasattr(self,'diameter')) or self.diameter != fp.diameter:
diameterchange = True
matchouterchange = not (hasattr(self,'matchOuter')) or self.matchOuter != fp.matchOuter
if fp.diameter == 'Auto' or matchouterchange:
d = screwMaker.AutoDiameter(fp.type, shape, baseobj, fp.matchOuter)
fp.diameter = d
diameterchange = True
else:
d = fp.diameter
if hasattr(fp,'length'):
if (fp.length != self.length):
if (fp.length != 'Custom'):
fp.lengthCustom = FastenerBase.LenStr2Num(fp.length) #***
elif (hasattr(self,'customlen') and float(fp.lengthCustom) != self.customlen):
fp.length = 'Custom'
origLen = self.ActiveLength(fp)
origIsCustom = fp.length == 'Custom'
d , l = screwMaker.FindClosest(fp.type, d, origLen)
if d != fp.diameter:
diameterchange = True
fp.diameter = d
if (origIsCustom):
l = origLen
if l != origLen or diameterchange or typechange:
if diameterchange or typechange:
fp.length = screwMaker.GetAllLengths(fp.type, fp.diameter)
if (origIsCustom):
fp.length = 'Custom'
else:
fp.length = l
fp.lengthCustom = l
else:
l = 1
screwMaker.updateFastenerParameters()
threadType = 'simple'
if hasattr(fp,'thread') and fp.thread:
threadType = 'real'
(key, s) = FastenerBase.FSGetKey(self.itemText, fp.type, d, l, threadType)
if s is None:
s = screwMaker.createFastener(fp.type, d, l, threadType, True)
FastenerBase.FSCache[key] = s
else:
FreeCAD.Console.PrintLog("Using cached object\n")
self.type = fp.type
self.diameter = fp.diameter
self.matchOuter = fp.matchOuter
if hasattr(fp,'length'):
self.length = l
self.customlen = float(fp.lengthCustom)
fp.Label = fp.diameter + 'x' + l + '-' + self.itemText
else:
fp.Label = fp.diameter + '-' + self.itemText
if hasattr(fp,'thread'):
self.realThread = fp.thread
#self.itemText = s[1]
fp.Shape = s
if shape != None:
#feature = FreeCAD.ActiveDocument.getObject(self.Proxy)
#fp.Placement = FreeCAD.Placement() # reset placement
FastenerBase.FSMoveToObject(fp, shape, fp.invert, fp.offset.Value)
#def getItemText():
# return self.itemText
class FSViewProviderTree:
"A View provider for custom icon"
def __init__(self, obj):
obj.Proxy = self
self.Object = obj.Object
def attach(self, obj):
self.Object = obj.Object
return
def updateData(self, fp, prop):
return
def getDisplayModes(self,obj):
modes=[]
return modes
def setDisplayMode(self,mode):
return mode
def onChanged(self, vp, prop):
return
def __getstate__(self):
# return {'ObjectName' : self.Object.Name}
return None
def __setstate__(self,state):
if state is not None:
import FreeCAD
doc = FreeCAD.ActiveDocument #crap
self.Object = doc.getObject(state['ObjectName'])
def getIcon(self):
if hasattr(self.Object, "type"):
return os.path.join( iconPath , self.Object.type + '.svg')
elif hasattr(self.Object.Proxy, "type"):
return os.path.join( iconPath, self.Object.Proxy.type + '.svg')
# default to ISO4017.svg
return os.path.join( iconPath , 'ISO4017.svg')
class FSScrewCommand:
"""Add Screw command"""
def __init__(self, type, help):
self.Type = type
self.Help = help
self.TypeName = screwMaker.GetTypeName(type)
def GetResources(self):
icon = os.path.join( iconPath , self.Type + '.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add " + self.Help ,
'ToolTip' : self.Help}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",self.TypeName)
FSScrewObject(a, self.Type, selObj)
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
def FSAddScrewCommand(type, help, dropGroup = None):
cmd = 'FS' + type
Gui.addCommand(cmd,FSScrewCommand(type, help))
FastenerBase.FSCommands.append(cmd, "screws", dropGroup)
FSAddScrewCommand("ISO4017", "ISO 4017 Hex head screw", "Hex head")
FSAddScrewCommand("ISO4014", "ISO 4014 Hex head bolt", "Hex head")
FSAddScrewCommand("EN1662", "EN 1662 Hexagon bolt with flange, small series", "Hex head")
FSAddScrewCommand("EN1665", "EN 1665 Hexagon bolt with flange, heavy series", "Hex head")
FSAddScrewCommand("ISO4762", "ISO4762 Hexagon socket head cap screw", "Hexagon socket")
FSAddScrewCommand("DIN7984", "DIN 7984 Hexagon socket head cap screws with low head", "Hexagon socket")
FSAddScrewCommand("DIN6912", "DIN 6912 Hexagon socket head cap screws with low head with centre", "Hexagon socket")
FSAddScrewCommand("ISO7380-1", "ISO 7380 Hexagon socket button head screw", "Hexagon socket")
FSAddScrewCommand("ISO7380-2", "ISO 7380 Hexagon socket button head screws with collar", "Hexagon socket")
FSAddScrewCommand("ISO10642", "ISO 10642 Hexagon socket countersunk head screw", "Hexagon socket")
FSAddScrewCommand("ISO2009", "ISO 2009 Slotted countersunk flat head screw", "Slotted")
FSAddScrewCommand("ISO2010", "ISO 2010 Slotted raised countersunk head screw", "Slotted")
FSAddScrewCommand("ISO1580", "ISO 1580 Slotted pan head screw", "Slotted")
FSAddScrewCommand("ISO1207", "ISO 1207 Slotted cheese head screw", "Slotted")
FSAddScrewCommand("DIN967", "DIN 967 Cross recessed pan head screws with collar", "H cross")
FSAddScrewCommand("ISO7045", "ISO 7045 Pan head screws type H cross recess", "H cross")
FSAddScrewCommand("ISO7046", "ISO 7046 Countersunk flat head screws H cross r.", "H cross")
FSAddScrewCommand("ISO7047", "ISO 7047 Raised countersunk head screws H cross r.", "H cross")
FSAddScrewCommand("ISO7048", "ISO 7048 Cheese head screws with type H cross r.", "H cross")
FSAddScrewCommand("ISO14579", "ISO 14579 Hexalobular socket head cap screws", "Hexalobular socket")
FSAddScrewCommand("ISO14580", "ISO 14580 Hexalobular socket cheese head screws", "Hexalobular socket")
#FSAddScrewCommand("ISO14581", "ISO 14581 Hexalobular socket countersunk flat head screws", "Hexalobular socket")
FSAddScrewCommand("ISO14582", "ISO 14582 Hexalobular socket countersunk head screws, high head", "Hexalobular socket")
FSAddScrewCommand("ISO14583", "ISO 14583 Hexalobular socket pan head screws", "Hexalobular socket")
FSAddScrewCommand("ISO14584", "ISO 14584 Hexalobular socket raised countersunk head screws", "Hexalobular socket")
FSAddScrewCommand("ISO7379", "ISO 7379 Hexagon socket head shoulder screw", "Hexagon socket")
FSAddScrewCommand("ISO7089", "ISO 7089 Washer", "Washer")
FSAddScrewCommand("ISO7090", "ISO 7090 Plain Washers, chamfered - Normal series", "Washer")
#FSAddScrewCommand("ISO7091", "ISO 7091 Plain washer - Normal series Product Grade C", "Washer") # same as 7089??
FSAddScrewCommand("ISO7092", "ISO 7092 Plain washers - Small series", "Washer")
FSAddScrewCommand("ISO7093-1", "ISO 7093-1 Plain washers - Large series", "Washer")
FSAddScrewCommand("ISO7094", "ISO 7094 Plain washers - Extra large series", "Washer")
FSAddScrewCommand("ISO4026", "ISO 4026 Hexagon socket set screws with flat point", "Hexagon socket")
FSAddScrewCommand("ISO4027", "ISO 4027 Hexagon socket set screws with cone point", "Hexagon socket")
FSAddScrewCommand("ISO4028", "ISO 4028 Hexagon socket set screws with dog point", "Hexagon socket")
FSAddScrewCommand("ISO4029", "ISO 4029 Hexagon socket set screws with cup point", "Hexagon socket")
FSAddScrewCommand("ISO4032", "ISO 4032 Hexagon nuts, Style 1", "Nut")
FSAddScrewCommand("ISO4033", "ISO 4033 Hexagon nuts, Style 2", "Nut")
FSAddScrewCommand("ISO4035", "ISO 4035 Hexagon thin nuts, chamfered", "Nut")
#FSAddScrewCommand("ISO4036", "ISO 4035 Hexagon thin nuts, unchamfered", "Nut")
FSAddScrewCommand("EN1661", "EN 1661 Hexagon nuts with flange", "Nut")
FSAddScrewCommand("DIN557", "DIN 557 Square nuts", "Nut")
FSAddScrewCommand("DIN562", "DIN 562 Square nuts", "Nut")
FSAddScrewCommand("DIN985", "DIN 985 Nyloc nuts", "Nut")
FSAddScrewCommand("ASMEB18.2.1.6", "ASME B18.2.1 UNC Hex head screws", "Hex head")
FSAddScrewCommand("ASMEB18.2.1.8", "ASME B18.2.1 UNC Hex head screws with flange", "Hex head")
FSAddScrewCommand("ASMEB18.2.2.1A", "ASME B18.2.2 UNC Machine screw nuts", "Nut")
FSAddScrewCommand("ASMEB18.2.2.4A", "ASME B18.2.2 UNC Hexagon nuts", "Nut")
FSAddScrewCommand("ASMEB18.2.2.4B", "ASME B18.2.2 UNC Hexagon thin nuts", "Nut")
FSAddScrewCommand("ASMEB18.3.1A", "ASME B18.3 UNC Hex socket head cap screws", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.2", "ASME B18.3 UNC Hex socket countersunk head screws", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.3A", "ASME B18.3 UNC Hex socket button head screws", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.3B", "ASME B18.3 UNC Hex socket button head screws with flange", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.4", "ASME B18.3 UNC Hexagon socket head shoulder screws", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.5A", "ASME B18.3 UNC Hexagon socket set screws with flat point", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.5B", "ASME B18.3 UNC Hexagon socket set screws with cone point", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.5C", "ASME B18.3 UNC Hexagon socket set screws with dog point", "Hexagon socket")
FSAddScrewCommand("ASMEB18.3.5D", "ASME B18.3 UNC Hexagon socket set screws with cup point", "Hexagon socket")
FSAddScrewCommand("ASMEB18.5.2", "ASME B18.5 UNC Round head square neck bolts", "Other head")
FSAddScrewCommand("ASMEB18.6.3.1A", "ASME B18.6.3 UNC slotted countersunk flat head screws", "Slotted")
FSAddScrewCommand("ASMEB18.21.1.12A", "ASME B18.21.1 UN washers, narrow series", "Washer")
FSAddScrewCommand("ASMEB18.21.1.12B", "ASME B18.21.1 UN washers, regular series", "Washer")
FSAddScrewCommand("ASMEB18.21.1.12C", "ASME B18.21.1 UN washers, wide series", "Washer")
#deprecated
class FSWasherObject(FSBaseObject):
def __init__(self, obj, type, attachTo):
'''"Add washer / nut type fastener" '''
FSBaseObject.__init__(self, obj, attachTo)
self.itemText = screwMaker.GetTypeName(type)
diameters = screwMaker.GetAllDiams(type)
diameters.insert(0, 'Auto')
#self.Proxy = obj.Name
obj.addProperty("App::PropertyEnumeration","type","Parameters","Screw type").type = screwMaker.GetAllTypes(self.itemText)
obj.addProperty("App::PropertyEnumeration","diameter","Parameters","Screw diameter standard").diameter = diameters
obj.type = type
obj.Proxy = self
def execute(self, fp):
'''"Print a short message when doing a recomputation, this method is mandatory" '''
try:
baseobj = fp.baseObject[0]
shape = baseobj.Shape.getElement(fp.baseObject[1][0])
except:
baseobj = None
shape = None
if (not (hasattr(self,'diameter')) or self.diameter != fp.diameter):
if fp.diameter == 'Auto':
d = screwMaker.AutoDiameter(fp.type, shape)
diameterchange = True
else:
d = fp.diameter
d , l = screwMaker.FindClosest(fp.type, d, '0')
if d != fp.diameter:
fp.diameter = d
s = screwMaker.createScrew(fp.type, d, l, 'simple', True)
self.diameter = fp.diameter
fp.Label = fp.diameter + '-' + self.itemText
#self.itemText = s[1]
fp.Shape = s
else:
FreeCAD.Console.PrintLog("Using cached object\n")
if shape != None:
#feature = FreeCAD.ActiveDocument.getObject(self.Proxy)
#fp.Placement = FreeCAD.Placement() # reset placement
FastenerBase.FSMoveToObject(fp, shape, fp.invert, fp.offset.Value)
def getItemText():
return self.itemText
#deprecated
class FSWasherCommand:
"""Add Screw command"""
def __init__(self, type, help):
self.Type = type
self.Help = help
def GetResources(self):
icon = os.path.join( iconPath , self.Type + '.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add " + self.Help ,
'ToolTip' : self.Help}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Washer")
FSWasherObject(a, self.Type, selObj)
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
#Gui.addCommand("FSISO7089",FSWasherCommand("ISO7089", "Washer"))
#FastenerBase.FSCommands.append("FSISO7089")
class FSScrewRodObject(FSBaseObject):
def __init__(self, obj, attachTo, typeStr):
'''"Add screw rod" '''
FSBaseObject.__init__(self, obj, attachTo)
self.itemText = "ScrewTap"
self.type = typeStr
diameters = screwMaker.GetAllDiams(self.type) + ["Custom"]
diameters.insert(0, 'Auto')
obj.addProperty("App::PropertyEnumeration","diameter","Parameters","Screw diameter standard").diameter = diameters
obj.addProperty("App::PropertyLength","diameterCustom","Parameters","Screw major diameter custom").diameterCustom = 6
obj.addProperty("App::PropertyLength","pitchCustom","Parameters","Screw pitch custom").pitchCustom = 1.0
obj.addProperty("App::PropertyLength","length","Parameters","Screw length").length = 20.0
self.VerifyMissingAttrs(obj)
obj.addProperty("App::PropertyBool", "thread", "Parameters", "Generate real thread").thread = False
obj.Proxy = self
def VerifyMissingAttrs(self, obj):
self.updateProps(obj)
if not (hasattr(obj,'matchOuter')):
obj.addProperty("App::PropertyBool", "matchOuter", "Parameters", "Match outer thread diameter").matchOuter = FastenerBase.FSMatchOuter
# for old objects from before custom diameter and pitch were implemented
if not hasattr(obj,"pitchCustom"):
obj.addProperty("App::PropertyLength","pitchCustom","Parameters","Screw pitch custom").pitchCustom = 1.0
obj.addProperty("App::PropertyLength","diameterCustom","Parameters","Screw major diameter custom").diameterCustom = 6
dia_tmp = obj.diameter
self.type = "ScrewTap"
obj.diameter = screwMaker.GetAllDiams(self.type) + ["Custom"]
obj.diameter = dia_tmp
def execute(self, fp):
'''"Print a short message when doing a recomputation, this method is mandatory" '''
try:
baseobj = fp.baseObject[0]
shape = baseobj.Shape.getElement(fp.baseObject[1][0])
except:
baseobj = None
shape = None
self.VerifyMissingAttrs(fp)
diameterchange = False
if not (hasattr(self,'diameter')) or self.diameter != fp.diameter:
diameterchange = True
matchouterchange = not (hasattr(self,'matchOuter')) or self.matchOuter != fp.matchOuter
if fp.diameter == 'Auto' or matchouterchange:
d = screwMaker.AutoDiameter(self.type, shape, baseobj, fp.matchOuter)
fp.diameter = d
diameterchange = True
d_custom = None
elif fp.diameter == 'Custom':
d = fp.diameter
d_custom = fp.diameterCustom.Value
else:
d = fp.diameter
d_custom = None
l = fp.length.Value
if l < 2.0:
l = 2.0
fp.length = 2.0
if fp.diameter == 'Custom':
p = fp.pitchCustom.Value
else:
p = None
screwMaker.updateFastenerParameters()
threadType = 'simple'
if hasattr(fp,'thread') and fp.thread:
threadType = 'real'
# since we are bypassing the createScrew() method, we must set
# the rThread parameter manually
screwMaker.rThread = (threadType == 'real')
s = screwMaker.makeScrewTap(self.type,d,l,p,d_custom)
self.diameter = fp.diameter
self.length = l
self.matchOuter = fp.matchOuter
diastr = fp.diameter if fp.diameter != 'Custom' else str(fp.diameterCustom)
fp.Label = diastr + 'x' + str(l) + '-' + self.itemText
self.realThread = fp.thread
fp.Shape = s
if shape != None:
FastenerBase.FSMoveToObject(fp, shape, fp.invert, fp.offset.Value)
class FSScrewRodCommand:
"""Add Screw Rod command"""
def GetResources(self):
icon = os.path.join( iconPath , 'ScrewTap.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add threaded rod for tapping holes" ,
'ToolTip' : "Add arbitrary length threaded rod for tapping holes"}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ScrewTap")
FSScrewRodObject(a, selObj, "ScrewTap")
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
Gui.addCommand("FSScrewTap",FSScrewRodCommand())
FastenerBase.FSCommands.append("FSScrewTap", "screws", "misc")
class FSScrewRodCommandInch:
"""Add Screw Rod command"""
def GetResources(self):
icon = os.path.join( iconPath , 'ScrewTapInch.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add inch threaded rod for tapping holes" ,
'ToolTip' : "Add arbitrary length threaded rod for tapping holes (inch sizes)"}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ScrewTap")
FSScrewRodObject(a, selObj, "ScrewTapInch")
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
Gui.addCommand("FSScrewTapInch",FSScrewRodCommandInch())
FastenerBase.FSCommands.append("FSScrewTapInch", "screws", "misc")
class FSScrewDieObject(FSBaseObject):
def __init__(self, obj, attachTo, typeStr):
'''"Add screw die" '''
FSBaseObject.__init__(self, obj, attachTo)
self.itemText = "ScrewDie"
self.type = typeStr
diameters = screwMaker.GetAllDiams(self.type) + ["Custom"]
diameters.insert(0, 'Auto')
#self.Proxy = obj.Name
obj.addProperty("App::PropertyEnumeration","diameter","Parameters","Screw diameter standard").diameter = diameters
obj.addProperty("App::PropertyLength","length","Parameters","Screw length").length = 20.0
obj.addProperty("App::PropertyLength","diameterCustom","Parameters","Screw major diameter custom").diameterCustom = 6
obj.addProperty("App::PropertyLength","pitchCustom","Parameters","Screw pitch custom").pitchCustom = 1.0
self.VerifyMissingAttrs(obj)
obj.addProperty("App::PropertyBool", "thread", "Parameters", "Generate real thread").thread = False
obj.Proxy = self
def VerifyMissingAttrs(self, obj):
self.updateProps(obj)
if not (hasattr(obj,'matchOuter')):
obj.addProperty("App::PropertyBool", "matchOuter", "Parameters", "Match outer thread diameter").matchOuter = FastenerBase.FSMatchOuter
# for old objects from before custom diameter and pitch were implemented
if not hasattr(obj,"pitchCustom"):
obj.addProperty("App::PropertyLength","pitchCustom","Parameters","Screw pitch custom").pitchCustom = 1.0
obj.addProperty("App::PropertyLength","diameterCustom","Parameters","Screw major diameter custom").diameterCustom = 6
dia_tmp = obj.diameter
self.type = "ScrewDie"
obj.diameter = screwMaker.GetAllDiams(self.type) + ["Custom"]
obj.diameter = dia_tmp
def execute(self, fp):
'''"Print a short message when doing a recomputation, this method is mandatory" '''
try:
baseobj = fp.baseObject[0]
shape = baseobj.Shape.getElement(fp.baseObject[1][0])
except:
baseobj = None
shape = None
self.VerifyMissingAttrs(fp)
diameterchange = False
if not (hasattr(self,'diameter')) or self.diameter != fp.diameter:
diameterchange = True
matchouterchange = not (hasattr(self,'matchOuter')) or self.matchOuter != fp.matchOuter
if fp.diameter == 'Auto' or matchouterchange:
d = screwMaker.AutoDiameter(self.type, shape, baseobj, fp.matchOuter)
fp.diameter = d
diameterchange = True
d_custom = None
elif fp.diameter == 'Custom':
d = fp.diameter
d_custom = fp.diameterCustom.Value
else:
d = fp.diameter
d_custom = None
l = fp.length.Value
if l < 2.0:
l = 2.0
fp.length = 2.0
if fp.diameter == 'Custom':
p = fp.pitchCustom.Value
else:
p = None
screwMaker.updateFastenerParameters()
threadType = 'simple'
if hasattr(fp,'thread') and fp.thread:
threadType = 'real'
# since we are bypassing the createScrew() method, we must set
# the rThread parameter manually
screwMaker.rThread = (threadType == 'real')
s = screwMaker.makeScrewDie(self.type,d,l,p,d_custom)
self.diameter = fp.diameter
self.length = l
self.matchOuter = fp.matchOuter
diastr = fp.diameter if fp.diameter != 'Custom' else str(fp.diameterCustom)
fp.Label = diastr + 'x' + str(l) + '-' + self.itemText
self.realThread = fp.thread
fp.Shape = s
if shape != None:
FastenerBase.FSMoveToObject(fp, shape, fp.invert, fp.offset.Value)
class FSScrewDieCommand:
"""Add Screw Die command"""
def GetResources(self):
icon = os.path.join( iconPath , 'ScrewDie.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add object to cut external threads" ,
'ToolTip' : "Add arbitrary length threaded tube for cutting external threads"}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ScrewDie")
FSScrewDieObject(a, selObj, "ScrewDie")
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
Gui.addCommand("FSScrewDie",FSScrewDieCommand())
FastenerBase.FSCommands.append("FSScrewDie", "screws", "misc")
class FSScrewDieCommandInch:
"""Add Screw Die command"""
def GetResources(self):
icon = os.path.join( iconPath , 'ScrewDieInch.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add object to cut external non-metric threads" ,
'ToolTip' : "Add arbitrary length threaded tube for cutting inch standard external threads"}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ScrewDie")
FSScrewDieObject(a, selObj, "ScrewDieInch")
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
Gui.addCommand("FSScrewDieInch",FSScrewDieCommandInch())
FastenerBase.FSCommands.append("FSScrewDieInch", "screws", "misc")
class FSThreadedRodObject(FSBaseObject):
def __init__(self, obj, attachTo, typeStr):
'''"Add threaded rod" '''
FSBaseObject.__init__(self, obj, attachTo)
self.itemText = "ThreadedRod"
self.type = typeStr
diameters = screwMaker.GetAllDiams(self.type) + ["Custom"]
diameters.insert(0, 'Auto')
#self.Proxy = obj.Name
obj.addProperty("App::PropertyEnumeration","diameter","Parameters","Screw diameter standard").diameter = diameters
obj.addProperty("App::PropertyLength","length","Parameters","Screw length").length = 20.0
obj.addProperty("App::PropertyLength","diameterCustom","Parameters","Screw major diameter custom").diameterCustom = 6
obj.addProperty("App::PropertyLength","pitchCustom","Parameters","Screw pitch custom").pitchCustom = 1.0
self.VerifyMissingAttrs(obj)
obj.addProperty("App::PropertyBool", "thread", "Parameters", "Generate real thread").thread = False
obj.Proxy = self
def VerifyMissingAttrs(self, obj):
self.updateProps(obj)
if not (hasattr(obj,'matchOuter')):
obj.addProperty("App::PropertyBool", "matchOuter", "Parameters", "Match outer thread diameter").matchOuter = FastenerBase.FSMatchOuter
# for old objects from before custom diameter and pitch were implemented
if not hasattr(obj,"pitchCustom"):
obj.addProperty("App::PropertyLength","pitchCustom","Parameters","Screw pitch custom").pitchCustom = 1.0
obj.addProperty("App::PropertyLength","diameterCustom","Parameters","Screw major diameter custom").diameterCustom = 6
dia_tmp = obj.diameter
self.type = "ThreadedRod"
obj.diameter = screwMaker.GetAllDiams(self.type) + ["Custom"]
obj.diameter = dia_tmp
def execute(self, fp):
'''"Print a short message when doing a recomputation, this method is mandatory" '''
try:
baseobj = fp.baseObject[0]
shape = baseobj.Shape.getElement(fp.baseObject[1][0])
except:
baseobj = None
shape = None
self.VerifyMissingAttrs(fp)
diameterchange = False
if not (hasattr(self,'diameter')) or self.diameter != fp.diameter:
diameterchange = True
matchouterchange = not (hasattr(self,'matchOuter')) or self.matchOuter != fp.matchOuter
if fp.diameter == 'Auto' or matchouterchange:
d = screwMaker.AutoDiameter(self.type, shape, baseobj, fp.matchOuter)
fp.diameter = d
diameterchange = True
d_custom = None
elif fp.diameter == 'Custom':
d = fp.diameter
d_custom = fp.diameterCustom.Value
else:
d = fp.diameter
d_custom = None
l = fp.length.Value
if l < 2.0:
l = 2.0
fp.length = 2.0
if fp.diameter == 'Custom':
p = fp.pitchCustom.Value
else:
p = None
screwMaker.updateFastenerParameters()
threadType = 'simple'
if hasattr(fp,'thread') and fp.thread:
threadType = 'real'
# since we are bypassing the createScrew() method, we must set
# the rThread parameter manually
screwMaker.rThread = (threadType == 'real')
s = screwMaker.makeThreadedRod(self.type,d,l,p,d_custom)
self.diameter = fp.diameter
self.length = l
self.matchOuter = fp.matchOuter
diastr = fp.diameter if fp.diameter != 'Custom' else str(fp.diameterCustom)
fp.Label = diastr + 'x' + str(l) + '-' + self.itemText
self.realThread = fp.thread
fp.Shape = s
if shape != None:
FastenerBase.FSMoveToObject(fp, shape, fp.invert, fp.offset.Value)
class FSThreadedRodCommand:
"""Add Threaded Rod command"""
def GetResources(self):
icon = os.path.join( iconPath , 'ThreadedRod.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add DIN 975 threaded rod" ,
'ToolTip' : "Add arbitrary length threaded rod object"}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ThreadedRod")
FSThreadedRodObject(a, selObj, "ThreadedRod")
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
Gui.addCommand("FSThreadedRod",FSThreadedRodCommand())
FastenerBase.FSCommands.append("FSThreadedRod", "screws", "misc")
class FSThreadedRodCommandInch:
"""Add Threaded Rod command"""
def GetResources(self):
icon = os.path.join( iconPath , 'ThreadedRodInch.svg')
return {'Pixmap' : icon , # the name of a svg file available in the resources
'MenuText': "Add UNC threaded rod" ,
'ToolTip' : "Add arbitrary length threaded rod object, inch standard coarse threads"}
def Activated(self):
for selObj in FastenerBase.FSGetAttachableSelections():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ThreadedRod")
FSThreadedRodObject(a, selObj, "ThreadedRodInch")
a.Label = a.Proxy.itemText
FSViewProviderTree(a.ViewObject)
FreeCAD.ActiveDocument.recompute()
return
def IsActive(self):
return Gui.ActiveDocument != None
Gui.addCommand("FSThreadedRodInch",FSThreadedRodCommandInch())
FastenerBase.FSCommands.append("FSThreadedRodInch", "screws", "misc")
## add fastener types
FastenerBase.FSAddFastenerType("Screw")
FastenerBase.FSAddFastenerType("Washer", False)
FastenerBase.FSAddFastenerType("Nut", False)
FastenerBase.FSAddFastenerType("ScrewTap", True, False)
FastenerBase.FSAddFastenerType("ScrewDie", True, False)
FastenerBase.FSAddFastenerType("ThreadedRod", True, False)
for item in ScrewMaker.screwTables:
FastenerBase.FSAddItemsToType(ScrewMaker.screwTables[item][0], item)