-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCommandsPipe.py
283 lines (248 loc) · 11.4 KB
/
CommandsPipe.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
#(c) 2016 R. T. LGPL: part of Flamingo tools w.b. for FreeCAD
__title__="pypeTools toolbar"
__author__="oddtopus"
__url__="github.com/oddtopus/flamingo"
__license__="LGPL 3"
# import FreeCAD modules
import FreeCAD, FreeCADGui,inspect, os
# helper -------------------------------------------------------------------
# FreeCAD TemplatePyMod module
# (c) 2007 Juergen Riegel LGPL
def addCommand(name,cmdObject):
(list,num) = inspect.getsourcelines(cmdObject.Activated)
pos = 0
# check for indentation
while(list[1][pos] == ' ' or list[1][pos] == '\t'):
pos += 1
source = ""
for i in range(len(list)-1):
source += list[i+1][pos:]
FreeCADGui.addCommand(name,cmdObject,source)
#---------------------------------------------------------------------------
# The command classes
#---------------------------------------------------------------------------
class insertPipe:
def Activated (self):
import pipeForms
pipForm=pipeForms.insertPipeForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","pipe.svg"),'MenuText':'Insert a tube','ToolTip':'Insert a tube'}
class insertElbow:
def Activated (self):
import pipeForms,FreeCAD
elbForm=pipeForms.insertElbowForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","elbow.svg"),'MenuText':'Insert a curve','ToolTip':'Insert a curve'}
class insertReduct:
def Activated (self):
import pipeForms
pipeFormObj=pipeForms.insertReductForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","reduct.svg"),'MenuText':'Insert a reduction','ToolTip':'Insert a reduction'}
class insertCap:
def Activated (self):
import pipeForms
pipeFormObj=pipeForms.insertCapForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","cap.svg"),'MenuText':'Insert a cap','ToolTip':'Insert a cap'}
class insertFlange:
def Activated (self):
import pipeForms
pipeFormObj=pipeForms.insertFlangeForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","flange.svg"),'MenuText':'Insert a flange','ToolTip':'Insert a flange'}
class insertUbolt:
def Activated (self):
import pipeForms
pipeFormObj=pipeForms.insertUboltForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","clamp.svg"),'MenuText':'Insert a U-bolt','ToolTip':'Insert a U-bolt'}
class insertPypeLine:
def Activated (self):
import pipeForms
pipeFormObj=pipeForms.insertPypeLineForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","pypeline.svg"),'MenuText':'PypeLine Manager','ToolTip':'Open PypeLine Manager'}
class insertBranch:
def Activated (self):
import pipeForms
#pipeCmd.makeBranch()
pipeFormObj=pipeForms.insertBranchForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","branch.svg"),'MenuText':'Insert a branch','ToolTip':'Insert a PypeBranch'}
class breakPipe:
def Activated (self):
import pipeForms
pipeFormObj=pipeForms.breakForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","break.svg"),'MenuText':'Break the pipe','ToolTip':'Break one pipe at point and insert gap'}
class mateEdges:
def Activated (self):
import pipeCmd
FreeCAD.activeDocument().openTransaction('Mate')
pipeCmd.alignTheTube()
FreeCAD.activeDocument().commitTransaction()
FreeCAD.activeDocument().recompute()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","mate.svg"),'Accel':"M,E",'MenuText':'Mate pipes edges','ToolTip':'Mate two terminations through their edges'}
class flat: # tool implemented with pipeCmd.placeTheElbow()
def Activated (self):
import frameCmd, pipeCmd
if len(frameCmd.beams())>1:
p1,p2=frameCmd.beams()[:2]
try:
P=frameCmd.intersectionCLines(p1,p2)
com1=p1.Shape.Solids[0].CenterOfMass
com2=p2.Shape.Solids[0].CenterOfMass
v1=P-com1
v2=com2-P
curves=[e for e in FreeCADGui.Selection.getSelection() if hasattr(e,'PType') and hasattr(e,'BendAngle')]
if curves:
FreeCAD.ActiveDocument.openTransaction('Place one curve')
pipeCmd.placeoTherElbow(curves[0],v1,v2,P)
FreeCAD.ActiveDocument.recompute() # recompute for the elbow
port1,port2=pipeCmd.portsPos(curves[0])
if (com1-port1).Length<(com1-port2).Length:
frameCmd.extendTheBeam(p1,port1)
frameCmd.extendTheBeam(p2,port2)
else:
frameCmd.extendTheBeam(p1,port2)
frameCmd.extendTheBeam(p2,port1)
FreeCAD.ActiveDocument.recompute() # recompute for the pipes
FreeCAD.ActiveDocument.commitTransaction()
else:
FreeCAD.Console.PrintError('Select at least one elbow')
except:
FreeCAD.Console.PrintError('Intersection point not found\n')
else:
FreeCAD.Console.PrintError('Select two intersecting pipes\n')
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","flat.svg"),'MenuText':'Fit one elbow','ToolTip':'Place the elbow between two pipes or beams'}
class extend2intersection:
def Activated (self):
import pipeCmd
FreeCAD.activeDocument().openTransaction('Xtend2int')
pipeCmd.extendTheTubes2intersection()
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","intersect.svg"),'MenuText':'Extends pipes to intersection','ToolTip':'Extends pipes to intersection'}
class extend1intersection:
def Activated (self):
import pipeCmd
FreeCAD.activeDocument().openTransaction('Xtend1int')
pipeCmd.extendTheTubes2intersection(both=False)
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","intersect1.svg"),'MenuText':'Extends pipe to intersection','ToolTip':'Extends pipe to intersection'}
class laydown:
def Activated (self):
import pipeCmd, frameCmd
from Part import Plane
refFace=[f for f in frameCmd.faces() if type(f.Surface)==Plane][0]
FreeCAD.activeDocument().openTransaction('Lay-down the pipe')
for b in frameCmd.beams():
if pipeCmd.isPipe(b):
pipeCmd.laydownTheTube(b,refFace)
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","laydown.svg"),'MenuText':'Lay-down the pipe','ToolTip':'Lay-down the pipe on the support plane'}
class raiseup:
def Activated (self):
import pipeCmd, frameCmd
from Part import Plane
selex=FreeCADGui.Selection.getSelectionEx()
for sx in selex:
sxFaces=[f for f in frameCmd.faces([sx]) if type(f.Surface)==Plane]
if len(sxFaces)>0:
refFace=sxFaces[0]
support=sx.Object
FreeCAD.activeDocument().openTransaction('Raise-up the support')
for b in frameCmd.beams():
if pipeCmd.isPipe(b):
pipeCmd.laydownTheTube(b,refFace,support)
break
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","raiseup.svg"),'MenuText':'Raise-up the support','ToolTip':'Raise the support to the pipe'}
class joinPype:
'''
'''
def Activated(self):
import FreeCAD, FreeCADGui, pipeForms #pipeObservers
# s=pipeObservers.joinObserver()
FreeCADGui.Control.showDialog(pipeForms.joinForm()) #.Selection.addObserver(s)
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","join.svg"),'MenuText':'Join pypes','ToolTip':'Select the part-pype and the port'}
class insertValve:
def Activated (self):
import pipeForms
#pipeFormObj=pipeForms.insertValveForm()
#FreeCADGui.Control.showDialog(pipeForms.insertValveForm())
pipeFormObj=pipeForms.insertValveForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","valve.svg"),'MenuText':'Insert a valve','ToolTip':'Insert a valve'}
class attach2tube:
def Activated (self):
import pipeCmd
FreeCAD.activeDocument().openTransaction('Attach to tube')
pipeCmd.attachToTube()
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","attach.svg"),'MenuText':'Attach to tube','ToolTip':'Attach one pype to the nearest port of selected pipe'}
class point2point:
def Activated(self):
import pipeForms
form = pipeForms.point2pointPipe()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","point2point.svg"),'MenuText':'draw a tube point-to-point','ToolTip':'Click on subsequent points.'}
class insertAny:
'''
Dialog to insert any object saved as .STEP, .IGES or .BREP in folder ../Mod/flamingo/shapes or subfolders.
'''
def Activated(self):
import anyShape
FreeCADGui.Control.showDialog(anyShape.shapeDialog())
def GetResources(self):
return{'MenuText':'Insert any shape','ToolTip':'Insert a STEP, IGES or BREP'}
class insertTank:
def Activated(self):
import FreeCADGui, pipeForms
FreeCADGui.Control.showDialog(pipeForms.insertTankForm())
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","tank.svg"),'MenuText':'Insert a tank','ToolTip':'Create tank and nozzles'}
class insertRoute:
def Activated(self):
import FreeCADGui, pipeForms
FreeCADGui.Control.showDialog(pipeForms.insertRouteForm())
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons","route.svg"),'MenuText':'Insert a pipe route','ToolTip':'Create a sketch attached to a circular edge'}
#---------------------------------------------------------------------------
# Adds the commands to the FreeCAD command manager
#---------------------------------------------------------------------------
addCommand('insertPipe',insertPipe())
addCommand('insertElbow',insertElbow())
addCommand('insertReduct',insertReduct())
addCommand('insertCap',insertCap())
addCommand('insertValve',insertValve())
addCommand('insertFlange',insertFlange())
addCommand('insertUbolt',insertUbolt())
addCommand('insertPypeLine',insertPypeLine())
addCommand('insertBranch',insertBranch())
addCommand('insertTank',insertTank())
addCommand('insertRoute',insertRoute())
addCommand('breakPipe',breakPipe())
addCommand('mateEdges',mateEdges())
addCommand('joinPype',joinPype())
addCommand('attach2tube',attach2tube())
addCommand('flat',flat())
addCommand('extend2intersection',extend2intersection())
addCommand('extend1intersection',extend1intersection())
addCommand('laydown',laydown())
addCommand('raiseup',raiseup())
addCommand('point2point',point2point())
addCommand('insertAny',insertAny())