forked from oddtopus/dodo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpFeatures.py
1348 lines (1256 loc) · 49 KB
/
pFeatures.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
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
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# (c) 2019 R. T. LGPL: part ofdodo tools w.b. for FreeCAD
__title__ = "pypeTools objects"
__author__ = "oddtopus"
__url__ = "github.com/oddtopus/dodo"
__license__ = "LGPL 3"
objs = ["Pipe", "Elbow", "Reduct", "Cap", "Flange", "Ubolt", "Valve"]
metaObjs = ["PypeLine", "PypeBranch"]
from os.path import abspath, dirname, join
import FreeCAD
import FreeCADGui
import Part
import fCmd
import pCmd
from quetzal_config import FREECADVERSION, get_icon_path
QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP
translate = FreeCAD.Qt.translate
vO = FreeCAD.Vector(0, 0, 0)
vX = FreeCAD.Vector(1, 0, 0)
vY = FreeCAD.Vector(0, 1, 0)
vZ = FreeCAD.Vector(0, 0, 1)
################ CLASSES ###########################
class pypeType(object):
def __init__(self, obj):
obj.addProperty(
"App::PropertyString",
"PType",
"PBase",
QT_TRANSLATE_NOOP("App::Property", "Type of tubeFeature"),
).PType
obj.addProperty(
"App::PropertyString",
"PRating",
"PBase",
QT_TRANSLATE_NOOP("App::Property", "Rating of pipeFeature"),
).PRating
obj.addProperty(
"App::PropertyString",
"PSize",
"PBase",
QT_TRANSLATE_NOOP("App::Property", "Nominal diameter"),
).PSize
obj.addProperty(
"App::PropertyVectorList",
"Ports",
"PBase",
QT_TRANSLATE_NOOP(
"App::Property",
"Ports position relative to the origin of Shape",
),
)
obj.addProperty(
"App::PropertyFloat",
"Kv",
"PBase",
QT_TRANSLATE_NOOP("App::Property", "Flow factor (m3/h/bar)"),
).Kv
if FREECADVERSION > 0.19:
obj.addExtension("Part::AttachExtensionPython")
else:
obj.addExtension("Part::AttachExtensionPython", obj) # 20220704
self.Name = obj.Name
def execute(self, fp):
fp.positionBySupport() # to recomute placement according the Support
def nearestPort(self, point=None):
"""
nearestPort (point=None)
Returns the Port nearest to point
or to the selected geometry.
(<portNr>, <portPos>, <portDir>)
"""
if FreeCAD.ActiveDocument:
obj = FreeCAD.ActiveDocument.getObject(self.Name)
if not point and FreeCADGui.ActiveDocument:
try:
selex = FreeCADGui.Selection.getSelectionEx()
target = selex[0].Object
so = selex[0].SubObjects[0]
except:
FreeCAD.Console.PrintError("No geometry selected\n")
return None
if type(so) == Part.Vertex:
point = so.Point
else:
point = so.CenterOfMass
if point:
pos = pCmd.portsPos(obj)[0]
Z = pCmd.portsDir(obj)[0]
i = nearest = 0
if len(obj.Ports) > 1:
for p in pCmd.portsPos(obj)[1:]:
i += 1
if (p - point).Length < (pos - point).Length:
pos = p
Z = pCmd.portsDir(obj)[i]
nearest = i
return nearest, pos, Z
class Pipe(pypeType):
"""Class for object PType="Pipe"
Pipe(obj,[PSize="DN50",OD=60.3,thk=3, H=100])
obj: the "App::FeaturePython object"
PSize (string): nominal diameter
OD (float): outside diameter
thk (float): shell thickness
H (float): length of pipe"""
def __init__(self, obj, DN="DN50", OD=60.3, thk=3, H=100):
# initialize the parent class
super(Pipe, self).__init__(obj)
# define common properties
obj.PType = "Pipe"
obj.Proxy = self
obj.PRating = "SCH-STD"
obj.PSize = DN
# define specific properties
obj.addProperty(
"App::PropertyLength",
"OD",
"Pipe",
QT_TRANSLATE_NOOP("App::Property", "Outside diameter"),
).OD = OD
obj.addProperty(
"App::PropertyLength",
"thk",
"Pipe",
QT_TRANSLATE_NOOP("App::Property", "Wall thickness"),
).thk = thk
obj.addProperty(
"App::PropertyLength",
"ID",
"Pipe",
QT_TRANSLATE_NOOP("App::Property", "Inside diameter"),
).ID = obj.OD - 2 * obj.thk
obj.addProperty(
"App::PropertyLength",
"Height",
"Pipe",
QT_TRANSLATE_NOOP("App::Property", "Length of tube"),
).Height = H
obj.addProperty(
"App::PropertyString",
"Profile",
"Pipe",
QT_TRANSLATE_NOOP("App::Property", "Section dim."),
).Profile = str(obj.OD) + "x" + str(obj.thk)
def onChanged(self, fp, prop):
if prop == "ID" and fp.ID < fp.OD:
fp.thk = (fp.OD - fp.ID) / 2
def execute(self, fp):
from math import tan
try:
parent = fp.getParentGroup()
i = parent.Tubes.index(fp.Name)
edges = parent.Base.Shape.Edges
L = edges[i].Length
R = parent.BendRadius
if i < len(parent.Curves):
v1, v2 = [e.tangentAt(0) for e in edges[i : i + 2]]
alfa = float(v1.getAngle(v2)) / 2
L -= float(R * tan(alfa))
if i:
v1, v2 = [e.tangentAt(0) for e in edges[i - 1 : i + 1]]
alfa = float(v1.getAngle(v2)) / 2
tang = float(R * tan(alfa))
L -= tang
fp.AttachmentOffset.Base = FreeCAD.Vector(0, 0, tang)
fp.Height = L
except Exception:
# FreeCAD.Console.PrintWarning(str(e) + "\n")
pass
if fp.thk > fp.OD / 2:
fp.thk = fp.OD / 2
fp.ID = fp.OD - 2 * fp.thk
fp.Profile = str(fp.OD) + "x" + str(fp.thk)
if fp.ID:
fp.Shape = Part.makeCylinder(fp.OD / 2, fp.Height).cut(
Part.makeCylinder(fp.ID / 2, fp.Height)
)
else:
fp.Shape = Part.makeCylinder(fp.OD / 2, fp.Height)
fp.Ports = [FreeCAD.Vector(), FreeCAD.Vector(0, 0, float(fp.Height))]
super(Pipe, self).execute(fp) # perform common operations
class Elbow(pypeType):
"""Class for object PType="Elbow"
Elbow(obj,[PSize="DN50",OD=60.3,thk=3,BA=90,BR=45.225])
obj: the "App::FeaturePython" object
PSize (string): nominal diameter
OD (float): outside diameter
thk (float): shell thickness
BA (float): bend angle
BR (float): bend radius"""
def __init__(self, obj, DN="DN50", OD=60.3, thk=3, BA=90, BR=45.225):
# initialize the parent class
super(Elbow, self).__init__(obj)
# define common properties
obj.PType = "Elbow"
obj.PRating = "SCH-STD"
obj.PSize = DN
# define specific properties
obj.addProperty(
"App::PropertyLength",
"OD",
"Elbow",
QT_TRANSLATE_NOOP("App::Property", "Outside diameter"),
).OD = OD
obj.addProperty(
"App::PropertyLength",
"thk",
"Elbow",
QT_TRANSLATE_NOOP("App::Property", "Wall thickness"),
).thk = thk
obj.addProperty(
"App::PropertyLength",
"ID",
"Elbow",
QT_TRANSLATE_NOOP("App::Property", "Inside diameter"),
).ID = obj.OD - 2 * obj.thk
obj.addProperty(
"App::PropertyAngle",
"BendAngle",
"Elbow",
QT_TRANSLATE_NOOP("App::Property", "Bend Angle"),
).BendAngle = BA
obj.addProperty(
"App::PropertyLength",
"BendRadius",
"Elbow",
QT_TRANSLATE_NOOP("App::Property", "Bend Radius"),
).BendRadius = BR
obj.addProperty(
"App::PropertyString",
"Profile",
"Elbow",
QT_TRANSLATE_NOOP("App::Property", "Section dim."),
).Profile = str(obj.OD) + "x" + str(obj.thk)
# obj.Ports=[FreeCAD.Vector(1,0,0),FreeCAD.Vector(0,1,0)]
self.execute(obj)
def onChanged(self, fp, prop):
if prop == "ID" and fp.ID < fp.OD:
fp.thk = (fp.OD - fp.ID) / 2
def execute(self, fp):
parent = fp.getParentGroup()
if parent:
try:
edges = parent.Base.Shape.Edges
i = parent.Curves.index(fp.Name)
v1, v2 = [e.tangentAt(0) for e in edges[i : i + 2]]
pCmd.placeTheElbow(fp, v1, v2)
except Exception:
# FreeCAD.Console.PrintWarning(str(e) + "\n")
pass
if fp.BendAngle < 180:
if fp.thk > fp.OD / 2:
fp.thk = fp.OD / 2
fp.ID = fp.OD - 2 * fp.thk
fp.Profile = str(fp.OD) + "x" + str(fp.thk)
CenterOfBend = FreeCAD.Vector(fp.BendRadius, fp.BendRadius, 0)
## make center-line ##
R = Part.makeCircle(
fp.BendRadius,
CenterOfBend,
FreeCAD.Vector(0, 0, 1),
225 - float(fp.BendAngle) / 2,
225 + float(fp.BendAngle) / 2,
)
## move the cl so that Placement.Base is the center of elbow ##
from math import pi, cos, sqrt
d = fp.BendRadius * sqrt(2) - fp.BendRadius / cos(fp.BendAngle / 180 * pi / 2)
P = FreeCAD.Vector(-d * cos(pi / 4), -d * cos(pi / 4), 0)
R.translate(P)
## calculate Ports position ##
fp.Ports = [R.valueAt(R.FirstParameter), R.valueAt(R.LastParameter)]
## make the shape of the elbow ##
c = Part.makeCircle(fp.OD / 2, fp.Ports[0], R.tangentAt(R.FirstParameter) * -1)
b = Part.makeSweepSurface(R, c)
p1 = Part.Face(Part.Wire(c))
p2 = Part.Face(
Part.Wire(Part.makeCircle(fp.OD / 2, fp.Ports[1], R.tangentAt(R.LastParameter)))
)
try:
sol = Part.Solid(Part.Shell([b.Faces[0], p1.Faces[0], p2.Faces[0]]))
planeFaces = [f for f in sol.Faces if type(f.Surface) == Part.Plane]
# elbow=sol.makeThickness(planeFaces,-fp.thk,1.e-3)
# fp.Shape = elbow
if fp.thk < fp.OD / 2:
fp.Shape = sol.makeThickness(planeFaces, -fp.thk, 1.0e-3)
else:
fp.Shape = sol
super(Elbow, self).execute(fp) # perform common operations
except Part.OCCError as occer:
FreeCAD.Console.PrintWarning(str(occer) + "\n")
class Flange(pypeType):
"""Class for object PType="Flange"
Flange(obj,[PSize="DN50",FlangeType="SO", D=160, d=60.3,df=132, f=14 t=15,n=4, trf=0, drf=0, twn=0, dwn=0, ODp=0])
obj: the "App::FeaturePython" object
PSize (string): nominal diameter
FlangeType (string): type of Flange
D (float): flange diameter
d (float): bore diameter
df (float): bolts holes distance
f (float): bolts holes diameter
t (float): flange thickness
n (int): nr. of bolts
trf (float): raised-face thickness - OPTIONAL -
drf (float): raised-face diameter - OPTIONAL -
twn (float): welding-neck thickness - OPTIONAL -
dwn (float): welding-neck diameter - OPTIONAL -
ODp (float): outside diameter of pipe for wn flanges - OPTIONAL -
"""
def __init__(
self,
obj,
DN="DN50",
FlangeType="SO",
D=160,
d=60.3,
df=132,
f=14,
t=15,
n=4,
trf=0,
drf=0,
twn=0,
dwn=0,
ODp=0,
R=0,
T1=0,
B2=0,
Y=0,
):
# initialize the parent class
super(Flange, self).__init__(obj)
# define common properties
self.Type = "Flange"
obj.Proxy = self
obj.PType = "Flange"
obj.PRating = "DIN-PN16"
obj.PSize = DN
# define specific properties
obj.addProperty(
"App::PropertyString",
"FlangeType",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Type of flange"),
).FlangeType = FlangeType
obj.addProperty(
"App::PropertyLength",
"D",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Flange diameter"),
).D = D
obj.addProperty(
"App::PropertyLength",
"d",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Bore diameter"),
).d = d
obj.addProperty(
"App::PropertyLength",
"df",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Bolts distance"),
).df = df
obj.addProperty(
"App::PropertyLength",
"f",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Bolts hole diameter"),
).f = f
obj.addProperty(
"App::PropertyLength",
"t",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Thickness of flange"),
).t = t
obj.addProperty(
"App::PropertyInteger",
"n",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Nr. of bolts"),
).n = n
obj.addProperty(
"App::PropertyLength",
"trf",
"Flange2",
QT_TRANSLATE_NOOP("App::Property", "Thickness of raised face"),
).trf = trf
obj.addProperty(
"App::PropertyLength",
"drf",
"Flange2",
QT_TRANSLATE_NOOP("App::Property", "Diameter of raised face"),
).drf = drf
obj.addProperty(
"App::PropertyLength",
"twn",
"Flange2",
QT_TRANSLATE_NOOP("App::Property", "Length of welding neck"),
).twn = twn
obj.addProperty(
"App::PropertyLength",
"dwn",
"Flange2",
QT_TRANSLATE_NOOP("App::Property", "Diameter of welding neck"),
).dwn = dwn
obj.addProperty(
"App::PropertyLength",
"ODp",
"Flange2",
QT_TRANSLATE_NOOP("App::Property", "Outside diameter of pipe"),
).ODp = ODp
obj.addProperty(
"App::PropertyLength",
"R",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Flange fillet radius"),
).R = R
obj.addProperty(
"App::PropertyLength",
"T1",
"Flange",
QT_TRANSLATE_NOOP("App::Property", "Flange neck length"),
).T1 = T1
obj.addProperty(
"App::PropertyLength",
"B2",
"Flange Socket welding",
QT_TRANSLATE_NOOP("App::Property", "Socket diameter"),
).B2 = B2
obj.addProperty(
"App::PropertyLength",
"Y",
"Flange Socket welding",
QT_TRANSLATE_NOOP("App::Property", "Socket depth"),
).Y = Y
def onChanged(self, fp, prop):
# FreeCAD.Console.PrintMessage(prop)
if prop == "ODp":
if fp.ODp > fp.D:
FreeCAD.Console.PrintError(
"Raised edge diameter must be smaller than flange diameter"
)
return None
def execute(self, fp):
""" """
base = Part.Face(Part.Wire(Part.makeCircle(fp.D / 2)))
if fp.d > 0:
base = base.cut(Part.Face(Part.Wire(Part.makeCircle(fp.d / 2))))
# Operation designed to make flange hole cylinders
if fp.n > 0:
hole = Part.Face(
Part.Wire(
Part.makeCircle(
fp.f / 2,
FreeCAD.Vector(fp.df / 2, 0, 0),
FreeCAD.Vector(0, 0, 1),
)
)
)
hole.rotate(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, 1), 360.0 / fp.n / 2)
for i in list(range(fp.n)):
base = base.cut(hole)
hole.rotate(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, 1), 360.0 / fp.n)
# creates flange thickness
flange = base.extrude(FreeCAD.Vector(0, 0, fp.t - fp.trf))
fp.ViewObject.Deviation = 0.10
if (
fp.FlangeType == "SW"
or fp.FlangeType == "WN"
or fp.FlangeType == "LJ"
or fp.FlangeType == "SO"
):
# creates flange neck
nn = Part.makeCylinder(fp.ODp / 2, fp.T1 - fp.trf, vO, vZ).cut(
Part.makeCylinder(fp.d / 2, fp.T1 - fp.trf, vO, vZ)
)
flange = flange.fuse(nn)
if fp.trf > 0 and fp.drf < fp.D:
rf = Part.makeCylinder(fp.drf / 2, fp.trf, vO, vZ * -1).cut(
Part.makeCylinder(fp.d / 2, fp.trf, vO, vZ * -1)
)
flange = flange.fuse(rf)
if fp.FlangeType == "WN":
try: # Flange2:welding-neck
if fp.dwn > 0 and fp.twn > 0 and fp.ODp > 0:
wn = Part.makeCone(
fp.dwn / 2, fp.ODp / 2, fp.twn, vZ * float(fp.t - fp.trf)
).cut(Part.makeCylinder(fp.d / 2, fp.twn, vZ * float(fp.t - fp.trf)))
flange = flange.fuse(wn)
flange = flange.removeSplitter()
flange = flange.makeFillet(fp.R, [flange.Edges[2]])
flange = flange.makeChamfer((fp.ODp - fp.d) / 2 * 0.90, [flange.Edges[6]])
except:
pass
elif fp.FlangeType == "LJ":
edge = []
flange = flange.removeSplitter()
if fp.n == 4:
edge = flange.Edges[19]
if fp.n == 8:
edge = flange.Edges[31]
if fp.n == 12:
edge = flange.Edges[43]
if fp.n == 16:
edge = flange.Edges[55]
if fp.n == 20:
edge = flange.Edges[67]
flange = flange.makeFillet(fp.R, edge)
elif fp.FlangeType == "SW":
# creates flange neck
if fp.B2 > 0:
nn = flange.cut(
Part.makeCylinder(fp.B2 / 2, fp.Y, vZ * float(fp.T1 - fp.trf), vZ * -1)
)
flange = nn.removeSplitter()
fp.Shape = flange
fp.Ports = [FreeCAD.Vector(), FreeCAD.Vector(0, 0, float(fp.t))]
super(Flange, self).execute(fp) # perform common operations
#!TODO:this method generate a PartDesign object with sketch nest, pending feature compatibility
# def execute(self,fp):
# obj=FreeCAD.activeDocument().addObject('PartDesign::Body','Flange')
# sketch=obj.newObject('Sketcher::SketchObject','Sketch')
# sketch.AttachmentSupport=(FreeCAD.activeDocument().getObject('YZ_Plane'),[''])
# sketch.MapMode='FlatFace'
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(-26.396620,19.420528,0),FreeCAD.Vector(37.200497,20.283836,0)),False)
# sketch.addConstraint(Sketcher.Constraint('DistanceY',-1,1,0,2,fp.d/2))
# sketch.renameConstraint(0, u'InnerDiameter')
# sketch.addConstraint(Sketcher.Constraint('Symmetric',0,1,0,2,-2))
# sketch.addConstraint(Sketcher.Constraint('DistanceX',0,1,0,2,70))
# sketch.renameConstraint(2, u'OverallThickness')
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(37.200497,19.420528,0),FreeCAD.Vector(37.200497,24.312616,0)),False)
# sketch.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1))
# sketch.addConstraint(Sketcher.Constraint('Vertical',1))
# sketch.addGeometry(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(34.202893,24.312616,0),FreeCAD.Vector(0,0,1),2.997604),0.000000,1.287001),False)
# sketch.addConstraint(Sketcher.Constraint('Tangent',1,2,2,1))
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(35.042226,27.190315,0),FreeCAD.Vector(6.698068,35.457398,0)),False)
# sketch.addConstraint(Sketcher.Constraint('Tangent',2,2,3,1))
# sketch.addGeometry(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(7.314065,37.569377,0),FreeCAD.Vector(0,0,1),2.199979),-3.132797,-1.854592),False)
# sketch.addConstraint(Sketcher.Constraint('Equal',2,4))
# sketch.addConstraint(Sketcher.Constraint('Tangent',3,2,4,2))
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(5.114171,37.550027,0),FreeCAD.Vector(4.854102,67.117138,0)),False)
# sketch.addConstraint(Sketcher.Constraint('Tangent',4,1,5,1))
# sketch.addGeometry(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(1.818155,67.090434,0),FreeCAD.Vector(0,0,1),3.036064),0.008796,1.579592),False)
# sketch.addConstraint(Sketcher.Constraint('Equal',6,4))
# sketch.addConstraint(Sketcher.Constraint('Radius',4,3))
# sketch.addConstraint(Sketcher.Constraint('Tangent',5,2,6,1))
# sketch.addConstraint(Sketcher.Constraint('Vertical',5))
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(1.791451,70.126381,0),FreeCAD.Vector(-23.109907,69.907350,0)),False)
# sketch.addConstraint(Sketcher.Constraint('Horizontal',7))
# sketch.addConstraint(Sketcher.Constraint('Tangent',6,2,7,1))
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(-23.109907,69.907350,0),FreeCAD.Vector(-22.849606,40.313959,0)),False)
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(-22.849606,40.313959,0),FreeCAD.Vector(-27.278782,40.223301,0)),False)
# sketch.addConstraint(Sketcher.Constraint('Coincident',7,2,8,1))
# sketch.addConstraint(Sketcher.Constraint('Vertical',8))
# sketch.addConstraint(Sketcher.Constraint('Coincident',8,2,9,1))
# sketch.addConstraint(Sketcher.Constraint('DistanceY',8,1,8,2,-10))
# sketch.addConstraint(Sketcher.Constraint('Horizontal',9))
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(-27.278782,40.313959,0),FreeCAD.Vector(-26.396620,19.420528,0)),False)
# sketch.addConstraint(Sketcher.Constraint('Coincident',9,2,10,1))
# sketch.addConstraint(Sketcher.Constraint('Coincident',10,2,0,1))
# sketch.addConstraint(Sketcher.Constraint('Vertical',10))
# sketch.addConstraint(Sketcher.Constraint('DistanceY',-1,1,7,2,fp.D/2))
# sketch.renameConstraint(24, u'OuterDiameter')
# sketch.addConstraint(Sketcher.Constraint('DistanceX',9,2,5,2,fp.t))
# sketch.renameConstraint(25, u'FlangeThickness')
# sketch.Visibility=False
# sketch.recompute()
# revolution=obj.newObject('PartDesign::Revolution','Revolution')
# revolution.Profile=(sketch, [''])
# revolution.ReferenceAxis = (sketch, ['H_Axis'])
# fp.Placement=fp.Placement
# fp.Shape= obj.Shape
class Reduct(pypeType):
"""Class for object PType="Reduct"
Reduct(obj,[PSize="DN50",OD=60.3, OD2= 48.3, thk=3, thk2=None, H=None, conc=True])
obj: the "App::FeaturePython object"
PSize (string): nominal diameter (major)
OD (float): major outside diameter
OD2 (float): minor outside diameter
thk (float): major shell thickness
thk2 (float): minor shell thickness
H (float): length of reduction
conc (bool): True for a concentric reduction, False for eccentric
If thk2 is None or 0, the same thickness is used at both ends.
If H is None or 0, the length of the reduction is calculated as 3x(OD-OD2).
"""
def __init__(self, obj, DN="DN50", OD=60.3, OD2=48.3, thk=3, thk2=None, H=None, conc=True):
# initialize the parent class
super(Reduct, self).__init__(obj)
# define common properties
obj.Proxy = self
obj.PType = "Reduct"
obj.PRating = "SCH-STD"
obj.PSize = DN
# define specific properties
obj.addProperty(
"App::PropertyLength",
"OD",
"Reduct",
QT_TRANSLATE_NOOP("App::Property", "Major diameter"),
).OD = OD
obj.addProperty(
"App::PropertyLength",
"OD2",
"Reduct",
QT_TRANSLATE_NOOP("App::Property", "Minor diameter"),
).OD2 = OD2
obj.addProperty(
"App::PropertyLength",
"thk",
"Reduct",
QT_TRANSLATE_NOOP("App::Property", "Wall thickness"),
).thk = thk
obj.addProperty(
"App::PropertyLength",
"thk2",
"Reduct",
QT_TRANSLATE_NOOP("App::Property", "Wall thickness"),
)
if not thk2:
obj.thk2 = thk
else:
obj.thk2 = thk2
obj.addProperty(
"App::PropertyBool",
"calcH",
"Reduct",
QT_TRANSLATE_NOOP("App::Property", "Make the length variable"),
)
obj.addProperty(
"App::PropertyLength",
"Height",
"Reduction",
QT_TRANSLATE_NOOP("App::Property", "Length of reduction"),
)
if not H:
obj.calcH = True
obj.Height = 3 * (obj.OD - obj.OD2)
else:
obj.calcH = False
obj.Height = float(H)
obj.addProperty(
"App::PropertyString",
"Profile",
"Reduct",
QT_TRANSLATE_NOOP("App::Property", "Section dim."),
).Profile = str(obj.OD) + "x" + str(obj.OD2)
obj.addProperty(
"App::PropertyBool",
"conc",
"Reduct",
QT_TRANSLATE_NOOP("App::Property", "Concentric or Eccentric"),
).conc = conc
def onChanged(self, fp, prop):
return None
def execute(self, fp):
if fp.OD > fp.OD2:
if fp.calcH or fp.Height == 0:
fp.Height = 3 * (fp.OD - fp.OD2)
fp.Profile = str(fp.OD) + "x" + str(fp.OD2)
if fp.conc:
sol = Part.makeCone(fp.OD / 2, fp.OD2 / 2, fp.Height)
if fp.thk < fp.OD / 2 and fp.thk2 < fp.OD2 / 2:
fp.Shape = sol.cut(
Part.makeCone(fp.OD / 2 - fp.thk, fp.OD2 / 2 - fp.thk2, fp.Height)
)
else:
fp.Shape = sol
fp.Ports = [FreeCAD.Vector(), FreeCAD.Vector(0, 0, float(fp.Height))]
else:
C = Part.makeCircle(fp.OD / 2, FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, 1))
c = Part.makeCircle(fp.OD2 / 2, FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, 1))
c.translate(FreeCAD.Vector((fp.OD - fp.OD2) / 2, 0, fp.Height))
sol = Part.makeLoft([c, C], True)
if fp.thk < fp.OD / 2 and fp.thk2 < fp.OD2 / 2:
C = Part.makeCircle(
fp.OD / 2 - fp.thk,
FreeCAD.Vector(0, 0, 0),
FreeCAD.Vector(0, 0, 1),
)
c = Part.makeCircle(
fp.OD2 / 2 - fp.thk2,
FreeCAD.Vector(0, 0, 0),
FreeCAD.Vector(0, 0, 1),
)
c.translate(FreeCAD.Vector((fp.OD - fp.OD2) / 2, 0, fp.Height))
fp.Shape = sol.cut(Part.makeLoft([c, C], True))
else:
fp.Shape = sol
fp.Ports = [
FreeCAD.Vector(),
FreeCAD.Vector((fp.OD - fp.OD2) / 2, 0, float(fp.Height)),
]
super(Reduct, self).execute(fp) # perform common operations
class Cap(pypeType):
"""Class for object PType="Cap"
Cap(obj,[PSize="DN50",OD=60.3,thk=3])
obj: the "App::FeaturePython object"
PSize (string): nominal diameter
OD (float): outside diameter
thk (float): shell thickness"""
def __init__(self, obj, DN="DN50", OD=60.3, thk=3):
# initialize the parent class
super(Cap, self).__init__(obj)
# define common properties
obj.PType = "Cap"
obj.Proxy = self
obj.PRating = "SCH-STD"
obj.PSize = DN
# define specific properties
obj.addProperty(
"App::PropertyLength",
"OD",
"Cap",
QT_TRANSLATE_NOOP("App::Property", "Outside diameter"),
).OD = OD
obj.addProperty(
"App::PropertyLength",
"thk",
"Cap",
QT_TRANSLATE_NOOP("App::Property", "Wall thickness"),
).thk = thk
obj.addProperty(
"App::PropertyLength",
"ID",
"Cap",
QT_TRANSLATE_NOOP("App::Property", "Inside diameter"),
).ID = obj.OD - 2 * obj.thk
obj.addProperty(
"App::PropertyString",
"Profile",
"Cap",
QT_TRANSLATE_NOOP("App::Property", "Section dim."),
).Profile = str(obj.OD) + "x" + str(obj.thk)
def onChanged(self, fp, prop):
return None
def execute(self, fp):
if fp.thk > fp.OD / 2:
fp.thk = fp.OD / 2.1
fp.ID = fp.OD - 2 * fp.thk
fp.Profile = str(fp.OD) + "x" + str(fp.thk)
D = float(fp.OD)
s = float(fp.thk)
sfera = Part.makeSphere(0.8 * D, FreeCAD.Vector(0, 0, -(0.55 * D - 6 * s)))
cilindro = Part.makeCylinder(
D / 2,
D * 1.7,
FreeCAD.Vector(0, 0, -(0.55 * D - 6 * s + 1)),
FreeCAD.Vector(0, 0, 1),
)
common = sfera.common(cilindro)
fil = common.makeFillet(D / 6.5, common.Edges)
cut = fil.cut(
Part.makeCylinder(D * 1.1, D * 2, FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, -1))
)
cap = cut.makeThickness([f for f in cut.Faces if type(f.Surface) == Part.Plane], -s, 1.0e-3)
fp.Shape = cap
fp.Ports = [FreeCAD.Vector()]
super(Cap, self).execute(fp) # perform common operations
class PypeLine2(pypeType):
"""Class for object PType="PypeLine2"
This object represent a collection of objects "PType" that are updated with the
methods defined in the Python class.
At present time it creates, with the method obj.Proxy.update(,obj,[edges]), pipes and curves over
the given edges and collect them in a group named according the object's .Label.
PypeLine2 features also the optional attribute ".Base":
- Base can be a Wire or a Sketch or any object which has edges in its Shape.
- Running "obj.Proxy.update(obj)", without any [edges], the class attempts to render the pypeline
(Pipe and Elbow objects) on the "obj.Base" edges: for well defined geometries
and open paths, this usually leads to acceptable results.
- Running "obj.Proxy.purge(obj)" deletes from the model all Pipes and Elbows
that belongs to the pype-line.
- It's possible to add other objects afterwards (such as Flange, Reduct...)
using the relevant insertion dialogs but remember that these won't be updated
when the .Base is changed and won't be deleted if the pype-line is purged.
- If Base is None, PypeLine2 behaves like a bare container of objects,
with possibility to group them automatically and extract the part-list.
"""
def __init__(self, obj, DN="DN50", PRating="SCH-STD", OD=60.3, thk=3, BR=None, lab=None):
# initialize the parent class
super(PypeLine2, self).__init__(obj)
# define common properties
obj.Proxy = self
obj.PType = "PypeLine"
obj.PSize = DN
obj.PRating = PRating
if lab:
obj.Label = lab
# define specific properties
if not BR:
BR = 0.75 * OD
obj.addProperty(
"App::PropertyLength",
"BendRadius",
"PypeLine2",
QT_TRANSLATE_NOOP("App::Property", "the radius of bending"),
).BendRadius = BR
obj.addProperty(
"App::PropertyLength",
"OD",
"PypeLine2",
QT_TRANSLATE_NOOP("App::Property", "Outside diameter"),
).OD = OD
obj.addProperty(
"App::PropertyLength",
"thk",
"PypeLine2",
QT_TRANSLATE_NOOP("App::Property", "Wall thickness"),
).thk = thk
obj.addProperty(
"App::PropertyString",
"Group",
"PypeLine2",
QT_TRANSLATE_NOOP("App::Property", "The group."),
).Group = obj.Label + "_pieces"
group = FreeCAD.activeDocument().addObject("App::DocumentObjectGroup", obj.Group)
group.addObject(obj)
FreeCAD.Console.PrintWarning("Created group " + obj.Group + "\n")
obj.addProperty("App::PropertyLink", "Base", "PypeLine2", "the edges")
def onChanged(self, fp, prop):
if prop == "Label" and len(fp.InList):
fp.InList[0].Label = fp.Label + "_pieces"
fp.Group = fp.Label + "_pieces"
if hasattr(fp, "Base") and prop == "Base" and fp.Base:
FreeCAD.Console.PrintWarning(fp.Label + " Base has changed to " + fp.Base.Label + "\n")
if prop == "OD":
fp.BendRadius = 0.75 * fp.OD
fp.Proxy.update(fp)
def purge(self, fp):
group = FreeCAD.activeDocument().getObjectsByLabel(fp.Group)[0]
for o in group.OutList:
if hasattr(o, "PType") and o.PType in ["Pipe", "Elbow"]:
FreeCAD.activeDocument().removeObject(o.Name)
def update(self, fp, edges=None):
from DraftVecUtils import rounded
from math import degrees
if not edges and hasattr(fp.Base, "Shape"):
edges = fp.Base.Shape.Edges
if not edges:
FreeCAD.Console.PrintError("Base has not valid edges\n")
return
pipes = list()
for e in edges:
# ---Create the tube---
p = pCmd.makePipe(
[fp.PSize, fp.OD, fp.thk, e.Length], pos=e.valueAt(0), Z=e.tangentAt(0)
)
p.PRating = fp.PRating
p.PSize = fp.PSize
pCmd.moveToPyLi(p, fp.Label)
pipes.append(p)
n = len(pipes) - 1
if n and not fCmd.isParallel(fCmd.beamAx(pipes[n]), fCmd.beamAx(pipes[n - 1])):
# ---Create the curve---
propList = [fp.PSize, fp.OD, fp.thk, 90, fp.BendRadius]
c = pCmd.makeElbowBetweenThings(edges[n], edges[n - 1], propList)
if c:
portA, portB = [c.Placement.multVec(port) for port in c.Ports]
# ---Trim the tube---
p1, p2 = pipes[-2:]
fCmd.extendTheBeam(p1, portA)
fCmd.extendTheBeam(p2, portB)
pCmd.moveToPyLi(c, fp.Label)
def execute(self, fp):
return None
class ViewProviderPypeLine:
def __getstate__(self):
return None
def __setstate__(self, data):
return None
def __init__(self, vobj):
vobj.Proxy = self
def getIcon(self):
return get_icon_path("Quetzal_InsertPypeLine")
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
def getIcon(self):
from os.path import join, dirname, abspath
return get_icon_path("Quetzal_InsertPypeLine")
def attach(self, vobj):
self.ViewObject = vobj
self.Object = vobj.Object
class Ubolt:
"""Class for object PType="Clamp"
UBolt(obj,[PSize="DN50",ClampType="U-bolt", C=76, H=109, d=10])
obj: the "App::FeaturePython" object
PSize (string): nominal diameter
ClampType (string): the clamp type or standard
C (float): the diameter of the U-bolt
H (float): the total height of the U-bolt
d (float): the rod diameter
"""
def __init__(self, obj, DN="DN50", ClampType="DIN-UBolt", C=76, H=109, d=10):
obj.Proxy = self
obj.addProperty(
"App::PropertyString",
"PType",
"Ubolt",
QT_TRANSLATE_NOOP("App::Property", "Type of pipeFeature"),
).PType = "Clamp"
obj.addProperty(
"App::PropertyString",
"ClampType",
"Ubolt",
QT_TRANSLATE_NOOP("App::Property", "Type of clamp"),
).ClampType = ClampType
obj.addProperty(
"App::PropertyString",
"PSize",
"Ubolt",
QT_TRANSLATE_NOOP("App::Property", "Size of clamp"),
).PSize = DN
obj.addProperty(
"App::PropertyLength",
"C",
"Ubolt",
QT_TRANSLATE_NOOP("App::Property", "Arc diameter"),
).C = C
obj.addProperty(
"App::PropertyLength",
"H",
"Ubolt",
QT_TRANSLATE_NOOP("App::Property", "Overall height"),
).H = H
obj.addProperty(
"App::PropertyLength",
"d",
"Ubolt",
QT_TRANSLATE_NOOP("App::Property", "Rod diameter"),
).d = d
obj.addProperty(
"App::PropertyString",
"thread",
"Ubolt",
QT_TRANSLATE_NOOP("App::Property", "Size of thread"),
).thread = "M" + str(d)
obj.addProperty(
"App::PropertyVectorList",
"Ports",
"PBase",