mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-13 06:53:36 +00:00
Allow for custom IfcUnits when editing psets
This commit is contained in:
committed by
Dion Moult
parent
c9f52d2f8e
commit
fab7b590f7
@@ -189,6 +189,7 @@ class Usecase:
|
|||||||
if prop.Name not in self.settings["properties"]:
|
if prop.Name not in self.settings["properties"]:
|
||||||
return
|
return
|
||||||
value = self.settings["properties"][prop.Name]
|
value = self.settings["properties"][prop.Name]
|
||||||
|
unit, value = self.unpack_unit_value(value)
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
sel_vals = []
|
sel_vals = []
|
||||||
for val in value:
|
for val in value:
|
||||||
@@ -210,12 +211,15 @@ class Usecase:
|
|||||||
elif isinstance(value, ifcopenshell.entity_instance):
|
elif isinstance(value, ifcopenshell.entity_instance):
|
||||||
prop.EnumerationReference.EnumerationValues = value.EnumerationReference.EnumerationValues
|
prop.EnumerationReference.EnumerationValues = value.EnumerationReference.EnumerationValues
|
||||||
prop.EnumerationValues = value.EnumerationValues
|
prop.EnumerationValues = value.EnumerationValues
|
||||||
|
if unit:
|
||||||
|
prop.Unit = unit
|
||||||
del self.settings["properties"][prop.Name]
|
del self.settings["properties"][prop.Name]
|
||||||
|
|
||||||
def update_existing_property(self, prop):
|
def update_existing_property(self, prop):
|
||||||
if prop.Name not in self.settings["properties"]:
|
if prop.Name not in self.settings["properties"]:
|
||||||
return
|
return
|
||||||
value = self.settings["properties"][prop.Name]
|
value = self.settings["properties"][prop.Name]
|
||||||
|
unit, value = self.unpack_unit_value(value)
|
||||||
if value is None:
|
if value is None:
|
||||||
if self.settings["should_purge"]:
|
if self.settings["should_purge"]:
|
||||||
del self.settings["properties"][prop.Name]
|
del self.settings["properties"][prop.Name]
|
||||||
@@ -230,6 +234,8 @@ class Usecase:
|
|||||||
)
|
)
|
||||||
value = self.cast_value_to_primary_measure_type(value, primary_measure_type)
|
value = self.cast_value_to_primary_measure_type(value, primary_measure_type)
|
||||||
prop.NominalValue = self.file.create_entity(primary_measure_type, value)
|
prop.NominalValue = self.file.create_entity(primary_measure_type, value)
|
||||||
|
if unit:
|
||||||
|
prop.Unit = unit
|
||||||
del self.settings["properties"][prop.Name]
|
del self.settings["properties"][prop.Name]
|
||||||
|
|
||||||
def add_new_properties(self):
|
def add_new_properties(self):
|
||||||
@@ -237,16 +243,17 @@ class Usecase:
|
|||||||
for name, value in self.settings["properties"].items():
|
for name, value in self.settings["properties"].items():
|
||||||
if value is None:
|
if value is None:
|
||||||
continue
|
continue
|
||||||
|
unit, value = self.unpack_unit_value(value)
|
||||||
if isinstance(value, ifcopenshell.entity_instance):
|
if isinstance(value, ifcopenshell.entity_instance):
|
||||||
if value.is_a(True) == "IFC4.IfcPropertyEnumeratedValue":
|
if value.is_a(True) == "IFC4.IfcPropertyEnumeratedValue":
|
||||||
properties.append(value)
|
properties.append(value)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
args = {"Name": name, "NominalValue": value}
|
||||||
|
if unit:
|
||||||
|
args["Unit"] = unit
|
||||||
properties.append(
|
properties.append(
|
||||||
self.file.create_entity(
|
self.file.create_entity("IfcPropertySingleValue", **args)
|
||||||
"IfcPropertySingleValue",
|
|
||||||
**{"Name": name, "NominalValue": value},
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# TODO-The following "elif" is temporary code, will need to refactor at some point - vulevukusej
|
# TODO-The following "elif" is temporary code, will need to refactor at some point - vulevukusej
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
@@ -256,6 +263,7 @@ class Usecase:
|
|||||||
"IFCPROPERTYENUMERATION",
|
"IFCPROPERTYENUMERATION",
|
||||||
Name=name,
|
Name=name,
|
||||||
EnumerationValues=pset_template.Enumerators.EnumerationValues,
|
EnumerationValues=pset_template.Enumerators.EnumerationValues,
|
||||||
|
**({"Unit": unit} if unit else {})
|
||||||
)
|
)
|
||||||
prop_enum_value = self.file.create_entity(
|
prop_enum_value = self.file.create_entity(
|
||||||
"IFCPROPERTYENUMERATEDVALUE",
|
"IFCPROPERTYENUMERATEDVALUE",
|
||||||
@@ -271,12 +279,12 @@ class Usecase:
|
|||||||
primary_measure_type = self.get_primary_measure_type(name, new_value=value)
|
primary_measure_type = self.get_primary_measure_type(name, new_value=value)
|
||||||
value = self.cast_value_to_primary_measure_type(value, primary_measure_type)
|
value = self.cast_value_to_primary_measure_type(value, primary_measure_type)
|
||||||
nominal_value = self.file.create_entity(primary_measure_type, value)
|
nominal_value = self.file.create_entity(primary_measure_type, value)
|
||||||
|
args = {"Name": name, "NominalValue": nominal_value}
|
||||||
|
if unit:
|
||||||
|
args["Unit"] = unit
|
||||||
|
|
||||||
properties.append(
|
properties.append(
|
||||||
self.file.create_entity(
|
self.file.create_entity("IfcPropertySingleValue", **args)
|
||||||
"IfcPropertySingleValue",
|
|
||||||
**{"Name": name, "NominalValue": nominal_value},
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return properties
|
return properties
|
||||||
|
|
||||||
@@ -332,3 +340,13 @@ class Usecase:
|
|||||||
elif type_str == "AGGREGATE OF INT":
|
elif type_str == "AGGREGATE OF INT":
|
||||||
return [int(i) for i in value]
|
return [int(i) for i in value]
|
||||||
return type_fn(value)
|
return type_fn(value)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def unpack_unit_value(value_candidate):
|
||||||
|
unit = None
|
||||||
|
if isinstance(value_candidate, dict): # Custom IfcUnits can be passed in a dict along with the pset value
|
||||||
|
unit = value_candidate["Unit"]
|
||||||
|
value = value_candidate["NominalValue"]
|
||||||
|
else:
|
||||||
|
value = value_candidate
|
||||||
|
return unit, value
|
||||||
|
|||||||
Reference in New Issue
Block a user