diff --git a/src/ifcopenshell-python/ifcopenshell/api/layer/__init__.py b/src/ifcopenshell-python/ifcopenshell/api/layer/__init__.py index 156f0ea551..f55668b15f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/layer/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/api/layer/__init__.py @@ -27,6 +27,7 @@ If you want to associated a whole element to a "layer", consider using from .. import wrap_usecases from .add_layer import add_layer +from .add_layer_with_style import add_layer_with_style from .assign_layer import assign_layer from .edit_layer import edit_layer from .remove_layer import remove_layer @@ -36,6 +37,7 @@ wrap_usecases(__path__, __name__) __all__ = [ "add_layer", + "add_layer_with_style", "assign_layer", "edit_layer", "remove_layer", diff --git a/src/ifcopenshell-python/ifcopenshell/api/layer/add_layer.py b/src/ifcopenshell-python/ifcopenshell/api/layer/add_layer.py index a502c7fd56..8a3c1dc95f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/layer/add_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/layer/add_layer.py @@ -35,9 +35,7 @@ def add_layer(file: ifcopenshell.file, name: str = "Unnamed") -> ifcopenshell.en may also use this layer information for filtering. :param name: The name of the layer. Defaults to "Unnamed". - :type name: str, optional :return: The newly created IfcPresentationLayerAssignment element - :rtype: ifcopenshell.entity_instance Example: diff --git a/src/ifcopenshell-python/ifcopenshell/api/layer/add_layer_with_style.py b/src/ifcopenshell-python/ifcopenshell/api/layer/add_layer_with_style.py new file mode 100644 index 0000000000..162bc867e8 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/layer/add_layer_with_style.py @@ -0,0 +1,59 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . +import ifcopenshell +from typing import Union, Literal, Sequence + +IfcLogical = Union[bool, Literal["UNKNOWN"]] + + +def add_layer_with_style( + file: ifcopenshell.file, + name: str = "Unnamed", + on: IfcLogical = "UNKNOWN", + frozen: IfcLogical = "UNKNOWN", + blocked: IfcLogical = "UNKNOWN", + styles: Sequence[ifcopenshell.entity_instance] = (), +) -> ifcopenshell.entity_instance: + """Adds a new layer with style + + :param name: The name of the layer. + :param on: Whether layer is visible. + :param frozen: + :param blocked: Whether layer elements are blocked from manipulation. + :param styles: Styles to be used as default for representation item. + :return: The newly created IfcPresentationLayerWithStyle element + + Example: + + ifcopenshell.api.layer.add_layer_with_style( + model, + name="AI-WALL-FULL-DIMS-N", + on=True, + frozen=False, + blocked=False, + stlyes=[curve_style] + ) + """ + return file.create_entity( + "IfcPresentationLayerWithStyle", + Name=name, + LayerOn=on, + LayerFrozen=frozen, + LayerBlocked=blocked, + LayerStyles=styles, + ) diff --git a/src/ifcopenshell-python/ifcopenshell/api/layer/assign_layer.py b/src/ifcopenshell-python/ifcopenshell/api/layer/assign_layer.py index 366f1a5728..5c4f3ee6e3 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/layer/assign_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/layer/assign_layer.py @@ -33,12 +33,9 @@ def assign_layer( :param items: The list of IfcRepresentationItems to assign to the layer. This should be the items from the object's IfcShapeRepresentation. - :type items: list[ifcopenshell.entity_instance] :param layer: The IfcPresentationLayerAssignment layer to assign the item to. - :type layer: ifcopenshell.entity_instance :return: None - :rtype: None Example: diff --git a/src/ifcopenshell-python/ifcopenshell/api/layer/edit_layer.py b/src/ifcopenshell-python/ifcopenshell/api/layer/edit_layer.py index edeb22c1de..6f55f5da1d 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/layer/edit_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/layer/edit_layer.py @@ -26,11 +26,8 @@ def edit_layer(file: ifcopenshell.file, layer: ifcopenshell.entity_instance, att IfcPresentationLayerAssignment, consult the IFC documentation. :param layer: The IfcPresentationLayerAssignment entity you want to edit - :type layer: ifcopenshell.entity_instance :param attributes: a dictionary of attribute names and values. - :type attributes: dict :return: None - :rtype: None Example: diff --git a/src/ifcopenshell-python/ifcopenshell/api/layer/remove_layer.py b/src/ifcopenshell-python/ifcopenshell/api/layer/remove_layer.py index 6fe38bf9ee..e0ae5e3604 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/layer/remove_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/layer/remove_layer.py @@ -25,9 +25,7 @@ def remove_layer(file: ifcopenshell.file, layer: ifcopenshell.entity_instance) - relationship to the layer will be removed. :param layer: The IfcPresentationLayerAssignment entity to remove - :type layer: ifcopenshell.entity_instance :return: None - :rtype: None Example: diff --git a/src/ifcopenshell-python/ifcopenshell/api/layer/unassign_layer.py b/src/ifcopenshell-python/ifcopenshell/api/layer/unassign_layer.py index fe4f13793e..8fe93d3a91 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/layer/unassign_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/layer/unassign_layer.py @@ -31,11 +31,8 @@ def unassign_layer( removed to keep IFC valid. :param items: A list IfcRepresentationItem elements to unassign - :type items: list[ifcopenshell.entity_instance] :param layer: The IfcPresentationLayerAssignment to unassign from - :type layer: ifcopenshell.entity_instance :return: None - :rtype: None Example: diff --git a/src/ifcopenshell-python/test/api/layer/test_add_layer_with_style.py b/src/ifcopenshell-python/test/api/layer/test_add_layer_with_style.py new file mode 100644 index 0000000000..0395e40178 --- /dev/null +++ b/src/ifcopenshell-python/test/api/layer/test_add_layer_with_style.py @@ -0,0 +1,45 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . + +import test.bootstrap +import ifcopenshell.api.layer + + +class TestAddLayerWithStyle(test.bootstrap.IFC4): + def test_add_layer_no_arguments(self): + layer = ifcopenshell.api.layer.add_layer_with_style(self.file) + assert layer.Name == "Unnamed" + assert layer.LayerOn == "UNKNOWN" + assert layer.LayerFrozen == "UNKNOWN" + assert layer.LayerBlocked == "UNKNOWN" + assert layer.LayerStyles == () + + def test_assign_all_arguments(self): + curve_style = self.file.create_entity("IfcCurveStyle") + layer = ifcopenshell.api.layer.add_layer_with_style( + self.file, name="Name", on=True, frozen=True, blocked=True, styles=(curve_style,) + ) + assert layer.Name == "Name" + assert layer.LayerOn == True + assert layer.LayerFrozen == True + assert layer.LayerBlocked == True + assert layer.LayerStyles == (curve_style,) + + +class TestAddLayerWithStyleIFC2X3(test.bootstrap.IFC2X3, TestAddLayerWithStyle): + pass