forked from oddtopus/dodo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPipe.py
319 lines (277 loc) · 12.1 KB
/
CPipe.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
#(c) 2019 R. T. LGPL: part of dodo w.b. for FreeCAD
__title__="pypeTools toolbar"
__author__="oddtopus"
__url__="github.com/oddtopus/dodo"
__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)
#print(name+":\n"+str(source))
def updatesPL(dialogqm):
if FreeCAD.activeDocument():
pypelines=[o.Label for o in FreeCAD.activeDocument().Objects if hasattr(o,'PType') and o.PType=='PypeLine']
else:
pypelines=[]
if pypelines: # updates pypelines in combo
dialogqm.QM.comboPL.clear()
dialogqm.QM.comboPL.addItems(pypelines)
#---------------------------------------------------------------------------
# The command classes
#---------------------------------------------------------------------------
class insertPipe:
def Activated (self):
import pForms
pipForm=pForms.insertPipeForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","pipe.svg"),'MenuText':'Insert a tube','ToolTip':'Insert a tube'}
class insertElbow:
def Activated (self):
import pForms,FreeCAD
elbForm=pForms.insertElbowForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","elbow.svg"),'MenuText':'Insert a curve','ToolTip':'Insert a curve'}
class insertReduct:
def Activated (self):
import pForms
pipeFormObj=pForms.insertReductForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","reduct.svg"),'MenuText':'Insert a reduction','ToolTip':'Insert a reduction'}
class insertCap:
def Activated (self):
import pForms
pipeFormObj=pForms.insertCapForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","cap.svg"),'MenuText':'Insert a cap','ToolTip':'Insert a cap'}
class insertFlange:
def Activated (self):
import pForms
pipeFormObj=pForms.insertFlangeForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","flange.svg"),'MenuText':'Insert a flange','ToolTip':'Insert a flange'}
class insertUbolt:
def Activated (self):
import pForms
pipeFormObj=pForms.insertUboltForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","clamp.svg"),'MenuText':'Insert a U-bolt','ToolTip':'Insert a U-bolt'}
class insertPypeLine:
def Activated (self):
import pForms
pipeFormObj=pForms.insertPypeLineForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","pypeline.svg"),'MenuText':'PypeLine Manager','ToolTip':'Open PypeLine Manager'}
class insertBranch:
def Activated (self):
import pForms
#pCmd.makeBranch()
pipeFormObj=pForms.insertBranchForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","branch.svg"),'MenuText':'Insert a branch','ToolTip':'Insert a PypeBranch'}
class breakPipe:
def Activated (self):
import pForms
pipeFormObj=pForms.breakForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","break.svg"),'MenuText':'Break the pipe','ToolTip':'Break one pipe at point and insert gap'}
class mateEdges:
def Activated (self):
import pCmd
FreeCAD.activeDocument().openTransaction('Mate')
pCmd.alignTheTube()
FreeCAD.activeDocument().commitTransaction()
FreeCAD.activeDocument().recompute()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","mate.svg"),'Accel':"M,E",'MenuText':'Mate pipes edges','ToolTip':'Mate two terminations through their edges'}
class flat:
def Activated (self):
import pCmd
pCmd.flatten()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","flat.svg"),'MenuText':'Fit one elbow','ToolTip':'Place the elbow between two pipes or beams'}
class extend2intersection:
def Activated (self):
import pCmd
FreeCAD.activeDocument().openTransaction('Xtend2int')
pCmd.extendTheTubes2intersection()
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","intersect.svg"),'MenuText':'Extends pipes to intersection','ToolTip':'Extends pipes to intersection'}
class extend1intersection:
def Activated (self):
import pCmd
FreeCAD.activeDocument().openTransaction('Xtend1int')
pCmd.extendTheTubes2intersection(both=False)
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","intersect1.svg"),'MenuText':'Extends pipe to intersection','ToolTip':'Extends pipe to intersection'}
class laydown:
def Activated (self):
import pCmd, fCmd
from Part import Plane
refFace=[f for f in fCmd.faces() if type(f.Surface)==Plane][0]
FreeCAD.activeDocument().openTransaction('Lay-down the pipe')
for b in fCmd.beams():
if pCmd.isPipe(b):
pCmd.laydownTheTube(b,refFace)
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","laydown.svg"),'MenuText':'Lay-down the pipe','ToolTip':'Lay-down the pipe on the support plane'}
class raiseup:
def Activated (self):
import pCmd, fCmd
from Part import Plane
selex=FreeCADGui.Selection.getSelectionEx()
for sx in selex:
sxFaces=[f for f in fCmd.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 fCmd.beams():
if pCmd.isPipe(b):
pCmd.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__)),"iconz","raiseup.svg"),'MenuText':'Raise-up the support','ToolTip':'Raise the support to the pipe'}
class joinPype:
'''
'''
def Activated(self):
import FreeCAD, FreeCADGui, pForms #pObservers
# s=pObservers.joinObserver()
FreeCADGui.Control.showDialog(pForms.joinForm()) #.Selection.addObserver(s)
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","join.svg"),'MenuText':'Join pypes','ToolTip':'Select the part-pype and the port'}
class insertValve:
def Activated (self):
import pForms
#pipeFormObj=pForms.insertValveForm()
#FreeCADGui.Control.showDialog(pForms.insertValveForm())
pipeFormObj=pForms.insertValveForm()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","valve.svg"),'MenuText':'Insert a valve','ToolTip':'Insert a valve'}
class attach2tube:
def Activated (self):
import pCmd
FreeCAD.activeDocument().openTransaction('Attach to tube')
pCmd.attachToTube()
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","attach.svg"),'MenuText':'Attach to tube','ToolTip':'Attach one pype to the nearest port of selected pipe'}
class point2point:
def Activated(self):
import pForms
form = pForms.point2pointPipe()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","point2point.svg"),'MenuText':'draw a tube point-to-point','ToolTip':'Click on subsequent points.'}
class insertAnyz:
'''
Dialog to insert any object saved as .STEP, .IGES or .BREP in folder ../Mod/dodo/shapez or subfolders.
'''
def Activated(self):
import anyShapez
FreeCADGui.Control.showDialog(anyShapez.shapezDialog())
def GetResources(self):
return{'MenuText':'Insert any shape','ToolTip':'Insert a STEP, IGES or BREP'}
class insertTank:
def Activated(self):
import FreeCADGui, pForms
FreeCADGui.Control.showDialog(pForms.insertTankForm())
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","tank.svg"),'MenuText':'Insert a tank','ToolTip':'Create tank and nozzles'}
class insertRoute:
def Activated(self):
import FreeCADGui, pForms
FreeCADGui.Control.showDialog(pForms.insertRouteForm())
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","route.svg"),'MenuText':'Insert a pipe route','ToolTip':'Create a sketch attached to a circular edge'}
class makeHeader:
def Activated (self):
import pCmd
FreeCAD.activeDocument().openTransaction('Connect to header')
pCmd.header()
FreeCAD.activeDocument().recompute()
FreeCAD.activeDocument().commitTransaction()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","header.svg"),'MenuText':'Connect to header','ToolTip':'Connect branches to one header pipe\nBranches and header\'s axes must be ortho'}
#---------------------------------------------------------------------------
# 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('insertAnyz',insertAnyz())
addCommand('makeHeader',makeHeader())
### QkMenus ###
class pipeQM:
def Activated(self):
import dodoPM
#dodoPM.pqm.updatePL()
dodoPM.pqm.show()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","pipe.svg"),'MenuText':'QM for pipes'}
addCommand('pipeQM',pipeQM())
class elbowQM():
def Activated (self):
import dodoPM
dodoPM.eqm.show()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","elbow.svg"),'MenuText':'QM for elbows'}
addCommand('elbowQM',elbowQM())
class flangeQM():
def Activated (self):
import dodoPM
dodoPM.fqm.show()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","flange.svg"),'MenuText':'QM for flanges'}
addCommand('flangeQM',flangeQM())
class valveQM():
def Activated (self):
import dodoPM
dodoPM.vqm.show()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","valve.svg"),'MenuText':'QM for valves'}
addCommand('valveQM',valveQM())
class capQM():
def Activated (self):
import dodoPM
dodoPM.cqm.show()
def GetResources(self):
return{'Pixmap':os.path.join(os.path.dirname(os.path.abspath(__file__)),"iconz","cap.svg"),'MenuText':'QM for caps'}
addCommand('capQM',capQM())