-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
BimPreflight.py
1190 lines (1094 loc) · 46.1 KB
/
BimPreflight.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
# ***************************************************************************
# * *
# * 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 importlib
import inspect
tests = [
"testAll",
"testIFC4",
"testHierarchy",
"testSites",
"testBuildings",
"testStoreys",
"testUndefined",
"testSolid",
"testQuantities",
"testCommonPsets",
"testPsets",
"testMaterials",
"testStandards",
"testExtrusions",
"testStandardCases",
"testTinyLines",
"testRectangleProfileDef",
]
class BIM_Preflight:
def GetResources(self):
return {
"Pixmap": os.path.join(
os.path.dirname(__file__), "icons", "BIM_Preflight.svg"
),
"MenuText": QT_TRANSLATE_NOOP("BIM_Preflight", "Preflight checks..."),
"ToolTip": QT_TRANSLATE_NOOP(
"BIM_Preflight",
"Checks several characteristics of this model before exporting to IFC",
),
}
def Activated(self):
import FreeCADGui
FreeCADGui.BIMPreflightDone = False
FreeCADGui.Control.showDialog(BIM_Preflight_TaskPanel())
class BIM_Preflight_TaskPanel:
def __init__(self):
import sys
import FreeCADGui
from PySide import QtCore, QtGui
self.results = {} # to store the result message
self.culprits = {} # to store objects to highlight
self.rform = None # to store the results dialog
self.form = FreeCADGui.PySideUic.loadUi(
os.path.join(os.path.dirname(__file__), "dialogPreflight.ui")
)
self.form.setWindowIcon(
QtGui.QIcon(
os.path.join(os.path.dirname(__file__), "icons", "BIM_Preflight.svg")
)
)
for test in tests:
getattr(self.form, test).setIcon(QtGui.QIcon(":/icons/button_right.svg"))
getattr(self.form, test).setToolTip(
translate("BIM", "Press to perform the test")
)
if hasattr(self, test):
getattr(self.form, test).clicked.connect(getattr(self, test))
self.results[test] = None
self.culprits[test] = None
# setup custom tests
self.customTests = {}
customModulePath = os.path.join(FreeCAD.getUserAppDataDir(), "BIM", "Preflight")
if os.path.exists(customModulePath):
customModules = [
m[:-3] for m in os.listdir(customModulePath) if m.endswith(".py")
]
if customModules:
sys.path.append(customModulePath)
for customModule in customModules:
mod = importlib.import_module(customModule)
if not "Preflight" in mod.__file__:
# prevent from using other modules with same name
FreeCAD.Console.PrintLog(
"Preflight: loaded wrong module - skipping: "
+ customModule
+ " "
+ str(mod)
+ "\n"
)
continue
FreeCAD.Console.PrintLog(
"Preflight: found custom module: "
+ customModule
+ " "
+ str(mod)
+ "\n"
)
functions = [
o[0]
for o in inspect.getmembers(mod)
if inspect.isfunction(o[1])
]
if functions:
box = QtGui.QGroupBox(customModule)
lay = QtGui.QGridLayout(box)
self.form.layout().addWidget(box)
for funcname in functions:
FreeCAD.Console.PrintLog(
"Preflight: found custom test: " + funcname + "\n"
)
func = getattr(mod, funcname)
descr = func.__doc__
if not descr:
descr = "Undefined"
lab = QtGui.QLabel(descr)
lab.setWordWrap(True)
but = QtGui.QPushButton()
butname = "Custom_" + customModule + "_" + funcname
but.setObjectName(butname)
setattr(self.form, butname, but)
self.reset(butname)
row = lay.rowCount()
lay.addWidget(lab, row, 0)
lay.addWidget(but, row, 1)
but.clicked.connect(lambda: self.testCustom(butname))
self.customTests[butname] = func
def getStandardButtons(self):
from PySide import QtCore, QtGui
return int(QtGui.QDialogButtonBox.Close)
def reject(self):
import FreeCADGui
from PySide import QtCore, QtGui
QtGui.QApplication.restoreOverrideCursor()
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()
def passed(self, test):
"sets the button as passed"
from PySide import QtCore, QtGui
getattr(self.form, test).setIcon(QtGui.QIcon(":/icons/button_valid.svg"))
getattr(self.form, test).setText(translate("BIM", "Passed"))
getattr(self.form, test).setToolTip(
translate("BIM", "This test has succeeded.")
)
def failed(self, test):
"sets the button as failed"
from PySide import QtCore, QtGui
getattr(self.form, test).setIcon(QtGui.QIcon(":/icons/process-stop.svg"))
getattr(self.form, test).setText("Failed")
getattr(self.form, test).setToolTip(
translate("BIM", "This test has failed. Press the button to know more")
)
def reset(self, test):
"reset the button"
from PySide import QtCore, QtGui
getattr(self.form, test).setIcon(QtGui.QIcon(":/icons/button_right.svg"))
getattr(self.form, test).setText(translate("BIM", "Test"))
getattr(self.form, test).setToolTip(
translate("BIM", "Press to perform the test")
)
def show(self, test):
"shows test results"
import FreeCADGui
if (test in self.results) and self.results[test]:
if (test in self.culprits) and self.culprits[test]:
FreeCADGui.Selection.clearSelection()
for c in self.culprits[test]:
FreeCADGui.Selection.addSelection(c)
if not self.rform:
self.rform = FreeCADGui.PySideUic.loadUi(
os.path.join(os.path.dirname(__file__), "dialogPreflightResults.ui")
)
# center the dialog over FreeCAD window
mw = FreeCADGui.getMainWindow()
self.rform.move(
mw.frameGeometry().topLeft()
+ mw.rect().center()
- self.rform.rect().center()
)
self.rform.buttonReport.clicked.connect(self.toReport)
self.rform.buttonOK.clicked.connect(self.closeReport)
self.rform.textBrowser.setText(self.results[test])
label = test.replace("test", "label")
self.rform.label.setText(getattr(self.form, label).text())
self.rform.test = test
self.rform.show()
def toReport(self):
"copies the resulting text to the report view"
if self.rform and hasattr(self.rform, "test") and self.rform.test:
if self.results[self.rform.test]:
FreeCAD.Console.PrintMessage(self.results[self.rform.test] + "\n")
def closeReport(self):
if self.rform:
self.rform.test = None
self.rform.hide()
def getObjects(self):
"selects target objects"
import FreeCADGui
import Draft
import Arch
objs = []
if self.form.getAll.isChecked():
objs = FreeCAD.ActiveDocument.Objects
elif self.form.getVisible.isChecked():
objs = [
o
for o in FreeCAD.ActiveDocument.Objects
if o.ViewObject.Visibility == True
]
else:
objs = FreeCADGui.Selection.getSelection()
# clean objects list of unwanted types
objs = Draft.get_group_contents(objs, walls=True, addgroups=True)
objs = [obj for obj in objs if not obj.isDerivedFrom("Part::Part2DObject")]
objs = [obj for obj in objs if not obj.isDerivedFrom("App::Annotation")]
objs = [
obj
for obj in objs
if (
hasattr(obj, "Shape")
and obj.Shape
and not (obj.Shape.Edges and (not obj.Shape.Faces))
)
]
objs = Arch.pruneIncluded(objs)
objs = [
obj for obj in objs if not obj.isDerivedFrom("App::DocumentObjectGroup")
]
objs = [
obj
for obj in objs
if Draft.getType(obj)
not in ["DraftText", "Material", "MaterialContainer", "WorkingPlaneProxy"]
]
return objs
def getToolTip(self, test):
"gets the toolTip text from the ui file"
import re
label = test.replace("test", "label")
tooltip = getattr(self.form, label).toolTip()
tooltip = tooltip.replace("</p>", "</p>\n\n")
tooltip = re.sub("<.*?>", "", tooltip) # strip html tags
return tooltip
def testAll(self):
"runs all tests"
import FreeCADGui
from PySide import QtCore, QtGui
from DraftGui import todo
for test in tests:
if test != "testAll":
QtGui.QApplication.processEvents()
self.reset(test)
if hasattr(self, test):
todo.delay(getattr(self, test), None)
for customTest in self.customTests.keys():
todo.delay(self.testCustom, customTest)
FreeCADGui.BIMPreflightDone = True
def testIFC4(self):
"tests for IFC4 support"
test = "testIFC4"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
self.reset(test)
self.results[test] = None
self.culprits[test] = None
msg = None
try:
import ifcopenshell
except ImportError:
msg = (
translate(
"BIM",
"ifcopenshell is not installed on your system or not available to FreeCAD. This library is responsible for IFC support in FreeCAD, and therefore IFC support is currently disabled. Check https://www.freecadweb.org/wiki/Extra_python_modules#IfcOpenShell to obtain more information.",
)
+ " "
)
self.failed(test)
else:
if hasattr(
ifcopenshell, "schema_identifier"
) and ifcopenshell.schema_identifier.startswith("IFC4"):
self.passed(test)
elif hasattr(ifcopenshell, "version"):
try:
from packaging import version
if "-" in ifcopenshell.version:
# Prebuild version have a version like 'v0.7.0-<GIT_COMMIT_ID>,
# trying to remove the commit id.
cur_version = version.parse(ifcopenshell.version.split('-')[0])
else:
cur_version = version.parse(ifcopenshell.version)
min_version = version.parse("0.6")
if cur_version >= min_version:
self.passed(test)
else:
msg = self.getToolTip(test)
msg = (
translate(
"BIM",
"The version of ifcopenshell installed on your system could not be parsed",
)
+ " "
)
self.failed(test)
except Exception as e:
self.failed(test)
else:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
"The version of ifcopenshell installed on your system will produce files with this schema version:",
)
+ "\n\n"
)
if hasattr(ifcopenshell, "schema_identifier"):
msg += ifcopenshell.schema_identifier + "\n\n"
else:
msg += "Unable to retrieve schemas information from ifcopenshell\n\n"
self.failed(test)
self.results[test] = msg
def testHierarchy(self):
"tests for project hierarchy support"
import FreeCADGui
import Draft
from PySide import QtCore, QtGui
test = "testHierarchy"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
sites = False
buildings = False
storeys = False
for obj in self.getObjects():
if (
(Draft.getType(obj) == "Site")
or (hasattr(obj, "IfcRole") and (obj.IfcRole == "Site"))
or (hasattr(obj, "IfcType") and (obj.IfcType == "Site"))
):
sites = True
elif (
(Draft.getType(obj) == "Building")
or (hasattr(obj, "IfcRole") and (obj.IfcRole == "Building"))
or (hasattr(obj, "IfcType") and (obj.IfcType == "Building"))
):
buildings = True
elif (
hasattr(obj, "IfcRole") and (obj.IfcRole == "Building Storey")
) or (hasattr(obj, "IfcType") and (obj.IfcType == "Building Storey")):
storeys = True
if (not sites) or (not buildings) or (not storeys):
msg = self.getToolTip(test)
msg += (
translate(
"BIM", "The following types were not found in the project:"
)
+ "\n"
)
if not sites:
msg += "\nSite"
if not buildings:
msg += "\nBuilding"
if not storeys:
msg += "\nBuilding Storey"
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testSites(self):
"tests for Sites support"
import FreeCADGui
import Draft
from PySide import QtCore, QtGui
test = "testSites"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
for obj in self.getObjects():
if (
(Draft.getType(obj) == "Building")
or (hasattr(obj, "IfcRole") and (obj.IfcRole == "Building"))
or (hasattr(obj, "IfcType") and (obj.IfcType == "Building"))
):
ok = False
for parent in obj.InList:
if (
(Draft.getType(parent) == "Site")
or (
hasattr(parent, "IfcRole")
and (parent.IfcRole == "Site")
)
or (
hasattr(parent, "IfcType")
and (parent.IfcType == "Site")
)
):
if hasattr(parent, "Group") and parent.Group:
if obj in parent.Group:
ok = True
break
if not ok:
self.culprits[test].append(obj)
if not msg:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
"The following Building objects have been found to not be included in any Site. You can resolve the situation by creating a Site object, if none is present in your model, and drag and drop the Building objects into it in the tree view:",
)
+ "\n\n"
)
msg += obj.Label + "\n"
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testBuildings(self):
"tests for Buildings support"
from PySide import QtCore, QtGui
test = "testBuildings"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
for obj in self.getObjects():
if (hasattr(obj, "IfcRole") and (obj.IfcRole == "Building Storey")) or (
hasattr(obj, "IfcType") and (obj.IfcType == "Building Storey")
):
ok = False
for parent in obj.InList:
if (
hasattr(parent, "IfcRole")
and (parent.IfcRole == "Building")
) or (
hasattr(parent, "IfcType")
and (parent.IfcType == "Building")
):
if hasattr(parent, "Group") and parent.Group:
if obj in parent.Group:
ok = True
break
if not ok:
self.culprits[test].append(obj)
if not msg:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
'The following Building Storey (BuildingParts with their IFC role set as "Building Storey") objects have been found to not be included in any Building. You can resolve the situation by creating a Building object, if none is present in your model, and drag and drop the Building Storey objects into it in the tree view:',
)
+ "\n\n"
)
msg += obj.Label + "\n"
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testStoreys(self):
"tests for Building Storey support"
from PySide import QtCore, QtGui
test = "testStoreys"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
for obj in self.getObjects():
if (
hasattr(obj, "IfcRole")
and (not obj.IfcRole in ["Building", "Building Storey", "Site"])
) or (
hasattr(obj, "IfcType")
and (not obj.IfcType in ["Building", "Building Storey", "Site"])
):
ok = False
ancestors = obj.InListRecursive
# append extra objects not in InList
if hasattr(obj,"Host") and not obj.Host in ancestors:
ancestors.append(obj.Host)
if hasattr(obj,"Hosts"):
for h in obj.Hosts:
if not h in ancestors:
ancestors.append(h)
for parent in ancestors:
# just check if any of the ancestors is a Building Storey for now. Don't check any further...
if (
hasattr(parent, "IfcRole")
and (parent.IfcRole in ["Building Storey", "Building"])
) or (
hasattr(parent, "IfcType")
and (parent.IfcType in ["Building Storey", "Building"])
):
ok = True
break
if not ok:
self.culprits[test].append(obj)
if not msg:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
'The following BIM objects have been found to not be included in any Building Storey (BuildingParts with their IFC role set as "Building Storey"). You can resolve the situation by creating a Building Storey object, if none is present in your model, and drag and drop these objects into it in the tree view:',
)
+ "\n\n"
)
msg += obj.Label + "\n"
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testUndefined(self):
"tests for undefined BIM objects"
from PySide import QtCore, QtGui
test = "testUndefined"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
undefined = []
notbim = []
msg = None
for obj in self.getObjects():
if hasattr(obj, "IfcType"):
if obj.IfcType == "Undefined":
self.culprits[test].append(obj)
undefined.append(obj)
elif hasattr(obj, "IfcRole"):
if obj.IfcRole == "Undefined":
self.culprits[test].append(obj)
undefined.append(obj)
else:
self.culprits[test].append(obj)
notbim.append(obj)
if undefined or notbim:
msg = self.getToolTip(test)
if undefined:
msg += (
translate(
"BIM",
'The following BIM objects have the "Undefined" type:',
)
+ "\n\n"
)
for o in undefined:
msg += o.Label + "\n"
if notbim:
msg += (
translate("BIM", "The following objects are not BIM objects:")
+ "\n\n"
)
for o in notbim:
msg += o.Label + "\n"
msg += translate(
"BIM",
"You can turn these objects into BIM objects by using the Utils -> Make Component tool.",
)
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testSolid(self):
"tests for invalid/non-solid BIM objects"
from PySide import QtCore, QtGui
test = "testSolid"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
for obj in self.getObjects():
if obj.isDerivedFrom("Part::Feature"):
if (not obj.Shape.isNull()) and (
(not obj.Shape.isValid()) or (not obj.Shape.Solids)
):
self.culprits[test].append(obj)
if self.culprits[test]:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
"The following BIM objects have an invalid or non-solid geometry:",
)
+ "\n\n"
)
for o in self.culprits[test]:
msg += o.Label + "\n"
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testQuantities(self):
"tests for explicit quantities export"
from PySide import QtCore, QtGui
test = "testQuantities"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
for obj in self.getObjects():
if hasattr(obj, "IfcAttributes") and (
Draft.getType(obj) != "BuildingPart"
):
for prop in ["Length", "Width", "Height"]:
if prop in obj.PropertiesList:
if (not "Export" + prop in obj.IfcAttributes) or (
obj.IfcAttributes["Export" + prop] == "False"
):
self.culprits[test].append(obj)
break
if self.culprits[test]:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
"The objects below have Length, Width or Height properties, but these properties won't be explicitly exported to IFC. This is not necessarily an issue, unless you specifically want these quantities to be exported:",
)
+ "\n\n"
)
for o in self.culprits[test]:
msg += o.Label + "\n"
msg += "\n" + translate(
"BIM",
"To enable exporting of these quantities, use the IFC quantities manager tool located under menu Manage -> Manage IFC Quantities...",
)
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testCommonPsets(self):
"tests for common property sets"
from PySide import QtCore, QtGui
import csv
test = "testCommonPsets"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
psets = []
psetspath = os.path.join(
FreeCAD.getResourceDir(),
"Mod",
"Arch",
"Presets",
"pset_definitions.csv",
)
if os.path.exists(psetspath):
with open(psetspath, "r") as csvfile:
reader = csv.reader(csvfile, delimiter=";")
for row in reader:
if "Common" in row[0]:
psets.append(row[0][5:-6])
psets = [
"".join(map(lambda x: x if x.islower() else " " + x, p)) for p in psets
]
psets = [pset.strip() for pset in psets]
# print(psets)
for obj in self.getObjects():
ok = True
if hasattr(obj, "IfcProperties") and isinstance(
obj.IfcProperties, dict
):
r = None
if hasattr(obj, "IfcType"):
r = obj.IfcType
if hasattr(obj, "IfcRole"):
r = obj.IfcRole
if r and (r in psets):
ok = False
if "Pset_" + r.replace(" ", "") + "Common" in ",".join(
obj.IfcProperties.values()
):
ok = True
if not ok:
self.culprits[test].append(obj)
if self.culprits[test]:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
"The objects below have a defined IFC type but do not have the associated common property set:",
)
+ "\n\n"
)
for o in self.culprits[test]:
msg += o.Label + "\n"
msg += "\n" + translate(
"BIM",
"To add common property sets to these objects, use the IFC properties manager tool located under menu Manage -> Manage IFC Properties...",
)
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testPsets(self):
"tests for property sets integrity"
from PySide import QtCore, QtGui
import csv
test = "testPsets"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
psets = {}
psetspath = os.path.join(
FreeCAD.getResourceDir(),
"Mod",
"Arch",
"Presets",
"pset_definitions.csv",
)
if os.path.exists(psetspath):
with open(psetspath, "r") as csvfile:
reader = csv.reader(csvfile, delimiter=";")
for row in reader:
if "Common" in row[0]:
psets[row[0]] = row[1:]
for obj in self.getObjects():
ok = True
if hasattr(obj, "IfcProperties") and isinstance(
obj.IfcProperties, dict
):
r = None
if hasattr(obj, "IfcType"):
r = obj.IfcType
elif hasattr(obj, "IfcRole"):
r = obj.IfcRole
if r and (r != "Undefined"):
found = None
for pset in psets.keys():
for val in obj.IfcProperties.values():
if pset in val:
found = pset
break
if found:
for i in range(int(len(psets[found]) / 2)):
p = psets[found][i * 2]
t = psets[found][i * 2 + 1]
# print("testing for ",p,t,found," in ",obj.IfcProperties)
if p in obj.IfcProperties:
if (not found in obj.IfcProperties[p]) or (
not t in obj.IfcProperties[p]
):
ok = False
else:
ok = False
if not ok:
self.culprits[test].append(obj)
if self.culprits[test]:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
"The objects below have a common property set but that property set doesn't contain all the needed properties:",
)
+ "\n\n"
)
for o in self.culprits[test]:
msg += o.Label + "\n"
msg += (
"\n"
+ translate(
"BIM",
"Verify which properties a certain property set must contain on http://www.buildingsmart-tech.org/ifc/IFC4/Add2/html/annex/annex-b/alphabeticalorder_psets.htm",
)
+ "\n\n"
)
msg += translate(
"BIM",
"To fix the property sets of these objects, use the IFC properties manager tool located under menu Manage -> Manage IFC Properties...",
)
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testMaterials(self):
"tests for materials in BIM objects"
from PySide import QtCore, QtGui
test = "testMaterials"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
for obj in self.getObjects():
if "Material" in obj.PropertiesList:
if not obj.Material:
self.culprits[test].append(obj)
if self.culprits[test]:
msg = self.getToolTip(test)
msg += (
translate(
"BIM", "The following BIM objects have no material attributed:"
)
+ "\n\n"
)
for o in self.culprits[test]:
msg += o.Label + "\n"
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testStandards(self):
"tests for standards in BIM objects"
from PySide import QtCore, QtGui
test = "testStandards"
if getattr(self.form, test).text() == "Failed":
self.show(test)
else:
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.reset(test)
self.results[test] = None
self.culprits[test] = []
msg = None
for obj in self.getObjects():
if "StandardCode" in obj.PropertiesList:
if not obj.StandardCode:
self.culprits[test].append(obj)
if "Material" in obj.PropertiesList:
if obj.Material:
if "StandardCode" in obj.Material.PropertiesList:
if not obj.Material.StandardCode:
self.culprits[test].append(obj.Material)
if self.culprits[test]:
msg = self.getToolTip(test)
msg += (
translate(
"BIM",
"The following BIM objects have no defined standard code:",
)
+ "\n\n"
)
for o in self.culprits[test]:
msg += o.Label + "\n"
if msg:
self.failed(test)
else:
self.passed(test)
self.results[test] = msg
QtGui.QApplication.restoreOverrideCursor()
def testExtrusions(self):