mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Run black on IfcOpenShell-python.
This commit is contained in:
@@ -32,7 +32,7 @@ class Usecase:
|
||||
# IfcTextLiteral
|
||||
"ifc_representation_class": None, # Whether to cast a mesh into a particular class
|
||||
"profile_set_usage": None, # The material profile set if the extrusion requires it
|
||||
"text_literal": None, # The text literal if the representation requires it
|
||||
"text_literal": None, # The text literal if the representation requires it
|
||||
}
|
||||
self.ifc_vertices = []
|
||||
for key, value in settings.items():
|
||||
|
||||
@@ -26,8 +26,10 @@ class Usecase:
|
||||
|
||||
if conversion_offset:
|
||||
return self.file.createIfcConversionBasedUnitWithOffset(
|
||||
exponents, unit_type, self.settings["name"], conversion_factor, conversion_offset,
|
||||
exponents,
|
||||
unit_type,
|
||||
self.settings["name"],
|
||||
conversion_factor,
|
||||
conversion_offset,
|
||||
)
|
||||
return self.file.createIfcConversionBasedUnit(
|
||||
exponents, unit_type, self.settings["name"], conversion_factor
|
||||
)
|
||||
return self.file.createIfcConversionBasedUnit(exponents, unit_type, self.settings["name"], conversion_factor)
|
||||
|
||||
@@ -62,10 +62,10 @@ def main(settings, files, iterators=None, merge_projection=True, progress_functi
|
||||
|
||||
geom_settings = ifcopenshell.geom.settings(
|
||||
# this is required for serialization
|
||||
APPLY_DEFAULT_MATERIALS = True,
|
||||
DISABLE_TRIANGULATION = True,
|
||||
APPLY_DEFAULT_MATERIALS=True,
|
||||
DISABLE_TRIANGULATION=True,
|
||||
# when not doing booleans, proper solids from shells isn't a requirement
|
||||
SEW_SHELLS = settings.subtract_before_hlr
|
||||
SEW_SHELLS=settings.subtract_before_hlr,
|
||||
)
|
||||
|
||||
if not iterators:
|
||||
@@ -83,7 +83,7 @@ def main(settings, files, iterators=None, merge_projection=True, progress_functi
|
||||
files,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if settings.cache:
|
||||
cache = ifcopenshell.geom.serializers.hdf5("cache.h5", geom_settings)
|
||||
for it in iterators:
|
||||
@@ -108,7 +108,7 @@ def main(settings, files, iterators=None, merge_projection=True, progress_functi
|
||||
sr.setElevationRefGuid(settings.drawing_guid)
|
||||
sr.setWithoutStoreys(True)
|
||||
# If you want to filter by IfcAnnotation ObjectType named "DRAWING"
|
||||
#sr.setElevationRef("DRAWING")
|
||||
# sr.setElevationRef("DRAWING")
|
||||
|
||||
# required for svgfill
|
||||
sr.setPolygonal(True)
|
||||
@@ -130,7 +130,7 @@ def main(settings, files, iterators=None, merge_projection=True, progress_functi
|
||||
sr.setSubtractionSettings(W.ALWAYS)
|
||||
|
||||
try:
|
||||
sh = ['none', 'full', 'left'].index(settings.storey_heights)
|
||||
sh = ["none", "full", "left"].index(settings.storey_heights)
|
||||
sr.setDrawStoreyHeights(sh)
|
||||
except:
|
||||
raise ValueError("storey_heights should be one of {'none', 'full', 'left'}")
|
||||
@@ -170,7 +170,7 @@ def main(settings, files, iterators=None, merge_projection=True, progress_functi
|
||||
|
||||
if not merge_projection:
|
||||
return svg_data_1
|
||||
|
||||
|
||||
if not settings.cells:
|
||||
return svg_data_1.encode("ascii", "xmlcharrefreplace")
|
||||
|
||||
@@ -275,9 +275,7 @@ def main(settings, files, iterators=None, merge_projection=True, progress_functi
|
||||
# the factor determines how much white will be interpolated
|
||||
# into the style diffuse color.
|
||||
clr = numpy.array(style.diffuse)
|
||||
factor = (math.log(elements[0].distance + 2.0) / 7.0) * (
|
||||
1.0 - 0.5 * abs(elements[0].dot_product)
|
||||
)
|
||||
factor = (math.log(elements[0].distance + 2.0) / 7.0) * (1.0 - 0.5 * abs(elements[0].dot_product))
|
||||
if style.has_transparency:
|
||||
factor *= 1.0 - style.transparency
|
||||
clr = WHITE * (1.0 - factor) + clr * factor
|
||||
@@ -314,18 +312,18 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
import time
|
||||
import argparse
|
||||
|
||||
|
||||
times = []
|
||||
|
||||
|
||||
def measure(task, fn):
|
||||
t0 = time.time()
|
||||
r = fn()
|
||||
dt = time.time() - t0
|
||||
times.append((task, dt))
|
||||
return r
|
||||
|
||||
|
||||
def print_progress(*args):
|
||||
print("\r", *args, " "*10, end="", flush=True)
|
||||
print("\r", *args, " " * 10, end="", flush=True)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
@@ -333,12 +331,8 @@ if __name__ == "__main__":
|
||||
|
||||
for field in fields(draw_settings):
|
||||
if field.type == bool:
|
||||
parser.add_argument(
|
||||
"--" + field.name.replace("_", "-"), dest=field.name, action="store_true"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-" + field.name.replace("_", "-"), dest=field.name, action="store_false"
|
||||
)
|
||||
parser.add_argument("--" + field.name.replace("_", "-"), dest=field.name, action="store_true")
|
||||
parser.add_argument("--no-" + field.name.replace("_", "-"), dest=field.name, action="store_false")
|
||||
parser.set_defaults(**{field.name: field.default})
|
||||
else:
|
||||
parser.add_argument(
|
||||
@@ -355,9 +349,8 @@ if __name__ == "__main__":
|
||||
files = measure("open files", lambda: list(map(ifcopenshell.open, files)))
|
||||
result = measure("processing", lambda: main(settings, files, progress_function=print_progress))
|
||||
open(output, "wb").write(result)
|
||||
|
||||
|
||||
print("\r Done!", " " * 20)
|
||||
|
||||
|
||||
for t, dt in times:
|
||||
print(f"{t}: {dt}")
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ def set_derived_atribute(*args):
|
||||
# inherited attributes) to set that particular
|
||||
# attribute by index.
|
||||
# For example. IFC2X3.IfcWall with have a list of
|
||||
# 9 methods. The first will point at
|
||||
# 9 methods. The first will point at
|
||||
# ifcopenshell.ifcopenshell_wrapper.entity_instance.setArgumentAsString
|
||||
# because the first attribute GlobalId ultimately
|
||||
# is of type string.
|
||||
@@ -56,25 +56,28 @@ for nm in ifcopenshell_wrapper.schema_names():
|
||||
for decl in schema.declarations():
|
||||
if hasattr(decl, "argument_types"):
|
||||
fq_name = ".".join((nm, decl.name()))
|
||||
|
||||
|
||||
# get type strings as reported by IfcOpenShell C++
|
||||
type_strs = decl.argument_types()
|
||||
|
||||
|
||||
# convert case for setter function
|
||||
type_strs = [x.title().replace(" ", "") for x in type_strs]
|
||||
|
||||
|
||||
# binary and enumeration are passed from python as string as well
|
||||
type_strs = [x.replace("Binary", "String") for x in type_strs]
|
||||
type_strs = [x.replace("Enumeration", "String") for x in type_strs]
|
||||
|
||||
|
||||
# prefix to get method names
|
||||
fn_names = ["setArgumentAs" + x for x in type_strs]
|
||||
|
||||
|
||||
# resolve to actual functions in wrapper
|
||||
functions = [
|
||||
set_derived_atribute if mname == "setArgumentAsDerived" else getattr(ifcopenshell_wrapper.entity_instance, mname) \
|
||||
for mname in fn_names]
|
||||
|
||||
set_derived_atribute
|
||||
if mname == "setArgumentAsDerived"
|
||||
else getattr(ifcopenshell_wrapper.entity_instance, mname)
|
||||
for mname in fn_names
|
||||
]
|
||||
|
||||
_method_dict[fq_name] = functions
|
||||
|
||||
|
||||
@@ -177,13 +180,13 @@ class entity_instance(object):
|
||||
|
||||
if self.method_list is None:
|
||||
super(entity_instance, self).__setattr__("method_list", _method_dict[self.is_a(True)])
|
||||
|
||||
|
||||
method = self.method_list[idx]
|
||||
|
||||
|
||||
if value is None:
|
||||
if method is not set_derived_atribute:
|
||||
self.wrapped_data.setArgumentAsNull(idx)
|
||||
else:
|
||||
else:
|
||||
self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value))
|
||||
|
||||
return value
|
||||
|
||||
@@ -26,13 +26,16 @@ import documentation
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
class Header(codegen.Base):
|
||||
def __init__(self, mapping):
|
||||
declarations = []
|
||||
|
||||
case_lookup = lambda nm: [k for k in mapping.schema.keys if k.lower() == nm.lower()][0]
|
||||
case_normalize = lambda nm: nm if nm.startswith("IfcUtil::") else case_lookup(nm)
|
||||
create_supertype_statement = lambda nms: ", ".join("public %s %s" % ("" if c.startswith("IfcUtil::") else "",c) for c in nms)
|
||||
create_supertype_statement = lambda nms: ", ".join(
|
||||
"public %s %s" % ("" if c.startswith("IfcUtil::") else "", c) for c in nms
|
||||
)
|
||||
|
||||
write = lambda str, **kwargs: declarations.append(
|
||||
str
|
||||
@@ -80,18 +83,24 @@ class Header(codegen.Base):
|
||||
else:
|
||||
superclasses.append("IfcUtil::IfcBaseType")
|
||||
superclasses.extend(get_select_super_types(name, bases=all_superclasses))
|
||||
|
||||
is_emitted = lambda nm: nm == "IfcUtil::IfcBaseType" or nm in mapping.schema.selects or nm.lower() in emitted_simpletypes
|
||||
|
||||
is_emitted = (
|
||||
lambda nm: nm == "IfcUtil::IfcBaseType"
|
||||
or nm in mapping.schema.selects
|
||||
or nm.lower() in emitted_simpletypes
|
||||
)
|
||||
if not all(map(is_emitted, superclasses)):
|
||||
continue
|
||||
|
||||
|
||||
superclasses = list(map(case_normalize, superclasses))
|
||||
|
||||
emitted_simpletypes.add(name.lower())
|
||||
|
||||
superclass_statement = create_supertype_statement(superclasses)
|
||||
|
||||
write(templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass_statement)
|
||||
write(
|
||||
templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass_statement
|
||||
)
|
||||
|
||||
class_definitions = []
|
||||
|
||||
@@ -149,7 +158,7 @@ class Header(codegen.Base):
|
||||
supertypes.extend(get_select_super_types(name, bases=all_supertypes))
|
||||
supertypes = list(map(case_normalize, supertypes))
|
||||
superclass = create_supertype_statement(supertypes)
|
||||
|
||||
|
||||
argument_count = mapping.argument_count(type)
|
||||
|
||||
argument_start = argument_count - len(type.attributes)
|
||||
|
||||
@@ -92,14 +92,16 @@ class Implementation(codegen.Base):
|
||||
else:
|
||||
return templates.get_attr_stmt
|
||||
|
||||
null_check = ''
|
||||
null_check = ""
|
||||
if arg["is_optional"]:
|
||||
attr_check = "if(!data_->getArgument(%d) || data_->getArgument(%d)->isNull()) { return %%s; }" % (arg["index"] - 1, arg["index"] - 1)
|
||||
attr_check = (
|
||||
"if(!data_->getArgument(%d) || data_->getArgument(%d)->isNull()) { return %%s; }"
|
||||
% (arg["index"] - 1, arg["index"] - 1)
|
||||
)
|
||||
if "boost::optional" in arg["full_type"]:
|
||||
null_check = attr_check % "boost::none"
|
||||
else:
|
||||
null_check = attr_check % "nullptr"
|
||||
|
||||
|
||||
tmpl = find_template(arg)
|
||||
write_attr(
|
||||
@@ -115,9 +117,11 @@ class Implementation(codegen.Base):
|
||||
"index": arg["index"] - 1,
|
||||
"type": arg["full_type"].replace("::Value", ""),
|
||||
"non_optional_type": arg["non_optional_type"].replace("::Value", ""),
|
||||
"non_optional_type_no_pointer": arg["non_optional_type"].replace("::Value", "").replace("*", ""),
|
||||
"non_optional_type_no_pointer": arg["non_optional_type"]
|
||||
.replace("::Value", "")
|
||||
.replace("*", ""),
|
||||
"list_instance_type": arg["list_instance_type"],
|
||||
"null_check": null_check
|
||||
"null_check": null_check,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -143,10 +147,10 @@ class Implementation(codegen.Base):
|
||||
schema_name_upper=schema_name_upper,
|
||||
body=tmpl
|
||||
% {
|
||||
"index": arg["index"] - 1,
|
||||
"index": arg["index"] - 1,
|
||||
"type": arg["full_type"].replace("::Value", ""),
|
||||
"non_optional_type": arg["non_optional_type"].replace("::Value", ""),
|
||||
"star_if_optional": "*" if "boost::optional" in arg["full_type"] else ""
|
||||
"star_if_optional": "*" if "boost::optional" in arg["full_type"] else "",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -142,10 +142,13 @@ class Mapping:
|
||||
raise ValueError("Unable to map type %r for attribute %r" % (type, attr))
|
||||
|
||||
ty = _make_argument_type(attr.type if hasattr(attr, "type") else attr)
|
||||
if ty == "TRIBOOL": ty = "LOGICAL"
|
||||
|
||||
if ty == "TRIBOOL":
|
||||
ty = "LOGICAL"
|
||||
|
||||
if ty not in self.supported_argument_types:
|
||||
import pdb; pdb.set_trace()
|
||||
import pdb
|
||||
|
||||
pdb.set_trace()
|
||||
print("Attribute %r mapped as 'unknown'" % (attr), file=sys.stderr)
|
||||
ty = "UNKNOWN"
|
||||
return "IfcUtil::Argument_%s" % ty
|
||||
@@ -175,7 +178,7 @@ class Mapping:
|
||||
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type)
|
||||
# We do not use pointers in aggregate_of<T>. aggregate_of has member vector<T*>
|
||||
ty = ty.replace("*", "")
|
||||
|
||||
|
||||
if self.schema.is_select(attr_type.type):
|
||||
type_str = templates.untyped_list
|
||||
elif self.schema.is_simpletype(ty) or str(ty) in self.express_to_cpp_typemapping.values():
|
||||
|
||||
@@ -57,6 +57,7 @@ if has_occ:
|
||||
# nb: we just subclass serializer settings, so in python
|
||||
# we do not differentiate between the two setting types
|
||||
|
||||
|
||||
class settings(ifcopenshell_wrapper.SerializerSettings):
|
||||
if has_occ:
|
||||
USE_PYTHON_OPENCASCADE = -1
|
||||
@@ -245,32 +246,35 @@ def make_shape_function(fn):
|
||||
serialise = make_shape_function(ifcopenshell_wrapper.serialise)
|
||||
tesselate = make_shape_function(ifcopenshell_wrapper.tesselate)
|
||||
|
||||
|
||||
def wrap_buffer_creation(fn):
|
||||
"""
|
||||
"""
|
||||
Python does not have automatic casts. The C++ serializers accept a stream_or_filename
|
||||
which in C++ can be automatically constructed from a filename string. In Python we
|
||||
have to implement this cast/construction explicitly.
|
||||
"""
|
||||
|
||||
|
||||
def transform_string(v):
|
||||
if isinstance(v, str):
|
||||
return ifcopenshell_wrapper.buffer(v)
|
||||
else:
|
||||
return v
|
||||
|
||||
def inner(*args):
|
||||
return fn(*map(transform_string, args))
|
||||
|
||||
return inner
|
||||
|
||||
|
||||
serializer_dict = {}
|
||||
serializer_dict['obj'] = wrap_buffer_creation(ifcopenshell_wrapper.WaveFrontOBJSerializer)
|
||||
serializer_dict['svg'] = wrap_buffer_creation(ifcopenshell_wrapper.SvgSerializer)
|
||||
serializer_dict['buffer'] = ifcopenshell_wrapper.buffer
|
||||
serializer_dict["obj"] = wrap_buffer_creation(ifcopenshell_wrapper.WaveFrontOBJSerializer)
|
||||
serializer_dict["svg"] = wrap_buffer_creation(ifcopenshell_wrapper.SvgSerializer)
|
||||
serializer_dict["buffer"] = ifcopenshell_wrapper.buffer
|
||||
try:
|
||||
# HdfSerializer doesn't support writing to a buffer (obviously) only to filename
|
||||
# so no wrap_buffer_creation()
|
||||
serializer_dict['hdf5'] = ifcopenshell_wrapper.HdfSerializer
|
||||
except: pass
|
||||
|
||||
serializers = type('serializers', (), serializer_dict)
|
||||
serializer_dict["hdf5"] = ifcopenshell_wrapper.HdfSerializer
|
||||
except:
|
||||
pass
|
||||
|
||||
serializers = type("serializers", (), serializer_dict)
|
||||
|
||||
@@ -86,7 +86,7 @@ class Migrator:
|
||||
"TransverseBarSpacing": 1,
|
||||
# Manual additions from experience
|
||||
"InteriorOrExteriorSpace": "NOTDEFINED",
|
||||
"AssemblyPlace": "NOTDEFINED", # See bug https://github.com/Autodesk/revit-ifc/issues/395
|
||||
"AssemblyPlace": "NOTDEFINED", # See bug https://github.com/Autodesk/revit-ifc/issues/395
|
||||
}
|
||||
self.default_entities = {
|
||||
"CurrentValue": None,
|
||||
|
||||
Reference in New Issue
Block a user