forked from yorikvanhavre/BIM_Workbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBimCommands.py
329 lines (245 loc) · 11.1 KB
/
BimCommands.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
# -*- coding: utf8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2017 Yorik van Havre <[email protected]> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
"""This module contains FreeCAD commands for the BIM workbench"""
import os
import FreeCAD
from BimTranslateUtils import *
import ArchWindow
class BIM_Help:
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","BIM_Help.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_Help", "BIM Help"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Help", "Opens the BIM help page on the FreeCAD documentation website")}
def Activated(self):
from PySide import QtCore,QtGui
QtGui.QDesktopServices.openUrl("https://www.freecadweb.org/wiki/BIM_Workbench")
class BIM_Glue:
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","BIM_Glue.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_Glue", "Glue"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Glue", "Joins selected shapes into one non-parametric shape")}
def IsActive(self):
import FreeCADGui
if FreeCADGui.Selection.getSelection():
return True
else:
return False
def Activated(self):
import FreeCADGui
sel = FreeCADGui.Selection.getSelection()
if sel:
rem = []
shapes = []
for obj in sel:
if obj.isDerivedFrom("Part::Feature"):
if obj.Shape:
shapes.append(obj.Shape)
rem.append(obj.Name)
import Part
if shapes:
comp = Part.makeCompound(shapes)
FreeCAD.ActiveDocument.openTransaction("Glue")
Part.show(comp)
for name in rem:
FreeCAD.ActiveDocument.removeObject(name)
FreeCAD.ActiveDocument.commitTransaction()
class BIM_Sketch:
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","Sketch.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_Sketch", "Sketch"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Sketch", "Creates a new sketch in the current working plane"),
'Accel' : 'S,K'}
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
else:
return False
def Activated(self):
import FreeCADGui
if hasattr(FreeCAD,"DraftWorkingPlane"):
FreeCAD.DraftWorkingPlane.setup()
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.setGrid()
sk = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Sketch')
sk.MapMode = "Deactivated"
p = FreeCAD.DraftWorkingPlane.getPlacement()
p.Base = FreeCAD.DraftWorkingPlane.position
sk.Placement = p
FreeCADGui.ActiveDocument.setEdit(sk.Name)
FreeCADGui.activateWorkbench('SketcherWorkbench')
class BIM_WPView:
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","BIM_WPView.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_WPView", "Working Plane View"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_WPView", "Aligns the view on the current item in BIM Views window or on the current working plane"),
'Accel' : '9'}
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
else:
return False
def Activated(self):
import FreeCADGui
done = False
try:
import BimViews
except ImportError:
pass
else:
v = BimViews.findWidget()
if v:
i = v.tree.currentItem()
if i:
# Aligning on current widget item
BimViews.show(i)
done = True
elif hasattr(v,"lastSelected"):
BimViews.show(v.lastSelected)
# Aligning on stored widget item
done = True
elif hasattr(FreeCAD,"DraftWorkingPlane"):
if hasattr(FreeCAD.DraftWorkingPlane,"lastBuildingPart"):
BimViews.show(FreeCAD.DraftWorkingPlane.lastBuildingPart)
done = True
if not done:
# Aligning on current working plane
c = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
r = FreeCAD.DraftWorkingPlane.getRotation().Rotation.Q
c.orientation.setValue(r)
class BIM_Convert:
def GetResources(self):
import Arch_rc
return {'Pixmap' : ":/icons/Arch_Component.svg",
'MenuText': QT_TRANSLATE_NOOP("BIM_Convert", "Convert to BIM"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Convert", "Converts any object to a BIM component")}
def IsActive(self):
if FreeCAD.ActiveDocument:
return True
else:
return False
def Activated(self):
import FreeCADGui
sel = FreeCADGui.Selection.getSelection()
if sel:
FreeCADGui.Control.showDialog(BIM_Convert_TaskPanel(sel))
class BIM_Convert_TaskPanel:
def __init__(self,objs):
from PySide import QtGui
self.types = ["Wall","Structure","Rebar","Window","Stairs","Roof","Panel","Frame","Space","Equipment","Component"]
self.objs = objs
self.form = QtGui.QListWidget()
import Arch_rc
for t in self.types:
ti = t+"_Tree"
tx = t
if t == "Component":
ti = t
tx = "Generic component"
i = QtGui.QListWidgetItem(QtGui.QIcon(":/icons/Arch_"+ti+".svg"),tx)
i.setToolTip(t)
self.form.addItem(i)
self.form.itemDoubleClicked.connect(self.accept)
def accept(self,idx=None):
i = self.form.currentItem()
if i:
import Arch
FreeCAD.ActiveDocument.openTransaction("Convert to BIM")
for o in self.objs:
getattr(Arch,"make"+i.toolTip())(o)
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
if idx:
from DraftGui import todo
todo.delay(FreeCADGui.Control.closeDialog,None)
return True
class BIM_Ungroup:
def GetResources(self):
import Draft_rc
return {'Pixmap' : ":/icons/Draft_AddToGroup.svg",
'MenuText': QT_TRANSLATE_NOOP("BIM_Convert", "Remove from group"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Convert", "Removes this object from its parent group")}
def Activated(self):
import FreeCADGui
sel = FreeCADGui.Selection.getSelection()
first = True
if sel:
for obj in sel:
for parent in obj.InList:
if parent.isDerivedFrom("App::DocumentObjectGroup") or parent.hasExtension("App::GroupExtension"):
if obj in parent.Group:
if first:
FreeCAD.ActiveDocument.openTransaction("Ungroup")
first = False
if hasattr(parent,"removeObject"):
parent.removeObject(obj)
else:
g = parent.Group
g.remove(obj)
parent.Group = g
if not first:
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
class BIM_Door(ArchWindow._CommandWindow):
def __init__(self):
if hasattr(ArchWindow._CommandWindow,"__init__"):
ArchWindow._CommandWindow.__init__(self)
self.doormode = True
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","BIM_Door.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_Door", "Door"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Door", "Places a door at a given location"),
'Accel': 'D,O'}
class BIM_Rewire:
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","BIM_Rewire.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_Rewire", "Rewire"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Rewire", "Recreates wires from selected objects"),
'Accel': 'R,W'}
def Activated(self):
import FreeCADGui
import Part
import DraftGeomUtils
objs = FreeCADGui.Selection.getSelection()
names = []
edges = []
for obj in objs:
if hasattr(obj,"Shape") and hasattr(obj.Shape,"Edges") and obj.Shape.Edges:
edges.extend(obj.Shape.Edges)
names.append(obj.Name)
wires = DraftGeomUtils.findWires(edges)
FreeCAD.ActiveDocument.openTransaction("Rewire")
selectlist = []
for wire in wires:
if DraftGeomUtils.hasCurves(wire):
nobj = FreeCAD.ActiveDocument.addObject("Part::Feature","Wire")
nobj.shape = wire
selectlist.append(nobj)
else:
selectlist.append(Draft.makeWire([v.Point for v in wire.OrderedVertexes]))
for name in names:
FreeCAD.ActiveDocument.removeObject(name)
FreeCAD.ActiveDocument.commitTransaction()
FreeCADGui.Selection.clearSelection()
for obj in selectlist:
FreeCADGui.Selection.addSelection(obj)
FreeCAD.ActiveDocument.recompute()