mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 13:46:54 +00:00
Simplified getting entity parent information for schema api
Removed unnecssary parent information from json schema - now API is getting it from ifcopenshell schema.
This commit is contained in:
@@ -20,6 +20,7 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import copy
|
import copy
|
||||||
|
import ifcopenshell
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import glob
|
import glob
|
||||||
@@ -49,7 +50,7 @@ SCHEMA_FILES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db = None
|
db = None
|
||||||
|
schema_by_name = {"IFC2X3": None, "IFC4": None}
|
||||||
|
|
||||||
def get_db(version):
|
def get_db(version):
|
||||||
global db
|
global db
|
||||||
@@ -67,16 +68,24 @@ def get_db(version):
|
|||||||
db[ifc_version][data_type] = json.load(fi)
|
db[ifc_version][data_type] = json.load(fi)
|
||||||
return db.get(version)
|
return db.get(version)
|
||||||
|
|
||||||
|
def get_schema_by_name(version):
|
||||||
|
global schema_by_name
|
||||||
|
if not schema_by_name[version]:
|
||||||
|
schema_by_name[version] = ifcopenshell.ifcopenshell_wrapper.schema_by_name(version)
|
||||||
|
return schema_by_name[version]
|
||||||
|
|
||||||
def get_entity_doc(version, entity, recursive=False):
|
def get_entity_doc(version, entity_name, recursive=False):
|
||||||
db = get_db(version)
|
db = get_db(version)
|
||||||
if db:
|
if db:
|
||||||
entity = copy.deepcopy(db["entities"].get(entity))
|
entity = copy.deepcopy(db["entities"].get(entity_name))
|
||||||
if not recursive:
|
if not recursive:
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
if "parent_entity" in entity:
|
ifc_schema = get_schema_by_name(version)
|
||||||
parent_entity = get_entity_doc(version, entity["parent_entity"], recursive=True)
|
ifc_entity = ifc_schema.declaration_by_name(entity_name)
|
||||||
|
ifc_supertype = ifc_entity.supertype()
|
||||||
|
if ifc_entity.supertype():
|
||||||
|
parent_entity = get_entity_doc(version, ifc_supertype.name(), recursive=True)
|
||||||
if 'attributes' not in entity:
|
if 'attributes' not in entity:
|
||||||
entity['attributes'] = dict()
|
entity['attributes'] = dict()
|
||||||
for parent_attr in parent_entity["attributes"]:
|
for parent_attr in parent_entity["attributes"]:
|
||||||
@@ -197,10 +206,7 @@ class DocExtractor:
|
|||||||
# because BeautifulSoup wrongly assume we confused
|
# because BeautifulSoup wrongly assume we confused
|
||||||
# html code for filepath and gives warnings
|
# html code for filepath and gives warnings
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore", category=MarkupResemblesLocatorWarning)
|
warnings.simplefilter("ignore", category=MarkupResemblesLocatorWarning)
|
||||||
doc_entity = bs_tree.find("docentity")
|
|
||||||
if doc_entity.has_attr('basedefinition'):
|
|
||||||
entities_dict[entity_name]["parent_entity"] = doc_entity["basedefinition"]
|
|
||||||
|
|
||||||
for html_attr in bs_tree.find_all("docattribute"):
|
for html_attr in bs_tree.find_all("docattribute"):
|
||||||
attr_name = html_attr["name"]
|
attr_name = html_attr["name"]
|
||||||
@@ -488,9 +494,6 @@ class DocExtractor:
|
|||||||
# html code for filepath and gives warnings
|
# html code for filepath and gives warnings
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore", category=MarkupResemblesLocatorWarning)
|
warnings.simplefilter("ignore", category=MarkupResemblesLocatorWarning)
|
||||||
doc_entity = bs_tree.find("docentity")
|
|
||||||
if doc_entity.has_attr('basedefinition'):
|
|
||||||
entities_dict[entity_name]["parent_entity"] = doc_entity["basedefinition"]
|
|
||||||
|
|
||||||
for html_attr in bs_tree.find_all("docattribute"):
|
for html_attr in bs_tree.find_all("docattribute"):
|
||||||
attr_name = html_attr["name"]
|
attr_name = html_attr["name"]
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user