mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
black.py formatting
This commit is contained in:
@@ -28,6 +28,7 @@ from bmesh.types import BMVert
|
|||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
||||||
def add_dumb_stair_object(self, context):
|
def add_dumb_stair_object(self, context):
|
||||||
if self.number_of_treads <= 0:
|
if self.number_of_treads <= 0:
|
||||||
self.number_of_treads = 1
|
self.number_of_treads = 1
|
||||||
@@ -77,6 +78,7 @@ class BIM_OT_add_object(Operator, AddObjectHelper):
|
|||||||
add_dumb_stair_object(self, context)
|
add_dumb_stair_object(self, context)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
def create_stair(
|
def create_stair(
|
||||||
operator,
|
operator,
|
||||||
context,
|
context,
|
||||||
@@ -236,4 +238,3 @@ class BIM_OT_add_clever_stair(Operator):
|
|||||||
def add_object_button(self, context):
|
def add_object_button(self, context):
|
||||||
self.layout.operator(BIM_OT_add_object.bl_idname, icon="PLUGIN")
|
self.layout.operator(BIM_OT_add_object.bl_idname, icon="PLUGIN")
|
||||||
self.layout.operator(BIM_OT_add_clever_stair.bl_idname, icon="PLUGIN")
|
self.layout.operator(BIM_OT_add_clever_stair.bl_idname, icon="PLUGIN")
|
||||||
|
|
||||||
|
|||||||
@@ -197,4 +197,4 @@ class LibraryGenerator:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
LibraryGenerator().generate(parse_profiles_type="EU", output_filename="IFC4 EU Steel.ifc")
|
LibraryGenerator().generate(parse_profiles_type="EU", output_filename="IFC4 EU Steel.ifc")
|
||||||
LibraryGenerator().generate(parse_profiles_type="AU", output_filename="IFC4 AU Steel.ifc")
|
LibraryGenerator().generate(parse_profiles_type="AU", output_filename="IFC4 AU Steel.ifc")
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ SCHEMA_FILES = {
|
|||||||
db = None
|
db = None
|
||||||
schema_by_name = {"IFC2X3": None, "IFC4": None}
|
schema_by_name = {"IFC2X3": None, "IFC4": None}
|
||||||
|
|
||||||
|
|
||||||
def get_db(version):
|
def get_db(version):
|
||||||
global db
|
global db
|
||||||
if not db:
|
if not db:
|
||||||
@@ -70,28 +71,30 @@ 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):
|
def get_schema_by_name(version):
|
||||||
global schema_by_name
|
global schema_by_name
|
||||||
if not schema_by_name[version]:
|
if not schema_by_name[version]:
|
||||||
schema_by_name[version] = ifcopenshell.ifcopenshell_wrapper.schema_by_name(version)
|
schema_by_name[version] = ifcopenshell.ifcopenshell_wrapper.schema_by_name(version)
|
||||||
return schema_by_name[version]
|
return schema_by_name[version]
|
||||||
|
|
||||||
|
|
||||||
def get_entity_doc(version, entity_name, recursive=True):
|
def get_entity_doc(version, entity_name, recursive=True):
|
||||||
db = get_db(version)
|
db = get_db(version)
|
||||||
if db:
|
if db:
|
||||||
entity = copy.deepcopy(db["entities"].get(entity_name))
|
entity = copy.deepcopy(db["entities"].get(entity_name))
|
||||||
if not recursive:
|
if not recursive:
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
ifc_schema = get_schema_by_name(version)
|
ifc_schema = get_schema_by_name(version)
|
||||||
ifc_entity = ifc_schema.declaration_by_name(entity_name)
|
ifc_entity = ifc_schema.declaration_by_name(entity_name)
|
||||||
ifc_supertype = ifc_entity.supertype()
|
ifc_supertype = ifc_entity.supertype()
|
||||||
if ifc_entity.supertype():
|
if ifc_entity.supertype():
|
||||||
parent_entity = get_entity_doc(version, ifc_supertype.name(), recursive=True)
|
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"]:
|
||||||
entity['attributes'][parent_attr] = parent_entity["attributes"][parent_attr]
|
entity["attributes"][parent_attr] = parent_entity["attributes"][parent_attr]
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
|
|
||||||
@@ -102,6 +105,7 @@ def get_attribute_doc(version, entity, attribute, recursive=True):
|
|||||||
if entity:
|
if entity:
|
||||||
return entity["attributes"].get(attribute)
|
return entity["attributes"].get(attribute)
|
||||||
|
|
||||||
|
|
||||||
def get_predefined_type_doc(version, entity, predefined_type):
|
def get_predefined_type_doc(version, entity, predefined_type):
|
||||||
db = get_db(version)
|
db = get_db(version)
|
||||||
if db:
|
if db:
|
||||||
@@ -109,11 +113,13 @@ def get_predefined_type_doc(version, entity, predefined_type):
|
|||||||
if entity:
|
if entity:
|
||||||
return entity["predefined_types"].get(predefined_type)
|
return entity["predefined_types"].get(predefined_type)
|
||||||
|
|
||||||
|
|
||||||
def get_property_set_doc(version, pset):
|
def get_property_set_doc(version, pset):
|
||||||
db = get_db(version)
|
db = get_db(version)
|
||||||
if db:
|
if db:
|
||||||
return db["properties"].get(pset)
|
return db["properties"].get(pset)
|
||||||
|
|
||||||
|
|
||||||
def get_property_doc(version, pset, prop):
|
def get_property_doc(version, pset, prop):
|
||||||
db = get_db(version)
|
db = get_db(version)
|
||||||
if db:
|
if db:
|
||||||
@@ -121,11 +127,13 @@ def get_property_doc(version, pset, prop):
|
|||||||
if pset:
|
if pset:
|
||||||
return pset["properties"].get(prop)
|
return pset["properties"].get(prop)
|
||||||
|
|
||||||
|
|
||||||
def get_type_doc(version, ifc_type):
|
def get_type_doc(version, ifc_type):
|
||||||
db = get_db(version)
|
db = get_db(version)
|
||||||
if db:
|
if db:
|
||||||
return db["types"].get(ifc_type)
|
return db["types"].get(ifc_type)
|
||||||
|
|
||||||
|
|
||||||
class DocExtractor:
|
class DocExtractor:
|
||||||
def extract_ifc2x3(self):
|
def extract_ifc2x3(self):
|
||||||
print("Parsing data for Ifc2.3.0.1")
|
print("Parsing data for Ifc2.3.0.1")
|
||||||
@@ -205,14 +213,14 @@ class DocExtractor:
|
|||||||
|
|
||||||
with open(xml_path, "r", encoding="utf-8") as fi:
|
with open(xml_path, "r", encoding="utf-8") as fi:
|
||||||
bs_tree = BeautifulSoup(fi.read(), features="lxml")
|
bs_tree = BeautifulSoup(fi.read(), features="lxml")
|
||||||
|
|
||||||
entity_attrs = dict()
|
entity_attrs = dict()
|
||||||
predefined_types = dict()
|
predefined_types = dict()
|
||||||
# temporarily disable MarkupResemblesLocatorWarning
|
# temporarily disable MarkupResemblesLocatorWarning
|
||||||
# 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)
|
||||||
|
|
||||||
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"]
|
||||||
@@ -228,7 +236,9 @@ class DocExtractor:
|
|||||||
for href in hrefs:
|
for href in hrefs:
|
||||||
# in IFC2X3 all documentation for constants is empty
|
# in IFC2X3 all documentation for constants is empty
|
||||||
# and as a temporary solution I'm trying to get constant's description from IFC4
|
# and as a temporary solution I'm trying to get constant's description from IFC4
|
||||||
const_path = ifc4_references_paths_lookup.get(href, ifc2x3_references_paths_lookup[href])
|
const_path = ifc4_references_paths_lookup.get(
|
||||||
|
href, ifc2x3_references_paths_lookup[href]
|
||||||
|
)
|
||||||
with open(const_path, "r", encoding="utf-8") as fi:
|
with open(const_path, "r", encoding="utf-8") as fi:
|
||||||
const_bs_tree = BeautifulSoup(fi.read(), features="lxml")
|
const_bs_tree = BeautifulSoup(fi.read(), features="lxml")
|
||||||
const_name = const_bs_tree.find("docconstant")["name"]
|
const_name = const_bs_tree.find("docconstant")["name"]
|
||||||
@@ -259,7 +269,7 @@ class DocExtractor:
|
|||||||
|
|
||||||
if entity_attrs:
|
if entity_attrs:
|
||||||
entities_dict[entity_name]["attributes"] = entity_attrs
|
entities_dict[entity_name]["attributes"] = entity_attrs
|
||||||
|
|
||||||
if predefined_types:
|
if predefined_types:
|
||||||
entities_dict[entity_name]["predefined_types"] = predefined_types
|
entities_dict[entity_name]["predefined_types"] = predefined_types
|
||||||
|
|
||||||
@@ -398,9 +408,7 @@ class DocExtractor:
|
|||||||
def extract_ifc2x3_types(self):
|
def extract_ifc2x3_types(self):
|
||||||
types_dict = dict()
|
types_dict = dict()
|
||||||
# search
|
# search
|
||||||
types_paths = [
|
types_paths = [filepath for filepath in glob.iglob(f"{IFC2x3_DOCS_LOCATION}/Sections/**/Types", recursive=True)]
|
||||||
filepath for filepath in glob.iglob(f"{IFC2x3_DOCS_LOCATION}/Sections/**/Types", recursive=True)
|
|
||||||
]
|
|
||||||
for parse_folder_path in types_paths:
|
for parse_folder_path in types_paths:
|
||||||
for type_path in glob.iglob(f"{parse_folder_path}/**/"):
|
for type_path in glob.iglob(f"{parse_folder_path}/**/"):
|
||||||
type_path = Path(type_path)
|
type_path = Path(type_path)
|
||||||
@@ -421,15 +429,15 @@ class DocExtractor:
|
|||||||
type_description = type_description.replace("Definition from ISO/CD 10303-41:1992: ", "")
|
type_description = type_description.replace("Definition from ISO/CD 10303-41:1992: ", "")
|
||||||
|
|
||||||
type_description = type_description.strip()
|
type_description = type_description.strip()
|
||||||
|
|
||||||
if type_description:
|
if type_description:
|
||||||
types_dict[type_name]['description'] = type_description
|
types_dict[type_name]["description"] = type_description
|
||||||
|
|
||||||
spec_url = (
|
spec_url = (
|
||||||
"https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/"
|
"https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/"
|
||||||
f"{md_path.parents[2].name.lower()}/lexical/{type_name.lower()}.htm"
|
f"{md_path.parents[2].name.lower()}/lexical/{type_name.lower()}.htm"
|
||||||
)
|
)
|
||||||
types_dict[type_name]['spec_url'] = spec_url
|
types_dict[type_name]["spec_url"] = spec_url
|
||||||
|
|
||||||
# export entities data
|
# export entities data
|
||||||
with open(BASE_MODULE_PATH / "schema/ifc2x3_types.json", "w", encoding="utf-8") as fo:
|
with open(BASE_MODULE_PATH / "schema/ifc2x3_types.json", "w", encoding="utf-8") as fo:
|
||||||
@@ -501,7 +509,6 @@ class DocExtractor:
|
|||||||
references_paths_lookup[property_reference] = parsed_path
|
references_paths_lookup[property_reference] = parsed_path
|
||||||
return references_paths_lookup
|
return references_paths_lookup
|
||||||
|
|
||||||
|
|
||||||
def extract_ifc4_entities(self):
|
def extract_ifc4_entities(self):
|
||||||
references_paths_lookup = self.setup_ifc4_reference_lookup()
|
references_paths_lookup = self.setup_ifc4_reference_lookup()
|
||||||
entities_dict = dict()
|
entities_dict = dict()
|
||||||
@@ -582,7 +589,7 @@ class DocExtractor:
|
|||||||
|
|
||||||
if entity_attrs:
|
if entity_attrs:
|
||||||
entities_dict[entity_name]["attributes"] = entity_attrs
|
entities_dict[entity_name]["attributes"] = entity_attrs
|
||||||
|
|
||||||
if predefined_types:
|
if predefined_types:
|
||||||
entities_dict[entity_name]["predefined_types"] = predefined_types
|
entities_dict[entity_name]["predefined_types"] = predefined_types
|
||||||
|
|
||||||
@@ -739,9 +746,7 @@ class DocExtractor:
|
|||||||
def extract_ifc4_types(self):
|
def extract_ifc4_types(self):
|
||||||
types_dict = dict()
|
types_dict = dict()
|
||||||
# search
|
# search
|
||||||
types_paths = [
|
types_paths = [filepath for filepath in glob.iglob(f"{IFC4_DOCS_LOCATION}/Sections/**/Types", recursive=True)]
|
||||||
filepath for filepath in glob.iglob(f"{IFC4_DOCS_LOCATION}/Sections/**/Types", recursive=True)
|
|
||||||
]
|
|
||||||
for parse_folder_path in types_paths:
|
for parse_folder_path in types_paths:
|
||||||
for type_path in glob.iglob(f"{parse_folder_path}/**/"):
|
for type_path in glob.iglob(f"{parse_folder_path}/**/"):
|
||||||
type_path = Path(type_path)
|
type_path = Path(type_path)
|
||||||
@@ -757,25 +762,28 @@ class DocExtractor:
|
|||||||
type_description = type_description.replace("\n", " ")
|
type_description = type_description.replace("\n", " ")
|
||||||
type_description = type_description.replace("\u00a0", " ")
|
type_description = type_description.replace("\u00a0", " ")
|
||||||
type_description = type_description.replace("{ .extDef}", "")
|
type_description = type_description.replace("{ .extDef}", "")
|
||||||
type_description = type_description.replace("NOTE Definition according to ISO/CD 10303-41:1992 ", "")
|
type_description = type_description.replace(
|
||||||
|
"NOTE Definition according to ISO/CD 10303-41:1992 ", ""
|
||||||
|
)
|
||||||
type_description = type_description.replace("Definition from ISO/CD 10303-41:1992: ", "")
|
type_description = type_description.replace("Definition from ISO/CD 10303-41:1992: ", "")
|
||||||
|
|
||||||
type_description = type_description.strip()
|
type_description = type_description.strip()
|
||||||
|
|
||||||
if type_description:
|
if type_description:
|
||||||
types_dict[type_name]['description'] = type_description
|
types_dict[type_name]["description"] = type_description
|
||||||
|
|
||||||
spec_url = (
|
spec_url = (
|
||||||
"https://standards.buildingsmart.org/IFC/RELEASE/IFC4/ADD2_TC1/HTML/schema/"
|
"https://standards.buildingsmart.org/IFC/RELEASE/IFC4/ADD2_TC1/HTML/schema/"
|
||||||
f"{md_path.parents[2].name.lower()}/lexical/{type_name.lower()}.htm"
|
f"{md_path.parents[2].name.lower()}/lexical/{type_name.lower()}.htm"
|
||||||
)
|
)
|
||||||
types_dict[type_name]['spec_url'] = spec_url
|
types_dict[type_name]["spec_url"] = spec_url
|
||||||
|
|
||||||
# export entities data
|
# export entities data
|
||||||
with open(BASE_MODULE_PATH / "schema/ifc4_types.json", "w", encoding="utf-8") as fo:
|
with open(BASE_MODULE_PATH / "schema/ifc4_types.json", "w", encoding="utf-8") as fo:
|
||||||
print(f"{len(types_dict)} ifc types parsed")
|
print(f"{len(types_dict)} ifc types parsed")
|
||||||
json.dump(types_dict, fo, sort_keys=True, indent=4)
|
json.dump(types_dict, fo, sort_keys=True, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def run_doc_api_examples():
|
def run_doc_api_examples():
|
||||||
print("Entities (with parent entities attributes included):")
|
print("Entities (with parent entities attributes included):")
|
||||||
print(get_entity_doc("IFC2X3", "IfcWindow"))
|
print(get_entity_doc("IFC2X3", "IfcWindow"))
|
||||||
|
|||||||
Reference in New Issue
Block a user