Skip to content

Commit d37697f

Browse files
Added schema definition
1 parent c469167 commit d37697f

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

ifcjson/ifc2json4.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def spf2Json(self):
5353
self.entityToDict(entity)
5454
for key in self.id_objects:
5555
jsonObjects.append(self.id_objects[key])
56-
return jsonObjects
56+
return {'file_schema': 'IFC.JSON4','data': jsonObjects}
5757

5858
@functools.lru_cache(maxsize=maxCache)
5959
def entityToDict(self, entity):
60-
attr_dict = entity.__dict__
60+
entityAttributes = entity.__dict__
6161

6262
ref = {
6363
"type": entity.is_a()
@@ -67,51 +67,51 @@ def entityToDict(self, entity):
6767
if entity.is_a() == 'IfcOwnerHistory':
6868
if not entity.id() in self.ownerHistories:
6969
self.ownerHistories[entity.id()] = guid.new()
70-
attr_dict["GlobalId"] = self.ownerHistories[entity.id()]
70+
entityAttributes["GlobalId"] = self.ownerHistories[entity.id()]
7171

7272
# Add missing GlobalId to IfcGeometricRepresentationContext
7373
if entity.is_a() == 'IfcGeometricRepresentationContext':
7474
if not entity.id() in self.representationContexts:
7575
self.representationContexts[entity.id()] = guid.new()
76-
attr_dict["GlobalId"] = self.representationContexts[entity.id()]
76+
entityAttributes["GlobalId"] = self.representationContexts[entity.id()]
7777

7878
# check for globalid
79-
if "GlobalId" in attr_dict:
80-
uuid = guid.split(guid.expand(attr_dict["GlobalId"]))[1:-1]
79+
if "GlobalId" in entityAttributes:
80+
uuid = guid.split(guid.expand(entityAttributes["GlobalId"]))[1:-1]
8181
ref["ref"] = uuid
82-
if not attr_dict["GlobalId"] in self.id_objects:
82+
if not entityAttributes["GlobalId"] in self.id_objects:
8383
d = {
8484
"type": entity.is_a()
8585
}
8686

8787
# Add missing GlobalId to OwnerHistory
8888
if entity.is_a() == 'IfcOwnerHistory':
89-
d["GlobalId"] = guid.split(guid.expand(self.ownerHistories[entity.id()]))[1:-1]
89+
d["globalId"] = guid.split(guid.expand(self.ownerHistories[entity.id()]))[1:-1]
9090

9191
# Add missing GlobalId to IfcGeometricRepresentationContext
9292
if entity.is_a() == 'IfcGeometricRepresentationContext':
93-
d["GlobalId"] = guid.split(guid.expand(self.representationContexts[entity.id()]))[1:-1]
93+
d["globalId"] = guid.split(guid.expand(self.representationContexts[entity.id()]))[1:-1]
9494

9595
for i in range(0,len(entity)):
9696
attr = entity.attribute_name(i)
9797
attrKey = common.toLowerCamelcase(attr)
9898
if attr == "GlobalId":
9999
d[attrKey] = uuid
100100
else:
101-
if attr in attr_dict:
102-
jsonValue = self.getEntityValue(attr_dict[attr])
101+
if attr in entityAttributes:
102+
jsonValue = self.getEntityValue(entityAttributes[attr])
103103
if jsonValue:
104104
if ((entity.is_a() == 'IfcOwnerHistory') and (attr == "GlobalId")):
105105
pass
106106
else:
107107
d[attrKey] = jsonValue
108-
if attr_dict[attr] == None:
108+
if entityAttributes[attr] == None:
109109
continue
110-
elif isinstance(attr_dict[attr], ifcopenshell.entity_instance):
111-
d[attrKey] = self.entityToDict(attr_dict[attr])
112-
elif isinstance(attr_dict[attr], tuple):
110+
elif isinstance(entityAttributes[attr], ifcopenshell.entity_instance):
111+
d[attrKey] = self.entityToDict(entityAttributes[attr])
112+
elif isinstance(entityAttributes[attr], tuple):
113113
subEnts = []
114-
for subEntity in attr_dict[attr]:
114+
for subEntity in entityAttributes[attr]:
115115
if isinstance(subEntity, ifcopenshell.entity_instance):
116116
subEntJson = self.entityToDict(subEntity)
117117
if subEntJson:
@@ -121,8 +121,8 @@ def entityToDict(self, entity):
121121
if len(subEnts) > 0:
122122
d[attrKey] = subEnts
123123
else:
124-
d[attrKey] = attr_dict[attr]
125-
self.id_objects[attr_dict["GlobalId"]] = d
124+
d[attrKey] = entityAttributes[attr]
125+
self.id_objects[entityAttributes["GlobalId"]] = d
126126
return ref
127127
else:
128128
d = {
@@ -132,18 +132,18 @@ def entityToDict(self, entity):
132132
for i in range(0,len(entity)):
133133
attr = entity.attribute_name(i)
134134
attrKey = common.toLowerCamelcase(attr)
135-
if attr in attr_dict:
135+
if attr in entityAttributes:
136136
if not attr == "OwnerHistory":
137-
jsonValue = self.getEntityValue(attr_dict[attr])
137+
jsonValue = self.getEntityValue(entityAttributes[attr])
138138
if jsonValue:
139139
d[attrKey] = jsonValue
140-
if attr_dict[attr] == None:
140+
if entityAttributes[attr] == None:
141141
continue
142-
elif isinstance(attr_dict[attr], ifcopenshell.entity_instance):
143-
d[attrKey] = self.entityToDict(attr_dict[attr])
144-
elif isinstance(attr_dict[attr], tuple):
142+
elif isinstance(entityAttributes[attr], ifcopenshell.entity_instance):
143+
d[attrKey] = self.entityToDict(entityAttributes[attr])
144+
elif isinstance(entityAttributes[attr], tuple):
145145
subEnts = []
146-
for subEntity in attr_dict[attr]:
146+
for subEntity in entityAttributes[attr]:
147147
if isinstance(subEntity, ifcopenshell.entity_instance):
148148
# subEnts.append(None)
149149
subEntJson = self.entityToDict(subEntity)
@@ -154,7 +154,7 @@ def entityToDict(self, entity):
154154
if len(subEnts) > 0:
155155
d[attrKey] = subEnts
156156
else:
157-
d[attrKey] = attr_dict[attr]
157+
d[attrKey] = entityAttributes[attr]
158158
return d
159159

160160
@functools.lru_cache(maxsize=maxCache)

0 commit comments

Comments
 (0)