mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Fix bug where removing material set items weren't consistent in how they purged materials and profiles
Previously remove_profile would purge unused materials and profiles, but remove_layer and remove_constituent wouldn't. This was as subtle inconsitency. Now everything by default consistently retains materials and profiles, and has options to change this default.
This commit is contained in:
@@ -314,7 +314,7 @@ class RemoveConstituent(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
if len(material_set.MaterialConstituents) == 1:
|
if len(material_set.MaterialConstituents) == 1:
|
||||||
self.report({"ERROR"}, "At least one constituent must exist")
|
self.report({"ERROR"}, "At least one constituent must exist")
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
ifcopenshell.api.run("material.remove_constituent", tool.Ifc.get(), constituent=constituent)
|
ifcopenshell.api.material.remove_constituent(tool.Ifc.get(), constituent=constituent)
|
||||||
|
|
||||||
|
|
||||||
class AddProfile(bpy.types.Operator, tool.Ifc.Operator):
|
class AddProfile(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -349,7 +349,7 @@ class RemoveProfile(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
if len(material_set.MaterialProfiles) == 1:
|
if len(material_set.MaterialProfiles) == 1:
|
||||||
self.report({"ERROR"}, "At least one profile must exist")
|
self.report({"ERROR"}, "At least one profile must exist")
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
ifcopenshell.api.run("material.remove_profile", tool.Ifc.get(), profile=profile)
|
ifcopenshell.api.material.remove_profile(tool.Ifc.get(), profile=profile)
|
||||||
|
|
||||||
|
|
||||||
class AddLayer(bpy.types.Operator, tool.Ifc.Operator):
|
class AddLayer(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -410,7 +410,7 @@ class RemoveLayer(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
if len(material_set.MaterialLayers) == 1:
|
if len(material_set.MaterialLayers) == 1:
|
||||||
self.report({"ERROR"}, "At least one layer must exist")
|
self.report({"ERROR"}, "At least one layer must exist")
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
ifcopenshell.api.run("material.remove_layer", tool.Ifc.get(), layer=layer)
|
ifcopenshell.api.material.remove_layer(tool.Ifc.get(), layer=layer)
|
||||||
for material_set in material_sets:
|
for material_set in material_sets:
|
||||||
slab.DumbSlabPlaner().regenerate_from_layer_set(material_set)
|
slab.DumbSlabPlaner().regenerate_from_layer_set(material_set)
|
||||||
wall.DumbWallPlaner().regenerate_from_layer_set(material_set)
|
wall.DumbWallPlaner().regenerate_from_layer_set(material_set)
|
||||||
|
|||||||
@@ -18,16 +18,16 @@
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
|
||||||
|
|
||||||
def remove_constituent(file: ifcopenshell.file, constituent: ifcopenshell.entity_instance) -> None:
|
def remove_constituent(
|
||||||
|
file: ifcopenshell.file, constituent: ifcopenshell.entity_instance, should_remove_material: bool = False
|
||||||
|
) -> None:
|
||||||
"""Removes a constituent from a constituent set
|
"""Removes a constituent from a constituent set
|
||||||
|
|
||||||
Note that it is invalid to have zero items in a set, so you should leave
|
Note that it is invalid to have zero items in a set, so you should leave
|
||||||
at least one constituent to ensure a valid IFC dataset.
|
at least one constituent to ensure a valid IFC dataset.
|
||||||
|
|
||||||
:param constituent: The IfcMaterialConstituent entity you want to remove
|
:param constituent: The IfcMaterialConstituent entity you want to remove
|
||||||
:type constituent: ifcopenshell.entity_instance
|
:param should_remove_material: If true, materials with no users will be removed
|
||||||
:return: None
|
|
||||||
:rtype: None
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -51,6 +51,7 @@ def remove_constituent(file: ifcopenshell.file, constituent: ifcopenshell.entity
|
|||||||
# invalid.
|
# invalid.
|
||||||
ifcopenshell.api.material.remove_constituent(model, constituent=glazing)
|
ifcopenshell.api.material.remove_constituent(model, constituent=glazing)
|
||||||
"""
|
"""
|
||||||
settings = {"constituent": constituent}
|
material = layer.Material
|
||||||
|
file.remove(constituent)
|
||||||
file.remove(settings["constituent"])
|
if material and should_remove_material:
|
||||||
|
ifcopenshell.util.element.remove_deep2(file, subelement)
|
||||||
|
|||||||
@@ -15,19 +15,19 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
import ifcopenshell
|
import ifcopenshell.util.element
|
||||||
|
|
||||||
|
|
||||||
def remove_layer(file: ifcopenshell.file, layer: ifcopenshell.entity_instance) -> None:
|
def remove_layer(
|
||||||
|
file: ifcopenshell.file, layer: ifcopenshell.entity_instance, should_remove_material: bool = False
|
||||||
|
) -> None:
|
||||||
"""Removes a layer from a layer set
|
"""Removes a layer from a layer set
|
||||||
|
|
||||||
Note that it is invalid to have zero items in a set, so you should leave
|
Note that it is invalid to have zero items in a set, so you should leave
|
||||||
at least one layer to ensure a valid IFC dataset.
|
at least one layer to ensure a valid IFC dataset.
|
||||||
|
|
||||||
:param layer: The IfcMaterialLayer entity you want to remove
|
:param layer: The IfcMaterialLayer entity you want to remove
|
||||||
:type layer: ifcopenshell.entity_instance
|
:param should_remove_material: If true, materials with no users will be removed
|
||||||
:return: None
|
|
||||||
:rtype: None
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ def remove_layer(file: ifcopenshell.file, layer: ifcopenshell.entity_instance) -
|
|||||||
# one one side such as to line a services riser.
|
# one one side such as to line a services riser.
|
||||||
ifcopenshell.api.material.remove_layer(model, layer=layer3)
|
ifcopenshell.api.material.remove_layer(model, layer=layer3)
|
||||||
"""
|
"""
|
||||||
settings = {"layer": layer}
|
material = layer.Material
|
||||||
|
file.remove(layer)
|
||||||
file.remove(settings["layer"])
|
if material and should_remove_material:
|
||||||
|
ifcopenshell.util.element.remove_deep2(file, subelement)
|
||||||
|
|||||||
@@ -17,20 +17,23 @@
|
|||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import ifcopenshell
|
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
|
|
||||||
|
|
||||||
def remove_profile(file: ifcopenshell.file, profile: ifcopenshell.entity_instance) -> None:
|
def remove_profile(
|
||||||
|
file: ifcopenshell.file,
|
||||||
|
profile: ifcopenshell.entity_instance,
|
||||||
|
should_remove_profile_def: bool = False,
|
||||||
|
should_remove_material: bool = False,
|
||||||
|
) -> None:
|
||||||
"""Removes a profile item from a profile set
|
"""Removes a profile item from a profile set
|
||||||
|
|
||||||
Note that it is invalid to have zero items in a set, so you should leave
|
Note that it is invalid to have zero items in a set, so you should leave
|
||||||
at least one profile to ensure a valid IFC dataset.
|
at least one profile to ensure a valid IFC dataset.
|
||||||
|
|
||||||
:param profile: The IfcMaterialProfile entity you want to remove
|
:param profile: The IfcMaterialProfile entity you want to remove
|
||||||
:type profile: ifcopenshell.entity_instance
|
:param should_remove_profile_def: If true, profile defs with no users will be removed
|
||||||
:return: None
|
:param should_remove_material: If true, materials with no users will be removed
|
||||||
:rtype: None
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -64,12 +67,14 @@ def remove_profile(file: ifcopenshell.file, profile: ifcopenshell.entity_instanc
|
|||||||
ifcopenshell.api.material.remove_profile(model, profile=weld_profile)
|
ifcopenshell.api.material.remove_profile(model, profile=weld_profile)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = {"profile": profile}
|
|
||||||
|
|
||||||
subelements = set()
|
subelements = set()
|
||||||
for attribute in settings["profile"]:
|
for attribute in profile:
|
||||||
if isinstance(attribute, ifcopenshell.entity_instance):
|
if isinstance(attribute, ifcopenshell.entity_instance):
|
||||||
subelements.add(attribute)
|
subelements.add(attribute)
|
||||||
file.remove(settings["profile"])
|
file.remove(profile)
|
||||||
for subelement in subelements:
|
for subelement in subelements:
|
||||||
|
if subelement.is_a("IfcMaterial") and not should_remove_material:
|
||||||
|
continue
|
||||||
|
elif subelement.is_a("IfcProfileDef") and not should_remove_profile_def:
|
||||||
|
continue
|
||||||
ifcopenshell.util.element.remove_deep2(file, subelement)
|
ifcopenshell.util.element.remove_deep2(file, subelement)
|
||||||
|
|||||||
Reference in New Issue
Block a user