forked from yorikvanhavre/BIM_Workbench
/
BimLibrary.py
608 lines (508 loc) · 24.1 KB
/
BimLibrary.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
# -*- coding: utf-8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2018 Yorik van Havre <yorik@uncreated.net> *
#* *
#* 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 *
#* *
#***************************************************************************
from __future__ import print_function
"""The BIM library tool"""
import os,FreeCAD,FreeCADGui,sys,re
import datetime
from DraftTools import translate
import addonmanager_utilities
def QT_TRANSLATE_NOOP(ctx,txt): return txt # dummy function for the QT translator
FILTERS = ["*.fcstd","*.FCStd","*.FCSTD","*.stp","*.STP","*.step","*.STEP", "*.brp", "*.BRP", "*.brep", "*.BREP", "*.ifc", "*.IFC", "*.sat", "*.SAT"]
TEMPLIBPATH = os.path.join(FreeCAD.getUserAppDataDir(),"BIM","OfflineLibrary")
LIBRARYURL = "https://github.com/FreeCAD/FreeCAD-library/tree/master"
USE_API = True # True to use github API instead of web fetching... Way faster
REFRESH_INTERVAL = 3600 # Min seconds between allowing a new API calls (3600 = one hour)
class BIM_Library:
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","BIM_Library.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_Library", "Objects library"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_Library", "Opens the objects library")}
def Activated(self):
# setting up a min reload interval of one hour
libok = False
self.librarypath = FreeCAD.ParamGet('User parameter:Plugins/parts_library').GetString('destination','')
if self.librarypath:
if os.path.exists(self.librarypath):
libok = True
else:
# check if the library is at the standard addon location
addondir = os.path.join(FreeCAD.getUserAppDataDir(),"Mod","parts_library")
if os.path.exists(addondir):
FreeCAD.ParamGet('User parameter:Plugins/parts_library').SetString('destination',addondir)
libok = True
if libok:
FreeCADGui.Control.showDialog(BIM_Library_TaskPanel())
else:
FreeCAD.Console.PrintError(translate("BIM","The Parts Library could not be found.")+"\n")
class BIM_Library_TaskPanel:
def __init__(self):
from PySide import QtCore,QtGui
self.librarypath = FreeCAD.ParamGet('User parameter:Plugins/parts_library').GetString('destination','')
self.form = FreeCADGui.PySideUic.loadUi(os.path.join(os.path.dirname(__file__),"dialogLibrary.ui"))
self.form.setWindowIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","BIM_Library.svg")))
# setting up a flat (no directories) file model for search
self.filemodel = QtGui.QStandardItemModel()
self.filemodel.setColumnCount(1)
# setting up a directory model that shows only fcstd, step and brep
self.dirmodel = LibraryModel()
self.dirmodel.setRootPath(self.librarypath)
self.dirmodel.setNameFilters(FILTERS)
self.dirmodel.setNameFilterDisables(False)
self.form.tree.setModel(self.dirmodel)
self.form.tree.doubleClicked[QtCore.QModelIndex].connect(self.insert)
self.form.buttonInsert.clicked.connect(self.insert)
self.modelmode = 1 # 0 = File search, 1 = Dir mode
# Don't show columns for size, file type, and last modified
self.form.tree.setHeaderHidden(True)
self.form.tree.hideColumn(1)
self.form.tree.hideColumn(2)
self.form.tree.hideColumn(3)
self.form.tree.setRootIndex(self.dirmodel.index(self.librarypath))
self.form.searchBox.textChanged.connect(self.onSearch)
# setup UI
self.form.buttonBimObject.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","bimobject.png")))
self.form.buttonBimObject.clicked.connect(self.onBimObject)
self.form.buttonNBSLibrary.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","nbslibrary.png")))
self.form.buttonNBSLibrary.clicked.connect(self.onNBSLibrary)
self.form.buttonBimTool.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","bimtool.png")))
self.form.buttonBimTool.clicked.connect(self.onBimTool)
self.form.checkOnline.toggled.connect(self.onCheckOnline)
self.form.checkOnline.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("LibraryOnline",False))
self.form.checkFCStdOnly.toggled.connect(self.onCheckFCStdOnly)
self.form.checkFCStdOnly.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("LibraryFCStdOnly",False))
self.form.checkWebSearch.toggled.connect(self.onCheckWebSearch)
self.form.checkWebSearch.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("LibraryWebSearch",False))
self.form.frameOptions.hide()
self.form.buttonOptions.clicked.connect(self.onButtonOptions)
self.form.buttonOptions.setText(translate("BIM","Options")+" ▼")
def onSearch(self,text):
from PySide import QtGui
import PartGui
if text:
self.setSearchModel(text)
else:
self.setFileModel()
def setSearchModel(self,text):
self.form.tree.setModel(self.filemodel)
self.filemodel.clear()
if self.form.checkOnline.isChecked():
res = self.getOfflineLib(structured = True)
else:
res = os.walk(self.librarypath)
for dp,dn,fn in res:
for f in fn:
if text.lower() in f.lower():
if not os.path.isdir(os.path.join(dp,f)):
it = QtGui.QStandardItem(f)
it.setToolTip(os.path.join(dp,f))
self.filemodel.appendRow(it)
if f.endswith('.fcstd'):
it.setIcon(QtGui.QIcon(':icons/freecad-doc.png'))
elif f.endswith('.ifc'):
it.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","IFC.svg")))
else:
it.setIcon(QtGui.QIcon(':icons/Tree_Part.svg'))
self.modelmode = 0
def setFileModel(self):
#self.form.tree.clear()
self.form.tree.setModel(self.dirmodel)
self.dirmodel.setRootPath(self.librarypath)
self.dirmodel.setNameFilters(FILTERS)
self.dirmodel.setNameFilterDisables(False)
self.form.tree.setRootIndex(self.dirmodel.index(self.librarypath))
self.modelmode = 1
self.form.tree.setHeaderHidden(True)
self.form.tree.hideColumn(1)
self.form.tree.hideColumn(2)
self.form.tree.hideColumn(3)
def setOnlineModel(self):
def addItems(root,d,path):
for k,v in d.items():
it = QtGui.QStandardItem(k)
root.appendRow(it)
it.setToolTip(path+"/"+k)
if isinstance(v,dict):
it.setIcon(QtGui.QIcon.fromTheme("folder",QtGui.QIcon(":/icons/Group.svg")))
addItems(it,v,path+"/"+k)
it.setToolTip("")
elif k.lower().endswith('.fcstd'):
it.setIcon(QtGui.QIcon(':icons/freecad-doc.png'))
elif k.lower().endswith('.ifc'):
it.setIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","IFC.svg")))
else:
it.setIcon(QtGui.QIcon(':icons/Tree_Part.svg'))
self.form.tree.setModel(self.filemodel)
self.filemodel.clear()
d = self.getOfflineLib()
addItems(self.filemodel,d,":github")
self.modelmode = 0
def getOfflineLib(self,structured=False):
def addDir(d,root):
fn = []
dn = []
dp = []
for k,v in d.items():
if isinstance(v,dict):
fn2,dn2,dp2 = addDir(v,root+"/"+k)
fn.extend(fn2)
dn.extend(dn2)
dp.extend(dp2)
else:
fn += k
dn += root
dp += root+"/"+k
return dp,dn,fn
templibfile = os.path.join(TEMPLIBPATH,"OfflineLibrary.py")
if not os.path.exists(templibfile):
FreeCAD.Console.PrintError(translate("BIM","No structure in cache. Please refresh.")+"\n")
return {}
import sys
sys.path.append(TEMPLIBPATH)
import OfflineLibrary
d = OfflineLibrary.library
if structured:
return addDir(d,":github")
else:
return d
def urlencode(self,text):
from PySide import QtGui
print(text,type(text))
if sys.version_info.major < 3:
import urllib
return urllib.quote_plus(text)
else:
import urllib.parse
return urllib.parse.quote_plus(text)
def openUrl(self,url):
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM")
s = p.GetBool("LibraryWebSearch",False)
if s:
import WebGui
WebGui.openBrowser(url)
else:
QtGui.QDesktopServices.openUrl(url)
def onBimObject(self):
term = self.form.searchBox.text()
if term:
self.openUrl("https://www.bimobject.com/en/product?filetype=8&freetext="+self.urlencode(term))
def onNBSLibrary(self):
term = self.form.searchBox.text()
if term:
self.openUrl("https://www.nationalbimlibrary.com/en/search/?facet=Xo-P0w&searchTerm="+self.urlencode(term))
def onBimTool(self):
term = self.form.searchBox.text()
if term:
self.openUrl("https://www.bimtool.com/Catalog.aspx?criterio="+self.urlencode(term))
def needsFullSpace(self):
return True
def getStandardButtons(self):
from PySide import QtGui
return int(QtGui.QDialogButtonBox.Close)
def reject(self):
if hasattr(self,"box") and self.box:
self.box.off()
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()
def insert(self, index=None):
if not index:
index = self.form.tree.selectedIndexes()
if not index:
return
index = index[0]
if self.modelmode == 1:
path = self.dirmodel.filePath(index)
else:
path = self.filemodel.itemFromIndex(index).toolTip()
if path.startswith(":github"):
path = self.download(LIBRARYURL.replace("/tree","/raw") + "/" + path[7:])
before = FreeCAD.ActiveDocument.Objects
self.name = os.path.splitext(os.path.basename(path))[0]
if path.lower().endswith(".stp") or path.lower().endswith(".step") or path.lower().endswith(".brp") or path.lower().endswith(".brep"):
self.place(path)
elif path.lower().endswith(".fcstd"):
FreeCADGui.ActiveDocument.mergeProject(path)
from DraftGui import todo
todo.delay(self.reject,None)
elif path.lower().endswith(".ifc"):
import importIFC
importIFC.ZOOMOUT = False
importIFC.insert(path,FreeCAD.ActiveDocument.Name)
from DraftGui import todo
todo.delay(self.reject,None)
elif path.lower().endswith(".sat"):
try:
import CadExchangerIO
except ImportError:
FreeCAD.Console.PrintError(translate("BIM","Error: Unable to import SAT files - CadExchanger addon must be installed"))
else:
path = CadExchangerIO.insert(path,FreeCAD.ActiveDocument.Name,returnpath = True)
self.place(path)
FreeCADGui.Selection.clearSelection()
for o in FreeCAD.ActiveDocument.Objects:
if not o in before:
FreeCADGui.Selection.addSelection(o)
FreeCADGui.SendMsgToActiveView("ViewSelection")
def download(self,url):
filepath = os.path.join(TEMPLIBPATH,url.split("/")[-1])
url = url.replace(" ","%20")
if not os.path.exists(filepath):
from PySide import QtCore,QtGui
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
u = addonmanager_utilities.urlopen(url)
if not u:
FreeCAD.Console.PrintError(translate("BIM", "Error: Unable to download")+ " "+url+"\n")
b = u.read()
f = open(filepath,"wb")
f.write(b)
f.close()
QtGui.QApplication.restoreOverrideCursor()
return filepath
def place(self,path):
import Part
self.shape = Part.read(path)
if hasattr(FreeCADGui,"Snapper"):
try:
import DraftTrackers
except Exception:
import draftguitools.gui_trackers as DraftTrackers
self.box = DraftTrackers.ghostTracker(self.shape,dotted=True,scolor=(0.0,0.0,1.0),swidth=1.0)
self.delta = self.shape.BoundBox.Center
self.box.move(self.delta)
self.box.on()
if hasattr(FreeCAD,"DraftWorkingPlane"):
FreeCAD.DraftWorkingPlane.setup()
self.origin = self.makeOriginWidget()
FreeCADGui.Snapper.getPoint(movecallback=self.mouseMove,callback=self.mouseClick,extradlg=self.origin)
else:
Part.show(self.shape)
def makeOriginWidget(self):
from PySide import QtGui
w = QtGui.QWidget()
w.setWindowTitle(translate("BIM","Insertion point"))
w.setWindowIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","BIM_Library.svg")))
l = QtGui.QVBoxLayout()
w.setLayout(l)
c = QtGui.QComboBox()
c.ObjectName = "comboOrigin"
w.comboOrigin = c
c.addItems([translate("BIM","Origin"),translate("BIM","Top left"),translate("BIM","Top center"),
translate("BIM","Top right"),translate("BIM","Middle left"),translate("BIM","Middle center"),
translate("BIM","Middle right"),translate("BIM","Bottom left"),translate("BIM","Bottom center"),
translate("BIM","Bottom right")])
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetInt("LibraryDefaultInsert",0)
c.setCurrentIndex(p)
c.currentIndexChanged.connect(self.storeInsert)
l.addWidget(c)
return w
def storeInsert(self,index):
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").SetInt("LibraryDefaultInsert",index)
def mouseMove(self,point,info):
self.box.move(point.add(self.getDelta()))
def mouseClick(self,point,info):
if point:
import Arch,Part
self.box.off()
self.shape.translate(point.add(self.getDelta()))
obj = Arch.makeEquipment()
obj.Shape = self.shape
obj.Label = self.name
self.reject()
def getDelta(self):
d = FreeCAD.Vector(-self.shape.BoundBox.Center.x,-self.shape.BoundBox.Center.y,0)
idx = self.origin.comboOrigin.currentIndex()
if idx <= 0:
return FreeCAD.Vector()
elif idx == 1:
return d.add(FreeCAD.Vector(self.shape.BoundBox.XLength/2,-self.shape.BoundBox.YLength/2,0))
elif idx == 2:
return d.add(FreeCAD.Vector(0,-self.shape.BoundBox.YLength/2,0))
elif idx == 3:
return d.add(FreeCAD.Vector(-self.shape.BoundBox.XLength/2,-self.shape.BoundBox.YLength/2,0))
elif idx == 4:
return d.add(FreeCAD.Vector(self.shape.BoundBox.XLength/2,0,0))
elif idx == 5:
return d
elif idx == 6:
return d.add(FreeCAD.Vector(-self.shape.BoundBox.XLength/2,0,0))
elif idx == 7:
return d.add(FreeCAD.Vector(self.shape.BoundBox.XLength/2,self.shape.BoundBox.YLength/2,0))
elif idx == 8:
return d.add(FreeCAD.Vector(0,self.shape.BoundBox.YLength/2,0))
elif idx == 9:
return d.add(FreeCAD.Vector(-self.shape.BoundBox.XLength/2,self.shape.BoundBox.YLength/2,0))
def getOnlineContentsWEB(self,url):
"""Returns a dirs,files pair representing files found from a github url. OBSOLETE"""
# obsolete code - now using getOnlineContentsAPI
result = {}
u = addonmanager_utilities.urlopen(url)
if u:
p = u.read()
if sys.version_info.major >= 3:
p = str(p)
dirs = re.findall("<.*?octicon-file-directory.*?href.*?>(.*?)</a>",p)
files = re.findall("<.*?octicon-file\".*?href.*?>(.*?)</a>",p)
nfiles = []
for f in files:
for ft in FILTERS:
if f.endswith(ft[1:]):
nfiles.append(f)
break
files = nfiles
for d in dirs:
# <spans>
if "</span" in d:
d1 = re.findall("<span.*?>(.*?)<",d)
d2 = re.findall("</span>(.*?)$",d)
if d1 and d2:
d = d1[0] + "/" + d2[0]
r = self.getOnlineContentsWEB(url+"/"+d.replace(" ","%20"))
result[d] = r
for f in files:
result[f] = f
else:
FreeCAD.Console.PrintError(translate("BIM","Cannot open URL")+":"+url+"\n")
return result
def getOnlineContentsAPI(self,url):
"""same as getOnlineContents but uses github API (faster)"""
result = {}
import requests
import json
count = 0
r = requests.get('https://api.github.com/repos/FreeCAD/FreeCAD-library/git/trees/master?recursive=1')
if r.ok:
j = json.loads(r.content)
if j['truncated']:
print("WARNING: The fetched content exceeds maximum Github allowance and is truncated")
t = j['tree']
for f in t:
path = f['path'].split("/")
if f['type'] == 'tree':
name = None
else:
name = path[-1]
path = path[:-1]
host = result
for fp in path:
if fp in host:
host = host[fp]
else:
host[fp] = {}
host = host[fp]
if name:
for ft in FILTERS:
if name.endswith(ft[1:]):
break
else:
continue
host[name] = name
count += 1
else:
FreeCAD.Console.PrintError(translate("BIM","Could not fetch library contents")+"\n")
#print("result:",result)
if not result:
FreeCAD.Console.PrintError(translate("BIM","No results fetched from online library")+"\n")
else:
FreeCAD.Console.PrintLog("BIM Library: Reloaded "+str(count)+" files")
return result
def onCheckOnline(self,state):
"""if the Online checkbox is clicked"""
# save state
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM")
p.SetBool("LibraryOnline",state)
if state:
# online
if USE_API:
timestamp = datetime.datetime.now()
stored = p.GetUnsigned("LibraryTimeStamp",0)
if stored:
stored = datetime.datetime.fromordinal(stored)
if(timestamp - stored).total_seconds() > REFRESH_INTERVAL:
p.SetUnsigned("LibraryTimeStamp",timestamp.toordinal())
self.onRefresh()
else:
FreeCAD.Console.PrintLog("BIM Library: Using cached library\n")
else:
FreeCAD.Console.PrintLog("BIM Library: Using cached library\n")
self.setOnlineModel()
else:
# offline
self.setFileModel()
def onRefresh(self):
"""refreshes the tree"""
def writeOfflineLib():
if USE_API:
rootfiles = self.getOnlineContentsAPI(LIBRARYURL)
else:
rootfiles = self.getOnlineContentsWEB(LIBRARYURL)
if rootfiles:
templibfile = os.path.join(TEMPLIBPATH,"OfflineLibrary.py")
tf = open(templibfile,"w")
tf.write("library="+str(rootfiles))
tf.close()
from PySide import QtCore,QtGui
reply = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").GetBool("LibraryWarning",False)
if not reply:
reply = QtGui.QMessageBox.information(None,"",translate("BIM","Warning, this can take several minutes!"))
if reply:
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM").SetBool("LibraryWarning",True)
self.form.setEnabled(False)
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.form.repaint()
QtGui.QApplication.processEvents()
QtCore.QTimer.singleShot(1,writeOfflineLib)
self.form.setEnabled(True)
QtGui.QApplication.restoreOverrideCursor()
self.setOnlineModel()
def onCheckFCStdOnly(self,state):
"""if the FCStd only checkbox is clicked"""
# save state
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM")
p.SetBool("LibraryFCStdOnly",state)
def onCheckWebSearch(self,state):
"""if the web search checkbox is clicked"""
# save state
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/BIM")
p.SetBool("LibraryWebSearch",state)
def onButtonOptions(self):
"""hides/shows the options"""
if self.form.frameOptions.isVisible():
self.form.frameOptions.hide()
self.form.buttonOptions.setText(translate("BIM","Options")+" ▼")
else:
self.form.frameOptions.show()
self.form.buttonOptions.setText(translate("BIM","Options")+" ▲")
if FreeCAD.GuiUp:
from PySide import QtCore,QtGui
class LibraryModel(QtGui.QFileSystemModel):
"a custom QFileSystemModel that displays freecad file icons"
def __init__(self):
QtGui.QFileSystemModel.__init__(self)
def data(self, index, role):
if index.column() == 0 and role == QtCore.Qt.DecorationRole:
if index.data().lower().endswith('.fcstd'):
return QtGui.QIcon(':icons/freecad-doc.png')
elif index.data().lower().endswith('.ifc'):
return QtGui.QIcon(os.path.join(os.path.dirname(__file__),"icons","IFC.svg"))
elif index.data().lower() == "private":
return QtGui.QIcon.fromTheme("folder-lock")
return super(LibraryModel, self).data(index, role)