-
-
Notifications
You must be signed in to change notification settings - Fork 686
/
test_ids.py
1342 lines (1185 loc) · 68.1 KB
/
test_ids.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
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Thomas Krijnen <thomas@aecgeeks.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import os
import re
import pytest
import logging
import unittest
import tempfile
import xmlschema
import functools
import itertools
import ifcopenshell
import ifcopenshell.api
from bcf import bcfxml
from dataclasses import dataclass
from ifcopenshell import ids, template, validate
from xml.dom.minidom import parseString
IFC_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IFC/", "IFC4_Wall_3_with_properties.ifc")
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_all_fields.xml")
logger = logging.getLogger("IDS_Logger")
# logging.basicConfig(level=logging.INFO, format="%(message)s")
# logging.basicConfig(filename=os.path.join(os.path.dirname(__file__), "log.txt"), level=logging.INFO, format="%(message)s")
file = open(os.path.join(tempfile.gettempdir(), "test.ifc"), "w")
file.write(IFC_URL)
file.close()
ifc_file = ifcopenshell.open(IFC_URL)
os.remove(os.path.join(tempfile.gettempdir(), "test.ifc"))
class TestIdsParsing(unittest.TestCase):
def test_parse_basic_ids(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_all_fields.xml")
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(type(ids_file).__name__, "ids")
def test_parse_entity_facet(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_entity.xml")
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "IfcWall")
def test_parse_predefinedType_facet(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_predefinedtype.xml")
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(
ids_file.specifications[0].requirements.terms[0].node["predefinedType"]["simpleValue"], "CLADDING"
)
def test_parse_property_facet(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property.xml")
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(
ids_file.specifications[0].requirements.terms[0].node["propertySet"]["simpleValue"], "Test_PropertySet"
)
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["value"]["simpleValue"], "Test_Value")
def test_parse_material_facet(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_material.xml")
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["value"]["simpleValue"], "Test_Material")
def test_parse_classification_facet(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_classification.xml")
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(
ids_file.specifications[0].requirements.terms[0].node["value"]["simpleValue"], "Test_Classification"
)
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["system"]["simpleValue"], "Test_System")
def test_failing_on_opening_invalid_ids_data(self):
with pytest.raises(xmlschema.validators.exceptions.XMLSchemaValidationError):
ids.ids.open("""<?xml version="1.0" encoding="UTF-8"?><clearly_not_an_ids/>""")
""" Saving parsed IDS to IDS.xml """
def test_parsed_ids_to_xml(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files", "IDS", "IDS_Wall_needs_all_fields.xml")
ids_file = ids.ids.open(IDS_URL)
fn = "output.xml"
result = ids_file.to_xml(fn)
assert os.path.isfile(fn)
os.remove(fn)
self.assertTrue(result)
def test_parsed_ids_to_string(self):
return # TODO
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files", "IDS", "IDS_Wall_needs_all_fields.xml")
ids_file = ids.ids.open(IDS_URL)
output = ids_file.to_string()
assert output and "http://standards.buildingsmart.org/IDS" in output
""" Parsing IDS files with restrictions """
def test_parse_restrictions_enumeration(self):
return # TODO
IDS_URL = os.path.join(
os.path.dirname(__file__),
"Sample-BIM-Files/IDS/",
"IDS_Wall_needs_property_with_restriction_enumeration.xml",
)
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
self.assertEqual(
[
x["@value"]
for x in ids_file.specifications[0].requirements.terms[0].node["value"]["restriction"][0]["enumeration"]
],
["testA", "testB"],
)
def test_parse_restrictions_bounds(self):
return # TODO
IDS_URL = os.path.join(
os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_bounds.xml"
)
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
self.assertEqual(
ids_file.specifications[0].requirements.terms[0].node["value"]["restriction"][0]["minInclusive"]["@value"],
"0",
)
def test_parse_restrictions_pattern_simple(self):
return # TODO
IDS_URL = os.path.join(
os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_pattern.xml"
)
ids_file = ids.ids.open(IDS_URL)
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
self.assertEqual(
ids_file.specifications[0].requirements.terms[0].node["value"]["restriction"][0]["pattern"]["@value"],
"[A-Z]{2,4}",
)
@dataclass
class doc_test_case:
name: str
ids_content: str
ids_filename: str
ifc_content: str
ifc_filename: str
expected_result: str
class spec_generator:
cases = []
def __call__(self, name, *, facet, inst, expected):
if not name:
return
fail_or_pass = "pass" if expected is True else "fail"
# Create an IFC file with the instance in `inst` passed to us
# based on an IFC file template with project and units.
f = template.create()
instances = [f.add(inst)]
for nm in inst.wrapped_data.get_inverse_attribute_names():
for v in getattr(inst, nm):
instances.append(f.add(v))
# Validate the file created and loop over the issues, fixing them
# one by one.
l = validate.json_logger()
validate.validate(f, l)
for issue in l.statements:
if "GlobalId" in issue["message"]:
issue["instance"].GlobalId = ifcopenshell.guid.new()
elif "PredefinedType" in issue["message"]:
ty = re.findall("\\(.+?\\)", issue["message"])[0][1:-1].split(", ")[0]
issue["instance"].PredefinedType = ty
elif "IfcMaterialList" in issue["message"]:
issue["instance"].Materials = [f.createIfcMaterial("Concrete", None, "CONCRETE")]
else:
raise Exception("About to emit invalid example data")
ifc_text = "\n".join(
map(str, {inst: None for inst in itertools.chain.from_iterable(map(f.traverse, instances))}.keys())
)
basename = f"{fail_or_pass}_{name.lower().replace(' ', '_')}"
# Write IFC to disk
f.write(f"{basename}.ifc")
# Create an IDS with the applicability selecting exactly
# the entity type passed to us in `inst`.
specs = ids.ids(title=name)
spec = ids.specification(name=name)
spec.add_applicability(ids.entity.create(name=inst.is_a()))
spec.add_requirement(facet)
specs.specifications.append(spec)
# Write IDS to disk
with open(f"{basename}.ids", "w", encoding="utf-8") as ids_file:
ids_file.write(specs.to_string())
xml_text = "\n".join(
l
for l in parseString(specs.to_string())
.getElementsByTagName("requirements")[0]
.childNodes[1]
.toprettyxml()
.split("\n")
if l.strip()
).replace("\t", " ")
self.cases.append(doc_test_case(name, xml_text, f"{basename}.ids", ifc_text, f"{basename}.ifc", fail_or_pass))
assert bool(facet(inst)) is expected
case = spec_generator()
class TestIdsAuthoring(unittest.TestCase):
def test_create_an_ids_with_minimal_information(self):
specs = ids.ids()
assert specs.asdict() == {
"@xmlns": "http://standards.buildingsmart.org/IDS",
"@xmlns:xs": "http://www.w3.org/2001/XMLSchema",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:schemaLocation": "http://standards.buildingsmart.org/IDS/ids_05.xsd",
"info": {"title": "Untitled"},
"specifications": {"specification": []},
}
def test_create_an_ids_with_all_possible_information(self):
specs = ids.ids(
title="title",
copyright="copyright",
version="version",
description="description",
author="author@test.com",
date="2020-01-01",
purpose="purpose",
milestone="milestone",
)
assert specs.asdict() == {
"@xmlns": "http://standards.buildingsmart.org/IDS",
"@xmlns:xs": "http://www.w3.org/2001/XMLSchema",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:schemaLocation": "http://standards.buildingsmart.org/IDS/ids_05.xsd",
"info": {
"title": "title",
"copyright": "copyright",
"version": "version",
"description": "description",
"author": "author@test.com",
"date": "2020-01-01",
"purpose": "purpose",
"milestone": "milestone",
},
"specifications": {"specification": []},
}
def test_check_invalid_ids_information(self):
specs = ids.ids(title=None, author="author", date="9999-99-99")
assert specs.asdict() == {
"@xmlns": "http://standards.buildingsmart.org/IDS",
"@xmlns:xs": "http://www.w3.org/2001/XMLSchema",
"@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"@xsi:schemaLocation": "http://standards.buildingsmart.org/IDS/ids_05.xsd",
"info": {"title": "Untitled"},
"specifications": {"specification": []},
}
def test_authoring_an_ids_with_no_specifications_is_invalid(self):
specs = ids.ids()
with pytest.raises(xmlschema.validators.exceptions.XMLSchemaChildrenValidationError):
specs.to_string()
def test_create_specification_with_minimal_information(self):
spec = ids.specification()
assert spec.asdict() == {
"@name": "Unnamed",
"@ifcVersion": ["IFC2X3", "IFC4"],
"applicability": {},
"requirements": {},
}
def test_create_specification_with_all_possible_information(self):
spec = ids.specification(
name="name",
minOccurs="0",
maxOccurs="unbounded",
ifcVersion="IFC4",
identifier="identifier",
description="description",
instructions="instructions",
)
assert spec.asdict() == {
"@name": "name",
"@minOccurs": "0",
"@maxOccurs": "unbounded",
"@ifcVersion": "IFC4",
"@identifier": "identifier",
"@description": "description",
"@instructions": "instructions",
"applicability": {},
"requirements": {},
}
def test_creating_an_entity_facet(self):
facet = ids.entity.create(name="IfcName")
assert facet.asdict() == {"name": {"simpleValue": "IfcName"}}
facet = ids.entity.create(name="IfcName", predefinedType="predefinedType", instructions="instructions")
assert facet.asdict() == {
"name": {"simpleValue": "IfcName"},
"predefinedType": {"simpleValue": "predefinedType"},
"@instructions": "instructions",
}
def test_filtering_using_an_entity_facet(self):
ifc = ifcopenshell.file()
# Wrong IFC classes are never matched.
facet = ids.entity.create(name="IFCRABBIT")
case("Non-existent entity name", facet=facet, inst=ifc.createIfcWall(), expected=False)
# IFC class is checked for an exact match. Subclasses should not match.
# TODO: Some votes to prefer inheritance (For: Moult, Evandro, Artur)
# Possible argument: CAD tools don't understand IFC
facet = ids.entity.create(name="IFCWALL")
case("Entity matching", facet=facet, inst=ifc.createIfcWall(), expected=True)
case(
"Entity with PredefinedType", facet=facet, inst=ifc.createIfcWall(PredefinedType="SOLIDWALL"), expected=True
)
case("Entity matching", facet=facet, inst=ifc.createIfcSlab(), expected=False)
case("Entity subtype", facet=facet, inst=ifc.createIfcWallStandardCase(), expected=False)
# IFC class is case sensitive and has to be uppercase.
# TODO But in that case why are the enumerations for things like partOf using the IFC capitalisation?
facet = ids.entity.create(name="IfcWall")
case("Entity case", facet=facet, inst=ifc.createIfcWall(), expected=False)
# Predefined types are checked from standard enumeration values
facet = ids.entity.create(name="IFCWALL", predefinedType="SOLIDWALL")
case("Entity PredefinedType 0", facet=facet, inst=ifc.createIfcWall(), expected=False)
case("Entity PredefinedType 1", facet=facet, inst=ifc.createIfcWall(PredefinedType="SOLIDWALL"), expected=True)
case(
"Entity PredefinedType 2",
facet=facet,
inst=ifc.createIfcWall(PredefinedType="PARTITIONING"),
expected=False,
)
# Predefined Type must be uppercase, exactly the same as defined in the enumeration
facet = ids.entity.create(name="IFCWALL", predefinedType="solidwall")
assert bool(facet(ifc.createIfcWall(PredefinedType="SOLIDWALL"))) is False
# Predefined types are checked from the object type field if not standard
facet = ids.entity.create(name="IFCWALL", predefinedType="WALDO")
case(
"Entity user-defined type",
facet=facet,
inst=ifc.createIfcWall(PredefinedType="USERDEFINED", ObjectType="WALDO"),
expected=True,
)
# Predefined types are checked from the element type field if not standard for types
facet = ids.entity.create(name="IFCWALLTYPE", predefinedType="WALDO")
case(
"Entity ElementType",
facet=facet,
inst=ifc.createIfcWallType(PredefinedType="USERDEFINED", ElementType="WALDO"),
expected=True,
)
# Predefined types are checked from the process type field if not standard for processes
facet = ids.entity.create(name="IFCTASKTYPE", predefinedType="TASKY")
case(
"Entity ProcessType",
facet=facet,
inst=ifc.createIfcTaskType(PredefinedType="USERDEFINED", ProcessType="TASKY"),
expected=True,
)
# Userdefined is not an allowed filter because userdefined implies a specified object or element type
facet = ids.entity.create(name="IFCWALL", predefinedType="USERDEFINED")
case(
"Entity no USERDEFINED",
facet=facet,
inst=ifc.createIfcWall(PredefinedType="USERDEFINED", ObjectType="WALDO"),
expected=False,
)
# Predefined types should match inherited predefined types from the element type
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType", predefined_type="X")
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
facet = ids.entity.create(name="IFCWALL", predefinedType="X")
case("Entity PredefinedType inheritance 0", facet=facet, inst=wall, expected=True)
# Predefined types should match overridden predefined types from the element type
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall", predefined_type="X")
wall_type = ifcopenshell.api.run(
"root.create_entity", ifc, ifc_class="IfcWallType", predefined_type="NOTDEFINED"
)
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
facet = ids.entity.create(name="IFCWALL", predefinedType="X")
case("Entity PredefinedType inheritance 1", facet=facet, inst=wall, expected=True)
# Restrictions are allowed when matching the IFC class
restriction = ids.restriction.create(options=["IFCWALL", "IFCSLAB"], type="enumeration")
facet = ids.entity.create(name=restriction)
case("Entity enumeration 0", facet=facet, inst=ifc.createIfcWall(), expected=True)
case("Entity enumeration 1", facet=facet, inst=ifc.createIfcSlab(), expected=True)
case("Entity enumeration 2", facet=facet, inst=ifc.createIfcBeam(), expected=False)
# Another example of how restrictions are allowed when matching the IFC class
# Note: Regex patterns follow the XSD flavour
restriction = ids.restriction.create(options="IFC.*TYPE", type="pattern")
facet = ids.entity.create(name=restriction)
case("Entity pattern 0", facet=facet, inst=ifc.createIfcWall(), expected=False)
case("Entity pattern 1", facet=facet, inst=ifc.createIfcWallType(), expected=True)
# Restrictions are allowed when matching the predefined type
restriction = ids.restriction.create(options="FOO.*", type="pattern")
facet = ids.entity.create(name="IFCWALL", predefinedType=restriction)
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall", predefined_type="FOOBAR")
wall2 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall", predefined_type="FOOBAZ")
wall3 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall", predefined_type="BAZFOO")
case("", facet=facet, inst=wall, expected=True)
case("", facet=facet, inst=wall2, expected=True)
case("", facet=facet, inst=wall3, expected=False)
def test_creating_an_attribute_facet(self):
attribute = ids.attribute.create(name="name")
assert attribute.asdict() == {"name": {"simpleValue": "name"}}
attribute = ids.attribute.create(name="name", value="value")
assert attribute.asdict() == {"name": {"simpleValue": "name"}, "value": {"simpleValue": "value"}}
attribute = ids.attribute.create(
name="name", value="value", minOccurs="0", maxOccurs="unbounded", instructions="instructions"
)
assert attribute.asdict() == {
"name": {"simpleValue": "name"},
"value": {"simpleValue": "value"},
"@minOccurs": "0",
"@maxOccurs": "unbounded",
"@instructions": "instructions",
}
def test_filtering_using_an_attribute_facet(self):
ifc = ifcopenshell.file()
# Attribute names that don't exist are never matched
facet = ids.attribute.create(name="Foobar")
case("", facet=facet, inst=ifc.createIfcWall(), expected=False)
# Attribute names that are either null or empty string are not matched.
# The logic is that unfortunately most BIM users cannot differentiate between the two.
facet = ids.attribute.create(name="Name")
case("", facet=facet, inst=ifc.createIfcWall(), expected=False)
case("", facet=facet, inst=ifc.createIfcWall(Name=""), expected=False)
case("", facet=facet, inst=ifc.createIfcWall(Name="Foobar"), expected=True)
# TODO write test case that evaluates empty list / set as False
# TODO write test case that evaluates logical UNKNOWN as False
# TODO write test case that evaluates any bool as True
# An object value is truthy
facet = ids.attribute.create(name="OwnerHistory")
assert bool(facet(ifc.createIfcWall())) is False
assert bool(facet(ifc.createIfcWall(OwnerHistory=ifc.createIfcOwnerHistory()))) is True
# Selects are only considered for truthy or falsey
facet = ids.attribute.create(name="DiffuseColour")
element = ifc.createIfcSurfaceStyleRendering()
assert bool(facet(element)) is False
assert bool(facet(ifc.createIfcSurfaceStyleRendering(DiffuseColour=ifc.createIfcColourRgb()))) is True
assert (
bool(facet(ifc.createIfcSurfaceStyleRendering(DiffuseColour=ifc.createIfcNormalisedRatioMeasure(0.5))))
is True
)
# When a value is specified, the value shall match case sensitively
facet = ids.attribute.create(name="Name", value="Foobar")
case("", facet=facet, inst=ifc.createIfcWall(Name="Foobar"), expected=True)
case("", facet=facet, inst=ifc.createIfcWall(Name="foobar"), expected=False)
case("", facet=facet, inst=ifc.createIfcWall(Name="Foobaz"), expected=False)
# A value that is 0 is still considered a value, not "null-like", so it is matched
facet = ids.attribute.create(name="Eastings")
case("", facet=facet, inst=ifc.createIfcMapConversion(Eastings=0), expected=True)
# Value checks are meaningless for checking objects, selects, and lists so it always fails
facet = ids.attribute.create(name="OwnerHistory", value="Foobar")
assert bool(facet(ifc.createIfcWall(OwnerHistory=ifc.createIfcOwnerHistory()))) is False
# Selects
# Lists
# TODO continue from here
# TODO should we be allowed to check inverse attributes?
# Nope - always false
# TODO should we be allowed to check derived attributes?
# Nope - always false
# Simple values which must be strings are checked with strict typing. No type casting shall occur.
facet = ids.attribute.create(name="Eastings", value="42")
case("", facet=facet, inst=ifc.createIfcMapConversion(Eastings=0), expected=False)
case("", facet=facet, inst=ifc.createIfcMapConversion(Eastings=42), expected=False)
# Strict type checking is done with restrictions. This is really ugly, but hopefully hidden to a user.
restriction = ids.restriction.create(options=[42], type="enumeration", base="decimal")
# Here is another uglier option:
# restriction = ids.restriction.create(
# options={"minInclusive": 42, "maxInclusive": 42}, type="bounds", base="decimal"
# )
facet = ids.attribute.create(name="Eastings", value=restriction)
case("", facet=facet, inst=ifc.createIfcMapConversion(Eastings=42), expected=True)
# Restrictions are allowed for the name
restriction = ids.restriction.create(options=".*Name.*", type="pattern")
facet = ids.attribute.create(name=restriction)
case("", facet=facet, inst=ifc.createIfcMaterialLayerSet(LayerSetName="Foo"), expected=True)
case("", facet=facet, inst=ifc.createIfcMaterialConstituentSet(Name="Foo"), expected=True)
# Restrictions for the name imply that multiple names may be matched. All, not any, must pass the checks.
restriction = ids.restriction.create(options=["Name", "Description"], type="enumeration")
facet = ids.attribute.create(name=restriction)
case("", facet=facet, inst=ifc.createIfcWall(Name="Foo"), expected=False)
case("", facet=facet, inst=ifc.createIfcWall(Name="Foo", Description="Bar"), expected=True)
# Restrictions are allowed for the value
restriction = ids.restriction.create(options=["Foo", "Bar"], type="enumeration")
facet = ids.attribute.create(name="Name", value=restriction)
case("", facet=facet, inst=ifc.createIfcWall(Name="Foo"), expected=True)
case("", facet=facet, inst=ifc.createIfcWall(Name="Bar"), expected=True)
case("", facet=facet, inst=ifc.createIfcWall(Name="Foobar"), expected=False)
# The facet checks on attributes on the type, which may be inherited by the occurence
# TODO attribute inheritance is not defined IFC behaviour
facet = ids.attribute.create(name="Description", value="Foobar")
case("", facet=facet, inst=ifc.createIfcWall(Description="Foobar"), expected=True)
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
wall_type.Description = "Foobar"
case("", facet=facet, inst=wall, expected=True)
# The facet checks on attributes on the type, which may be overriden by attributes on the occurence
# TODO attribute overriding is not defined IFC behaviour
facet = ids.attribute.create(name="Description", value="Foobar")
case("", facet=facet, inst=ifc.createIfcWall(Description="Foobar"), expected=True)
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
wall_type.Description = "Foobaz"
wall.Description = "Foobar"
case("", facet=facet, inst=wall, expected=True)
def test_creating_a_classification_facet(self):
facet = ids.classification.create()
assert facet.asdict() == {}
facet = ids.classification.create(value="value", system="system")
assert facet.asdict() == {"value": {"simpleValue": "value"}, "system": {"simpleValue": "system"}}
facet = ids.classification.create(
value="value",
system="system",
uri="https://test.com",
minOccurs="0",
maxOccurs="unbounded",
instructions="instructions",
)
assert facet.asdict() == {
"value": {"simpleValue": "value"},
"system": {"simpleValue": "system"},
"@uri": "https://test.com",
"@minOccurs": "0",
"@maxOccurs": "unbounded",
"@instructions": "instructions",
}
def test_filtering_using_a_classification_facet(self):
library = ifcopenshell.file()
system = library.createIfcClassification(Name="Foobar")
ref1 = library.createIfcClassificationReference(Identification="1", ReferencedSource=system)
ref11 = library.createIfcClassificationReference(Identification="11", ReferencedSource=ref1)
ref2 = library.createIfcClassificationReference(Identification="2", ReferencedSource=system)
ref22 = library.createIfcClassificationReference(Identification="22", ReferencedSource=ref2)
ifc = ifcopenshell.file()
project = ifc.createIfcProject()
ifcopenshell.api.run("classification.add_classification", ifc, classification=system)
element0 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element1 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
ifcopenshell.api.run(
"classification.add_reference", ifc, product=element1, reference=ref1, classification=system
)
element11 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
ifcopenshell.api.run(
"classification.add_reference", ifc, product=element11, reference=ref11, classification=system
)
element22 = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
ifcopenshell.api.run(
"classification.add_reference",
ifc,
product=element22,
reference=ref22,
classification=system,
is_lightweight=False,
)
# A classification facet with no data matches any present classification
facet = ids.classification.create()
case("", facet=facet, inst=element0, expected=False)
case("", facet=facet, inst=element1, expected=True)
# Values should match exactly if lightweight classifications are used.
facet = ids.classification.create(value="1")
case("", facet=facet, inst=element1, expected=True)
# Values should match subreferences if full classifications are used.
# E.g. a facet searching for Uniclass EF_25_10 Walls will match Uniclass EF_25_10_25, EF_25_10_30, etc
facet = ids.classification.create(value="2")
case("", facet=facet, inst=element22, expected=True)
# Systems should match exactly regardless of lightweight or full classifications
facet = ids.classification.create(system="Foobar")
case("", facet=facet, inst=project, expected=True)
case("", facet=facet, inst=element0, expected=False)
case("", facet=facet, inst=element1, expected=True)
case("", facet=facet, inst=element11, expected=True)
case("", facet=facet, inst=element22, expected=True)
# Restrictions can be used for values
restriction = ids.restriction.create(options="1.*", type="pattern")
facet = ids.classification.create(value=restriction)
case("", facet=facet, inst=element1, expected=True)
case("", facet=facet, inst=element11, expected=True)
case("", facet=facet, inst=element22, expected=False)
# Restrictions can be used for systems
restriction = ids.restriction.create(options="Foo.*", type="pattern")
facet = ids.classification.create(system=restriction)
case("", facet=facet, inst=element0, expected=False)
case("", facet=facet, inst=element1, expected=True)
# Specifying both a value and a system means that both (as opposed to either) requirements must be met
facet = ids.classification.create(system="Foobar", value="1")
case("", facet=facet, inst=element1, expected=True)
case("", facet=facet, inst=element11, expected=False)
# The facet checks on either the type or instance.
# IFC doesn't specify how inheritance and overrides work here. Two options:
# Option 1) Occurrences replace inherited type references
# Option 2) Occurrences union with inherited type references
# Option 2 is followed here.
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
ifcopenshell.api.run("classification.add_reference", ifc, product=wall, reference=ref11, classification=system)
ifcopenshell.api.run(
"classification.add_reference", ifc, product=wall_type, reference=ref22, classification=system
)
facet = ids.classification.create(value="11")
case("", facet=facet, inst=wall, expected=True)
case("", facet=facet, inst=wall_type, expected=False)
facet = ids.classification.create(value="22")
case("", facet=facet, inst=wall, expected=True)
case("", facet=facet, inst=wall_type, expected=True)
def test_creating_a_property_facet(self):
facet = ids.property.create()
assert facet.asdict() == {
"propertySet": {"simpleValue": "Property_Set"},
"name": {"simpleValue": "PropertyName"},
}
facet = ids.property.create(
propertySet="propertySet",
name="name",
value="value",
measure="String",
uri="https://test.com",
minOccurs="0",
maxOccurs="unbounded",
instructions="instructions",
)
assert facet.asdict() == {
"propertySet": {"simpleValue": "propertySet"},
"name": {"simpleValue": "name"},
"value": {"simpleValue": "value"},
"@measure": "String",
"@uri": "https://test.com",
"@minOccurs": "0",
"@maxOccurs": "unbounded",
"@instructions": "instructions",
}
def test_filtering_using_a_property_facet(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
# Milli prefix used to check measurement conversions
lengthunit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="LENGTHUNIT", name="METRE", prefix="MILLI")
areaunit = ifcopenshell.api.run(
"unit.add_si_unit", ifc, unit_type="AREAUNIT", name="SQUARE_METRE", prefix="MILLI"
)
volumeunit = ifcopenshell.api.run(
"unit.add_si_unit", ifc, unit_type="VOLUMEUNIT", name="CUBIC_METRE", prefix="MILLI"
)
timeunit = ifcopenshell.api.run("unit.add_si_unit", ifc, unit_type="TIMEUNIT", name="SECOND")
ifcopenshell.api.run("unit.assign_unit", ifc, units=[lengthunit, areaunit, volumeunit, timeunit])
# A name check by itself only checks that a property is non-null and non empty string
# The logic is that unfortunately most BIM users cannot differentiate between the two.
facet = ids.property.create(propertySet="Foo_Bar", name="Foo")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
case("", facet=facet, inst=element, expected=False)
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
case("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": None})
case("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
case("", facet=facet, inst=element, expected=True)
# A simple value checks an exact case-sensitive match
facet = ids.property.create(propertySet="Foo_Bar", name="Foo", value="Bar")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
case("", facet=facet, inst=element, expected=True)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Baz"})
case("", facet=facet, inst=element, expected=False)
# Simple values only check string matches
facet = ids.property.create(propertySet="Foo_Bar", name="Foo", value="1")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "1"})
case("", facet=facet, inst=element, expected=True)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ifc.createIfcInteger(1)})
case("", facet=facet, inst=element, expected=False)
# Restrictions are supported for property sets. If multiple are matched, all must satisfy requirements.
restriction = ids.restriction.create(options="Foo_.*", type="pattern")
facet = ids.property.create(propertySet=restriction, name="Foo")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
case("", facet=facet, inst=element, expected=True)
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Baz")
case("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
case("", facet=facet, inst=element, expected=True)
# Restrictions are supported for names. If multiple are matched, all must satisfy requirements.
restriction = ids.restriction.create(options="Foo.*", type="pattern")
facet = ids.property.create(propertySet="Foo_Bar", name=restriction, value="x")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": "x"})
case("", facet=facet, inst=element, expected=True)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": "x", "Foobaz": "x"})
case("", facet=facet, inst=element, expected=True)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": "x", "Foobaz": "y"})
case("", facet=facet, inst=element, expected=False)
# Restrictions are supported for values. If multiple are matched, all must satisfy requirements.
restriction1 = ids.restriction.create(options="Foo.*", type="pattern")
restriction2 = ids.restriction.create(options=["x", "y"], type="enumeration")
facet = ids.property.create(propertySet="Foo_Bar", name=restriction1, value=restriction2)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": "x", "Foobaz": "y"})
case("", facet=facet, inst=element, expected=True)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": "x", "Foobaz": "z"})
case("", facet=facet, inst=element, expected=False)
# Restrictions may be used to check basic data primitives
restriction = ids.restriction.create(options=[42.12], type="enumeration", base="decimal")
facet = ids.property.create(propertySet="Foo_Bar", name="Foobar", value=restriction)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": 42.12})
case("", facet=facet, inst=element, expected=True)
restriction = ids.restriction.create(options=[42], type="enumeration", base="integer")
facet = ids.property.create(propertySet="Foo_Bar", name="Foobar", value=restriction)
case("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": 42})
case("", facet=facet, inst=element, expected=True)
restriction = ids.restriction.create(options=[True], type="enumeration", base="boolean")
facet = ids.property.create(propertySet="Foo_Bar", name="Foobar", value=restriction)
case("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": True})
case("", facet=facet, inst=element, expected=True)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": False})
case("", facet=facet, inst=element, expected=False)
# When measure is not specified, no unit conversion is done and only primitives are checked
restriction = ids.restriction.create(options=[42.12], type="enumeration", base="decimal")
facet = ids.property.create(propertySet="Foo_Bar", name="Foobar", value=restriction)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foobar": 42.12})
case("", facet=facet, inst=element, expected=True)
# Measure may be used to specify an IFC data type
restriction = ids.restriction.create(options=[2], type="enumeration", base="decimal")
facet = ids.property.create(propertySet="Foo_Bar", name="Foo", value=restriction, measure="Time")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ifc.createIfcMassMeasure(2)})
case("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ifc.createIfcTimeMeasure(2)})
case("", facet=facet, inst=element, expected=True)
# Measure also implies that a unit matters, and so a conversion shall take place to SI units
restriction = ids.restriction.create(options=[2], type="enumeration", base="decimal")
facet = ids.property.create(propertySet="Foo_Bar", name="Foo", value=restriction, measure="Length")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=element, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ifc.createIfcLengthMeasure(2)})
case("", facet=facet, inst=element, expected=False)
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": ifc.createIfcLengthMeasure(2000)})
case("", facet=facet, inst=element, expected=True)
# The facet checks inherited properties from the type
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=wall_type, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
facet = ids.property.create(propertySet="Foo_Bar", name="Foo")
case("", facet=facet, inst=wall, expected=True)
case("", facet=facet, inst=wall_type, expected=True)
# The facet checks overriden properties from the occurrence
wall = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
wall_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", ifc, related_object=wall, relating_type=wall_type)
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=wall_type, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Baz"})
pset = ifcopenshell.api.run("pset.add_pset", ifc, product=wall, name="Foo_Bar")
ifcopenshell.api.run("pset.edit_pset", ifc, pset=pset, properties={"Foo": "Bar"})
facet = ids.property.create(propertySet="Foo_Bar", name="Foo", value="Bar")
case("", facet=facet, inst=wall, expected=True)
case("", facet=facet, inst=wall_type, expected=False)
def test_creating_a_material_facet(self):
facet = ids.material.create()
assert facet.asdict() == {}
facet = ids.material.create(
value="value", uri="https://test.com", minOccurs="0", maxOccurs="unbounded", instructions="instructions"
)
assert facet.asdict() == {
"value": {"simpleValue": "value"},
"@uri": "https://test.com",
"@minOccurs": "0",
"@maxOccurs": "unbounded",
"@instructions": "instructions",
}
def test_filtering_using_a_material_facet(self):
ifc = ifcopenshell.file()
# A material facet with no data matches any present material
facet = ids.material.create()
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
case("", facet=facet, inst=element, expected=False)
material = ifcopenshell.api.run("material.add_material", ifc)
ifcopenshell.api.run("material.assign_material", ifc, product=element, material=material)
case("", facet=facet, inst=element, expected=True)
# A value will match a material name or category
facet = ids.material.create(value="Foo")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
material = ifcopenshell.api.run("material.add_material", ifc)
ifcopenshell.api.run("material.assign_material", ifc, product=element, material=material)
case("", facet=facet, inst=element, expected=False)
material.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
material.Name = "Bar"
material.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
# A value will match any material name or category in a material list
facet = ids.material.create(value="Foo")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
material_set = ifcopenshell.api.run("material.add_material_set", ifc, set_type="IfcMaterialList")
ifcopenshell.api.run("material.assign_material", ifc, product=element, material=material_set)
case("", facet=facet, inst=element, expected=False)
material = ifcopenshell.api.run("material.add_material", ifc)
ifcopenshell.api.run("material.add_list_item", ifc, material_list=material_set, material=material)
material.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
material.Name = "Bar"
material.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
# A value will match any material name or category, or layer name or category in a layer set
facet = ids.material.create(value="Foo")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
material_set = ifcopenshell.api.run("material.add_material_set", ifc, set_type="IfcMaterialLayerSet")
ifcopenshell.api.run("material.assign_material", ifc, product=element, material=material_set)
case("", facet=facet, inst=element, expected=False)
material = ifcopenshell.api.run("material.add_material", ifc)
layer = ifcopenshell.api.run("material.add_layer", ifc, layer_set=material_set, material=material)
layer.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
layer.Name = "Bar"
layer.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
layer.Category = "Bar"
material.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
material.Name = "Bar"
material.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
# A value will match any material name or category, or profile name or category in a profile set
facet = ids.material.create(value="Foo")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
material_set = ifcopenshell.api.run("material.add_material_set", ifc, set_type="IfcMaterialProfileSet")
ifcopenshell.api.run("material.assign_material", ifc, product=element, material=material_set)
case("", facet=facet, inst=element, expected=False)
material = ifcopenshell.api.run("material.add_material", ifc)
profile = ifcopenshell.api.run("material.add_profile", ifc, profile_set=material_set, material=material)
profile.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
profile.Name = "Bar"
profile.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
profile.Category = "Bar"
material.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
material.Name = "Bar"
material.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
# A value will match any material name or category, or constituent name or category in a constituent set
facet = ids.material.create(value="Foo")
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
material_set = ifcopenshell.api.run("material.add_material_set", ifc, set_type="IfcMaterialConstituentSet")
ifcopenshell.api.run("material.assign_material", ifc, product=element, material=material_set)
case("", facet=facet, inst=element, expected=False)
material = ifcopenshell.api.run("material.add_material", ifc)
constituent = ifcopenshell.api.run(
"material.add_constituent", ifc, constituent_set=material_set, material=material
)
constituent.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
constituent.Name = "Bar"
constituent.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
constituent.Category = "Bar"
material.Name = "Foo"
case("", facet=facet, inst=element, expected=True)
material.Name = "Bar"
material.Category = "Foo"
case("", facet=facet, inst=element, expected=True)
# The facet will check for inherited materials
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", ifc, related_object=element, relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", ifc)
ifcopenshell.api.run("material.assign_material", ifc, product=element_type, material=material)
material.Name = "Foo"
facet = ids.material.create(value="Foo")
case("", facet=facet, inst=element, expected=True)
case("", facet=facet, inst=element_type, expected=True)
# The facet will check for overriden materials
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
element_type = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWallType")
ifcopenshell.api.run("type.assign_type", ifc, related_object=element, relating_type=element_type)
material = ifcopenshell.api.run("material.add_material", ifc)