This commit is contained in:
Andrej730
2025-09-08 14:42:36 +05:00
parent 9aafa32008
commit a4a04e6941
7 changed files with 173 additions and 169 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
from .serve import app
__all__ = ['app']
__all__ = ["app"]
+76 -63
View File
@@ -9,6 +9,7 @@ from ifctester.ids import Ids, IdsXmlValidationError, get_schema
# https://github.com/buildingSMART/IDS/blob/9914d568c7ac037acd97e58a0d16e9f93c3e3416/Schema/ids.xsd#L232
ifc_schemas = ["IFC2X3", "IFC4", "IFC4X3_ADD2"]
def get_predefined_types_for_entity(schema_name, entity_name):
"""Get a list of predefined types for a given entity."""
@@ -18,50 +19,57 @@ def get_predefined_types_for_entity(schema_name, entity_name):
entity = schema.declaration_by_name(entity_name)
except:
return []
if not entity or not entity.as_entity():
print(f"Entity {entity_name} not found")
return []
entity = entity.as_entity()
predefined_type_attr = None
# Check all attributes for "PredefinedType"
for attr in entity.all_attributes():
if attr.name() == "PredefinedType":
predefined_type_attr = attr
break
if not predefined_type_attr:
return []
param_type = predefined_type_attr.type_of_attribute()
if param_type.as_named_type():
enum_decl = param_type.as_named_type().declared_type()
if enum_decl.as_enumeration_type():
return enum_decl.as_enumeration_type().enumeration_items()
return []
def get_all_entity_classes(schema_name):
"""Get all IFC entity classes in the given schema."""
schema = ifcopenshell.schema_by_name(schema_name)
entities = []
for entity in schema.entities():
entities.append(entity.name())
# Sort alphabetically
entities.sort()
return entities
def get_all_data_types(schema_name):
"""Get all data types in the given schema."""
schema = ifcopenshell.schema_by_name(schema_name)
return {d.name(): ifcopenshell.util.attribute.get_primitive_type(d) for d in schema.declarations() if d.as_type_declaration()}
return {
d.name(): ifcopenshell.util.attribute.get_primitive_type(d)
for d in schema.declarations()
if d.as_type_declaration()
}
def get_entity_attributes(schema_name, entity_name):
"""Get all attributes for a given entity."""
@@ -72,40 +80,44 @@ def get_entity_attributes(schema_name, entity_name):
entity = schema.declaration_by_name(entity_name)
except:
return []
if not entity or not entity.as_entity():
print(f"Entity {entity_name} not found")
return []
entity = entity.as_entity()
attributes = []
for attr in entity.all_attributes():
attributes.append({
"name": attr.name(),
# "type": attr.type_of_attribute() # TODO Types of attribute
})
attributes.append(
{
"name": attr.name(),
# "type": attr.type_of_attribute() # TODO Types of attribute
}
)
return attributes
def get_applicable_psets(schema_name, entity_name, predefined_type = ""):
def get_applicable_psets(schema_name, entity_name, predefined_type=""):
"""Get all applicable property and quantity sets for a given entity."""
pset_qto = ifcopenshell.util.pset.PsetQto(schema_name)
pset_names = pset_qto.get_applicable_names(entity_name, predefined_type)
return pset_names
def get_all_psets(schema_name):
"""Get all property sets and quantity sets defined in an IFC schema"""
pset_qto = ifcopenshell.util.pset.PsetQto(schema_name)
result = {}
for template_file in pset_qto.templates:
for pset_template in template_file.by_type("IfcPropertySetTemplate"):
pset_name = pset_template.Name
properties = []
# Get property templates for this pset
if pset_template.HasPropertyTemplates:
for prop_template in pset_template.HasPropertyTemplates:
@@ -113,7 +125,7 @@ def get_all_psets(schema_name):
"name": prop_template.Name,
# "description": prop_template.Description
}
# Extract type information
if prop_template.is_a("IfcSimplePropertyTemplate"):
if prop_template.PrimaryMeasureType:
@@ -121,61 +133,62 @@ def get_all_psets(schema_name):
else:
prop_info["type"] = str(prop_template.TemplateType)
elif prop_template.is_a("IfcComplexPropertyTemplate"):
prop_info["type"] = None # Complex properties are not supported
prop_info["type"] = None # Complex properties are not supported
else:
prop_info["type"] = None
properties.append(prop_info)
result[pset_name] = properties
return result
def get_material_categories():
return ['concrete', 'steel', 'aluminium', 'block', 'brick', 'stone', 'wood', 'glass', 'gypsum', 'plastic', 'earth']
return ["concrete", "steel", "aluminium", "block", "brick", "stone", "wood", "glass", "gypsum", "plastic", "earth"]
def get_standard_classification_systems():
return {
'BB/SfB (3/4 cijfers)': {'source': 'Regie der Gebouwen', 'tokens': ['.']},
'BIMTypeCode': {'source': 'BIMStockholm', 'tokens': None},
'Common Arrangement of Work Sections (CAWS)': {'source': 'NBS', 'tokens': ['/']},
'CBI Classification - Level 2': {'source': 'Masterspec', 'tokens': None},
'CBI Classification - Level 4': {'source': 'Masterspec', 'tokens': None},
'Rumsfunktionskoder CC001 - 001': {'source': 'BIMAlliance', 'tokens': ['-']},
'CCS': {'source': 'Molio', 'tokens': None},
'CCTB': {'source': 'CCT-Bâtiments', 'tokens': ['.']},
'Funktionskoder Regionservice CD001 - 001': {'source': 'BIMAlliance', 'tokens': None},
'Rumsfunktion Blekinge CD002 - 001': {'source': 'BIMAlliance', 'tokens': None},
'EcoQuaestor Codetabel': {'source': 'EcoQuaestor', 'tokens': ['.', '-']},
'GuBIMclass CA': {'source': 'GuBIMClass', 'tokens': ['.']},
'GuBIMclass ES': {'source': 'GuBIMClass', 'tokens': ['.']},
'MasterFormat': {'source': 'CSI', 'tokens': [' ', '.']},
'NATSPEC Worksections': {'source': 'NATSPEC', 'tokens': None},
'NBS Create': {'source': 'NBS', 'tokens': ['_', '/']},
'NL/SfB (4 cijfers)': {'source': 'BIMLoket', 'tokens': ['.']},
'NS 3451 - Bygningsdelstabell': {'source': 'Standard Norge', 'tokens': None},
'OmniClass': {'source': 'OmniClass', 'tokens': ['-', ' ']},
'ÖNORM 6241-2': {'source': 'freeBIM 2', 'tokens': None},
'RICS NRM1': {'source': 'RICS', 'tokens': ['.']},
'RICS NRM3': {'source': 'RICS', 'tokens': ['.']},
'SFG20': {'source': 'SFG20', 'tokens': ['-']},
'SINAPI': {'source': 'Caixa', 'tokens': ['/']},
'STABU-Element': {'source': 'STABU', 'tokens': ['.']},
'TALO 2000 Building Component Classification': {'source': 'Rakennustieto', 'tokens': ['.']},
'TALO 2000 Hankenimikkeistö': {'source': 'Rakennustieto', 'tokens': ['.']},
'Uniclass': {'source': 'RIBA Enterprises Ltd', 'tokens': ['_']},
'Uniclass 2015': {'source': 'RIBA Enterprises Ltd', 'tokens': ['_']},
'UniFormat': {'source': 'UniFormat', 'tokens': ['.']},
'Uniformat': {'source': 'UniFormat', 'tokens': ['.']},
'VMSW': {'source': 'VMSW', 'tokens': ['.']}
"BB/SfB (3/4 cijfers)": {"source": "Regie der Gebouwen", "tokens": ["."]},
"BIMTypeCode": {"source": "BIMStockholm", "tokens": None},
"Common Arrangement of Work Sections (CAWS)": {"source": "NBS", "tokens": ["/"]},
"CBI Classification - Level 2": {"source": "Masterspec", "tokens": None},
"CBI Classification - Level 4": {"source": "Masterspec", "tokens": None},
"Rumsfunktionskoder CC001 - 001": {"source": "BIMAlliance", "tokens": ["-"]},
"CCS": {"source": "Molio", "tokens": None},
"CCTB": {"source": "CCT-Bâtiments", "tokens": ["."]},
"Funktionskoder Regionservice CD001 - 001": {"source": "BIMAlliance", "tokens": None},
"Rumsfunktion Blekinge CD002 - 001": {"source": "BIMAlliance", "tokens": None},
"EcoQuaestor Codetabel": {"source": "EcoQuaestor", "tokens": [".", "-"]},
"GuBIMclass CA": {"source": "GuBIMClass", "tokens": ["."]},
"GuBIMclass ES": {"source": "GuBIMClass", "tokens": ["."]},
"MasterFormat": {"source": "CSI", "tokens": [" ", "."]},
"NATSPEC Worksections": {"source": "NATSPEC", "tokens": None},
"NBS Create": {"source": "NBS", "tokens": ["_", "/"]},
"NL/SfB (4 cijfers)": {"source": "BIMLoket", "tokens": ["."]},
"NS 3451 - Bygningsdelstabell": {"source": "Standard Norge", "tokens": None},
"OmniClass": {"source": "OmniClass", "tokens": ["-", " "]},
"ÖNORM 6241-2": {"source": "freeBIM 2", "tokens": None},
"RICS NRM1": {"source": "RICS", "tokens": ["."]},
"RICS NRM3": {"source": "RICS", "tokens": ["."]},
"SFG20": {"source": "SFG20", "tokens": ["-"]},
"SINAPI": {"source": "Caixa", "tokens": ["/"]},
"STABU-Element": {"source": "STABU", "tokens": ["."]},
"TALO 2000 Building Component Classification": {"source": "Rakennustieto", "tokens": ["."]},
"TALO 2000 Hankenimikkeistö": {"source": "Rakennustieto", "tokens": ["."]},
"Uniclass": {"source": "RIBA Enterprises Ltd", "tokens": ["_"]},
"Uniclass 2015": {"source": "RIBA Enterprises Ltd", "tokens": ["_"]},
"UniFormat": {"source": "UniFormat", "tokens": ["."]},
"Uniformat": {"source": "UniFormat", "tokens": ["."]},
"VMSW": {"source": "VMSW", "tokens": ["."]},
}
def ids_from_xml_string(xml: str, validate: bool = False) -> Ids:
try:
decode = get_schema().decode(
xml, strip_namespaces=True, namespaces={
"": "http://standards.buildingsmart.org/IDS"
}
xml, strip_namespaces=True, namespaces={"": "http://standards.buildingsmart.org/IDS"}
)
except XMLSchemaValidationError as e:
raise IdsXmlValidationError(e, "Provided XML appears to be invalid. See details above.")
return Ids().parse(decode)
return Ids().parse(decode)
+27 -20
View File
@@ -22,11 +22,12 @@ from flask import Flask, send_from_directory, send_file
app = Flask(__name__)
def get_static_folder():
base_dir = os.path.dirname(__file__)
dist_dir = os.path.join(base_dir, 'dist')
www_dir = os.path.join(base_dir, 'www')
dist_dir = os.path.join(base_dir, "dist")
www_dir = os.path.join(base_dir, "www")
if os.path.exists(dist_dir) and os.path.isdir(dist_dir):
return dist_dir
elif os.path.exists(www_dir) and os.path.isdir(www_dir):
@@ -34,36 +35,42 @@ def get_static_folder():
else:
return dist_dir
STATIC_FOLDER = get_static_folder()
@app.route('/')
def index():
return send_file(os.path.join(STATIC_FOLDER, 'index.html'))
@app.route('/<path:filename>')
@app.route("/")
def index():
return send_file(os.path.join(STATIC_FOLDER, "index.html"))
@app.route("/<path:filename>")
def static_files(filename):
return send_from_directory(STATIC_FOLDER, filename)
@app.route('/assets/<path:filename>')
@app.route("/assets/<path:filename>")
def assets(filename):
return send_from_directory(os.path.join(STATIC_FOLDER, 'assets'), filename)
return send_from_directory(os.path.join(STATIC_FOLDER, "assets"), filename)
@app.errorhandler(404)
def not_found(error):
return send_file(os.path.join(STATIC_FOLDER, 'index.html'))
return send_file(os.path.join(STATIC_FOLDER, "index.html"))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Start IfcTester webapp')
parser.add_argument('--host', default='127.0.0.1', help='Host to bind to (default: 127.0.0.1)')
parser.add_argument('--port', type=int, default=5000, help='Port to bind to (default: 5000)')
parser.add_argument('--debug', action='store_true', help='Enable debug mode')
parser.add_argument('--dist-dir', default=STATIC_FOLDER, help='Directory containing built files')
parser = argparse.ArgumentParser(description="Start IfcTester webapp")
parser.add_argument("--host", default="127.0.0.1", help="Host to bind to (default: 127.0.0.1)")
parser.add_argument("--port", type=int, default=5000, help="Port to bind to (default: 5000)")
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
parser.add_argument("--dist-dir", default=STATIC_FOLDER, help="Directory containing built files")
args = parser.parse_args()
STATIC_FOLDER = args.dist_dir
print(f"Serving IfcTester webapp from: {STATIC_FOLDER}")
print(f"Server running at: http://{args.host}:{args.port}")
app.run(host=args.host, port=args.port, debug=args.debug)
app.run(host=args.host, port=args.port, debug=args.debug)