mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 10:06:47 +00:00
initial commit
-Added support for adding and editing enums -changed behaviour of template psets that have enums.
This commit is contained in:
@@ -94,13 +94,15 @@ class Data:
|
||||
elif hasattr(pset, "Properties"):
|
||||
props = pset.Properties or []
|
||||
# TODO: support more than single values
|
||||
data["Properties"] = [p.id() for p in props if p.is_a("IfcPropertySingleValue")]
|
||||
data["Properties"] = [p.id() for p in props if p.is_a("IfcPropertyEnumeratedValue") or p.is_a("IfcPropertySingleValue")]
|
||||
cls.psets[pset.id()] = data
|
||||
cls.products[product_id]["psets"].add(pset.id())
|
||||
for prop in props:
|
||||
# TODO: support more than single values
|
||||
if prop.is_a("IfcPropertySingleValue"):
|
||||
cls.load_prop(prop)
|
||||
elif prop.is_a("IfcPropertyEnumeratedValue"):
|
||||
cls.load_prop_enum(prop)
|
||||
|
||||
@classmethod
|
||||
def load_prop(cls, prop):
|
||||
@@ -116,7 +118,14 @@ class Data:
|
||||
# For convenience, which trumps correctness in this case
|
||||
data["NominalValue"] = prop[3]
|
||||
cls.properties[prop.id()] = data
|
||||
|
||||
|
||||
@classmethod
|
||||
def load_prop_enum(cls, prop):
|
||||
data = prop.get_info()
|
||||
enumerations = [enum.wrappedValue for enum in data["EnumerationValues"]]
|
||||
data["NominalValue"] = str(enumerations)
|
||||
cls.properties[prop.id()] = data
|
||||
|
||||
@classmethod
|
||||
def add_qto(cls, qto, product_id):
|
||||
data = qto.get_info()
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from distutils.command.sdist import sdist
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.pset
|
||||
|
||||
@@ -46,11 +47,40 @@ class Usecase:
|
||||
self.psetqto = ifcopenshell.util.pset.get_template("IFC4")
|
||||
self.pset_template = self.psetqto.get_by_name(self.settings["pset"].Name)
|
||||
|
||||
#TODO - Add support for changing property types?
|
||||
# For example - IfcPropertyEnumeratedValue to
|
||||
# IfcPropertySingleValue. Or maybe the user should
|
||||
# just delete the property first? - vulevukusej
|
||||
def update_existing_properties(self):
|
||||
for prop in self.get_properties():
|
||||
self.update_existing_property(prop)
|
||||
if prop.is_a("IfcPropertyEnumeratedValue"):
|
||||
self.update_existing_enum(prop)
|
||||
else:
|
||||
self.update_existing_property(prop)
|
||||
|
||||
def update_existing_enum(self, prop):
|
||||
if prop.Name not in self.settings["properties"]:
|
||||
return
|
||||
value = self.settings["properties"][prop.Name]
|
||||
if isinstance(value, list):
|
||||
sel_vals = []
|
||||
for val in value:
|
||||
primary_measure_type = prop.EnumerationReference.EnumerationValues[0].is_a() #Only need the first enum type since all enums are of the same type
|
||||
ifc_val = self.file.create_entity(primary_measure_type, val)
|
||||
sel_vals.append(ifc_val)
|
||||
prop.EnumerationValues = tuple(sel_vals)
|
||||
|
||||
def update_existing_property(self, prop):
|
||||
else:
|
||||
if value.EnumerationReference.EnumerationValues == ():
|
||||
prop.EnumerationReference.EnumerationValues = ()
|
||||
prop.EnumerationValues = ()
|
||||
|
||||
elif isinstance(value, ifcopenshell.entity_instance):
|
||||
prop.EnumerationReference.EnumerationValues = value.EnumerationReference.EnumerationValues
|
||||
prop.EnumerationValues = value.EnumerationValues
|
||||
del self.settings["properties"][prop.Name]
|
||||
|
||||
def update_existing_property(self, prop):
|
||||
if prop.Name not in self.settings["properties"]:
|
||||
return
|
||||
value = self.settings["properties"][prop.Name]
|
||||
@@ -73,16 +103,36 @@ class Usecase:
|
||||
continue
|
||||
if isinstance(value, ifcopenshell.entity_instance):
|
||||
nominal_value = value
|
||||
if value.is_a(True) == "IFC4.IfcPropertyEnumeratedValue":
|
||||
properties.append(value)
|
||||
#TODO-The following "elif" is temporary code, will need to refactor at some point - vulevukusej
|
||||
elif isinstance(value, list):
|
||||
for pset_template in self.settings["pset_template"].HasPropertyTemplates:
|
||||
if pset_template.Name == name:
|
||||
prop_enum = self.file.create_entity(
|
||||
"IFCPROPERTYENUMERATION",
|
||||
Name=name,
|
||||
EnumerationValues=pset_template.Enumerators.EnumerationValues
|
||||
)
|
||||
prop_enum_value = self.file.create_entity(
|
||||
"IFCPROPERTYENUMERATEDVALUE",
|
||||
Name=name,
|
||||
EnumerationValues=tuple(self.file.create_entity(
|
||||
pset_template.PrimaryMeasureType, v) for v in value),
|
||||
EnumerationReference=prop_enum
|
||||
)
|
||||
properties.append(prop_enum_value)
|
||||
else:
|
||||
primary_measure_type = self.get_primary_measure_type(name, new_value=value)
|
||||
value = self.cast_value_to_primary_measure_type(value, primary_measure_type)
|
||||
nominal_value = self.file.create_entity(primary_measure_type, value)
|
||||
properties.append(
|
||||
self.file.create_entity(
|
||||
"IfcPropertySingleValue",
|
||||
**{"Name": name, "NominalValue": nominal_value},
|
||||
|
||||
properties.append(
|
||||
self.file.create_entity(
|
||||
"IfcPropertySingleValue",
|
||||
**{"Name": name, "NominalValue": nominal_value},
|
||||
)
|
||||
)
|
||||
)
|
||||
return properties
|
||||
|
||||
def extend_pset_with_new_properties(self, new_properties):
|
||||
|
||||
Submodule src/ifcopenshell-python/ifcopenshell/mvd updated: 83c12fa494...667894b629
@@ -80,6 +80,13 @@ def get_properties(properties):
|
||||
for prop in properties or []:
|
||||
if prop.is_a("IfcPropertySingleValue"):
|
||||
results[prop.Name] = prop.NominalValue.wrappedValue if prop.NominalValue else None
|
||||
for enum in prop.EnumerationValues:
|
||||
values.append(enum.wrappedValue)
|
||||
if values:
|
||||
results[prop.Name] = str(values) if len(values)>1 else values[0]
|
||||
else:
|
||||
results[prop.Name] = None
|
||||
|
||||
elif prop.is_a("IfcComplexProperty"):
|
||||
data = {k: v for k, v in prop.get_info().items() if v is not None and k != "Name"}
|
||||
data["properties"] = get_properties(prop.HasProperties)
|
||||
|
||||
Reference in New Issue
Block a user