layer.add_layer_with_style

This commit is contained in:
Andrej730
2025-01-24 13:57:29 +05:00
parent d1082897b1
commit d37caedda7
8 changed files with 106 additions and 13 deletions
@@ -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",
@@ -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:
@@ -0,0 +1,59 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# 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 <http://www.gnu.org/licenses/>.
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,
)
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -0,0 +1,45 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
#
# 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 <http://www.gnu.org/licenses/>.
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