mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
Run black on existing entity_instance
This commit is contained in:
@@ -23,7 +23,8 @@ table below.
|
|||||||
| .ifc | .ifcJSON | Ifc2JSON_ |
|
| .ifc | .ifcJSON | Ifc2JSON_ |
|
||||||
+-------------------------+-------------------------+----------------------+
|
+-------------------------+-------------------------+----------------------+
|
||||||
| .ifc | .ifc | IfcPatch_ |
|
| .ifc | .ifc | IfcPatch_ |
|
||||||
| | (IFC2X3, IFC4, IFC4X3) | |
|
| | (IFC2X3, IFC4, IFC4X3), | |
|
||||||
|
| | SQLite, MySQL | |
|
||||||
+-------------------------+-------------------------+----------------------+
|
+-------------------------+-------------------------+----------------------+
|
||||||
| .ifc | .json (Code_Aster), | Ifc2CA_ |
|
| .ifc | .json (Code_Aster), | Ifc2CA_ |
|
||||||
| | .comm (Code_Aster) | |
|
| | .comm (Code_Aster) | |
|
||||||
@@ -33,7 +34,8 @@ table below.
|
|||||||
+-------------------------+-------------------------+----------------------+
|
+-------------------------+-------------------------+----------------------+
|
||||||
| .ifc | .csv, .ods, .xlsx | Ifc5D_ |
|
| .ifc | .csv, .ods, .xlsx | Ifc5D_ |
|
||||||
+-------------------------+-------------------------+----------------------+
|
+-------------------------+-------------------------+----------------------+
|
||||||
| .ifc | .csv, .ods, .xlsx | IfcCSV_ |
|
| .ifc | .csv, .ods, .xlsx, | IfcCSV_ |
|
||||||
|
| | Pandas DataFrame | |
|
||||||
+-------------------------+-------------------------+----------------------+
|
+-------------------------+-------------------------+----------------------+
|
||||||
| .csv | .ifc | Ifc5D_ |
|
| .csv | .ifc | Ifc5D_ |
|
||||||
+-------------------------+-------------------------+----------------------+
|
+-------------------------+-------------------------+----------------------+
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ except ImportError as e:
|
|||||||
def set_derived_attribute(*args):
|
def set_derived_attribute(*args):
|
||||||
raise TypeError("Unable to set derived attribute")
|
raise TypeError("Unable to set derived attribute")
|
||||||
|
|
||||||
|
|
||||||
def set_unsupported_attribute(*args):
|
def set_unsupported_attribute(*args):
|
||||||
raise TypeError("This is an unsupported attribute type")
|
raise TypeError("This is an unsupported attribute type")
|
||||||
|
|
||||||
@@ -83,8 +83,7 @@ def register_schema_attributes(schema):
|
|||||||
functions = [
|
functions = [
|
||||||
set_derived_attribute
|
set_derived_attribute
|
||||||
if mname == "setArgumentAsDerived"
|
if mname == "setArgumentAsDerived"
|
||||||
else
|
else set_unsupported_attribute
|
||||||
set_unsupported_attribute
|
|
||||||
if mname == "setArgumentAsUnknown"
|
if mname == "setArgumentAsUnknown"
|
||||||
else getattr(ifcopenshell_wrapper.entity_instance, mname)
|
else getattr(ifcopenshell_wrapper.entity_instance, mname)
|
||||||
for mname in fn_names
|
for mname in fn_names
|
||||||
@@ -139,18 +138,12 @@ class entity_instance(object):
|
|||||||
idx = self.wrapped_data.get_argument_index(name)
|
idx = self.wrapped_data.get_argument_index(name)
|
||||||
if _method_dict[self.is_a(True)][idx] != set_derived_attribute:
|
if _method_dict[self.is_a(True)][idx] != set_derived_attribute:
|
||||||
# A bit ugly, but we fall through to derived attribute handling below
|
# A bit ugly, but we fall through to derived attribute handling below
|
||||||
return entity_instance.wrap_value(
|
return entity_instance.wrap_value(self.wrapped_data.get_argument(idx), self.wrapped_data.file)
|
||||||
self.wrapped_data.get_argument(idx), self.wrapped_data.file
|
|
||||||
)
|
|
||||||
elif attr_cat == INVERSE:
|
elif attr_cat == INVERSE:
|
||||||
vs = entity_instance.wrap_value(
|
vs = entity_instance.wrap_value(self.wrapped_data.get_inverse(name), self.wrapped_data.file)
|
||||||
self.wrapped_data.get_inverse(name), self.wrapped_data.file
|
|
||||||
)
|
|
||||||
if settings.unpack_non_aggregate_inverses:
|
if settings.unpack_non_aggregate_inverses:
|
||||||
schema_name = self.wrapped_data.is_a(True).split(".")[0]
|
schema_name = self.wrapped_data.is_a(True).split(".")[0]
|
||||||
ent = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
|
ent = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
|
||||||
self.is_a()
|
|
||||||
)
|
|
||||||
inv = [i for i in ent.all_inverse_attributes() if i.name() == name][0]
|
inv = [i for i in ent.all_inverse_attributes() if i.name() == name][0]
|
||||||
if (inv.bound1(), inv.bound2()) == (-1, -1):
|
if (inv.bound1(), inv.bound2()) == (-1, -1):
|
||||||
if vs:
|
if vs:
|
||||||
@@ -164,9 +157,7 @@ class entity_instance(object):
|
|||||||
rules = importlib.import_module(f"ifcopenshell.express.rules.{schema_name}")
|
rules = importlib.import_module(f"ifcopenshell.express.rules.{schema_name}")
|
||||||
|
|
||||||
def yield_supertypes():
|
def yield_supertypes():
|
||||||
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
|
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
|
||||||
self.is_a()
|
|
||||||
)
|
|
||||||
while decl:
|
while decl:
|
||||||
yield decl.name()
|
yield decl.name()
|
||||||
decl = decl.supertype()
|
decl = decl.supertype()
|
||||||
@@ -178,8 +169,7 @@ class entity_instance(object):
|
|||||||
|
|
||||||
if attr_cat != FORWARD:
|
if attr_cat != FORWARD:
|
||||||
raise AttributeError(
|
raise AttributeError(
|
||||||
"entity instance of type '%s' has no attribute '%s'"
|
"entity instance of type '%s' has no attribute '%s'" % (self.wrapped_data.is_a(True), name)
|
||||||
% (self.wrapped_data.is_a(True), name)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -218,11 +208,7 @@ class entity_instance(object):
|
|||||||
:type attr: int
|
:type attr: int
|
||||||
:rtype: string
|
:rtype: string
|
||||||
"""
|
"""
|
||||||
attr_idx = (
|
attr_idx = attr if isinstance(attr, numbers.Integral) else self.wrapped_data.get_argument_index(attr)
|
||||||
attr
|
|
||||||
if isinstance(attr, numbers.Integral)
|
|
||||||
else self.wrapped_data.get_argument_index(attr)
|
|
||||||
)
|
|
||||||
return self.wrapped_data.get_argument_type(attr_idx)
|
return self.wrapped_data.get_argument_type(attr_idx)
|
||||||
|
|
||||||
def attribute_name(self, attr_idx):
|
def attribute_name(self, attr_idx):
|
||||||
@@ -240,23 +226,15 @@ class entity_instance(object):
|
|||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
if key < 0 or key >= len(self):
|
if key < 0 or key >= len(self):
|
||||||
raise IndexError(
|
raise IndexError("Attribute index {} out of range for instance of type {}".format(key, self.is_a()))
|
||||||
"Attribute index {} out of range for instance of type {}".format(
|
return entity_instance.wrap_value(self.wrapped_data.get_argument(key), self.wrapped_data.file)
|
||||||
key, self.is_a()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return entity_instance.wrap_value(
|
|
||||||
self.wrapped_data.get_argument(key), self.wrapped_data.file
|
|
||||||
)
|
|
||||||
|
|
||||||
def __setitem__(self, idx, value):
|
def __setitem__(self, idx, value):
|
||||||
if self.wrapped_data.file and self.wrapped_data.file.transaction:
|
if self.wrapped_data.file and self.wrapped_data.file.transaction:
|
||||||
self.wrapped_data.file.transaction.store_edit(self, idx, value)
|
self.wrapped_data.file.transaction.store_edit(self, idx, value)
|
||||||
|
|
||||||
if self.method_list is None:
|
if self.method_list is None:
|
||||||
super(entity_instance, self).__setattr__(
|
super(entity_instance, self).__setattr__("method_list", _method_dict[self.is_a(True)])
|
||||||
"method_list", _method_dict[self.is_a(True)]
|
|
||||||
)
|
|
||||||
|
|
||||||
method = self.method_list[idx]
|
method = self.method_list[idx]
|
||||||
|
|
||||||
@@ -264,9 +242,7 @@ class entity_instance(object):
|
|||||||
if method is not set_derived_attribute:
|
if method is not set_derived_attribute:
|
||||||
self.wrapped_data.setArgumentAsNull(idx)
|
self.wrapped_data.setArgumentAsNull(idx)
|
||||||
else:
|
else:
|
||||||
self.method_list[idx](
|
self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value))
|
||||||
self.wrapped_data, idx, entity_instance.unwrap_value(value)
|
|
||||||
)
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@@ -323,9 +299,9 @@ class entity_instance(object):
|
|||||||
elif None in (self.wrapped_data.file, other.wrapped_data.file):
|
elif None in (self.wrapped_data.file, other.wrapped_data.file):
|
||||||
# when not added to a file, we can only compare attribute values
|
# when not added to a file, we can only compare attribute values
|
||||||
# and we need this for where rule evaluation
|
# and we need this for where rule evaluation
|
||||||
return self.get_info(
|
return self.get_info(recursive=True, include_identifier=False) == other.get_info(
|
||||||
recursive=True, include_identifier=False
|
recursive=True, include_identifier=False
|
||||||
) == other.get_info(recursive=True, include_identifier=False)
|
)
|
||||||
else:
|
else:
|
||||||
# Proper entity instances have a stable identity by means of the numeric
|
# Proper entity instances have a stable identity by means of the numeric
|
||||||
# step id. Selected type instances (such as IfcPropertySingleValue.NominalValue
|
# step id. Selected type instances (such as IfcPropertySingleValue.NominalValue
|
||||||
@@ -346,9 +322,7 @@ class entity_instance(object):
|
|||||||
bool: True if the instance is an entity
|
bool: True if the instance is an entity
|
||||||
"""
|
"""
|
||||||
schema_name = self.wrapped_data.is_a(True).split(".")[0]
|
schema_name = self.wrapped_data.is_a(True).split(".")[0]
|
||||||
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
|
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
|
||||||
self.is_a()
|
|
||||||
)
|
|
||||||
return isinstance(decl, ifcopenshell_wrapper.entity)
|
return isinstance(decl, ifcopenshell_wrapper.entity)
|
||||||
|
|
||||||
def compare(self, other, op, reverse=False):
|
def compare(self, other, op, reverse=False):
|
||||||
@@ -436,9 +410,7 @@ class entity_instance(object):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_info(
|
def get_info(self, include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False):
|
||||||
self, include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False
|
|
||||||
):
|
|
||||||
"""Return a dictionary of the entity_instance's properties (Python and IFC) and their values.
|
"""Return a dictionary of the entity_instance's properties (Python and IFC) and their values.
|
||||||
|
|
||||||
:param include_identifier: Whether or not to include the STEP numerical identifier
|
:param include_identifier: Whether or not to include the STEP numerical identifier
|
||||||
@@ -472,18 +444,14 @@ class entity_instance(object):
|
|||||||
yield "id", self.id()
|
yield "id", self.id()
|
||||||
yield "type", self.is_a()
|
yield "type", self.is_a()
|
||||||
except BaseException:
|
except BaseException:
|
||||||
logging.exception(
|
logging.exception("unhandled exception while getting id / type info on {}".format(self))
|
||||||
"unhandled exception while getting id / type info on {}".format(
|
|
||||||
self
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for i in range(len(self)):
|
for i in range(len(self)):
|
||||||
try:
|
try:
|
||||||
if self.wrapped_data.get_attribute_names()[i] in ignore:
|
if self.wrapped_data.get_attribute_names()[i] in ignore:
|
||||||
continue
|
continue
|
||||||
attr_value = self[i]
|
attr_value = self[i]
|
||||||
|
|
||||||
to_include = {'v': True}
|
to_include = {"v": True}
|
||||||
|
|
||||||
if recursive or scalar_only:
|
if recursive or scalar_only:
|
||||||
|
|
||||||
@@ -500,29 +468,23 @@ class entity_instance(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def do_ignore(inst):
|
def do_ignore(inst):
|
||||||
to_include['v'] = False
|
to_include["v"] = False
|
||||||
return None
|
return None
|
||||||
|
|
||||||
attr_value = entity_instance.walk(
|
attr_value = entity_instance.walk(
|
||||||
is_instance, get_info_ if recursive else do_ignore, attr_value
|
is_instance, get_info_ if recursive else do_ignore, attr_value
|
||||||
)
|
)
|
||||||
|
|
||||||
if to_include['v']:
|
if to_include["v"]:
|
||||||
yield self.attribute_name(i), attr_value
|
yield self.attribute_name(i), attr_value
|
||||||
except BaseException:
|
except BaseException:
|
||||||
logging.exception(
|
logging.exception("unhandled exception occurred setting attribute name for {}".format(self))
|
||||||
"unhandled exception occurred setting attribute name for {}".format(
|
|
||||||
self
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return return_type(_())
|
return return_type(_())
|
||||||
|
|
||||||
__dict__ = property(get_info)
|
__dict__ = property(get_info)
|
||||||
|
|
||||||
def get_info_2(
|
def get_info_2(self, include_identifier=True, recursive=False, return_type=dict, ignore=()):
|
||||||
self, include_identifier=True, recursive=False, return_type=dict, ignore=()
|
|
||||||
):
|
|
||||||
assert include_identifier
|
assert include_identifier
|
||||||
assert recursive
|
assert recursive
|
||||||
assert return_type is dict
|
assert return_type is dict
|
||||||
|
|||||||
Reference in New Issue
Block a user