From d7c85b37b5ba7b015ba3e50cfa07826e3f1beaac Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Wed, 20 Nov 2024 13:30:46 +0100 Subject: [PATCH 1/4] removed some unnecessary attributes and methods --- CHANGELOG.md | 5 ++ src/compas_cadwork/datamodel/__init__.py | 2 - src/compas_cadwork/datamodel/dimension.py | 3 +- src/compas_cadwork/datamodel/element.py | 78 +++-------------------- src/compas_cadwork/scene/scene.py | 2 +- src/compas_cadwork/utilities/__init__.py | 8 +-- src/compas_cadwork/utilities/events.py | 2 +- 7 files changed, 20 insertions(+), 80 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c436c2..967eb15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +* Added `Element.is_beam` property. + ### Changed ### Removed +* Removed `ElementType` class. +* Removed `Element.from_id` method. +* Removed `Element.type` property. ## [0.8.0] 2024-11-15 diff --git a/src/compas_cadwork/datamodel/__init__.py b/src/compas_cadwork/datamodel/__init__.py index d8aa1e8..e6f0c69 100644 --- a/src/compas_cadwork/datamodel/__init__.py +++ b/src/compas_cadwork/datamodel/__init__.py @@ -1,5 +1,4 @@ from .element import Element -from .element import ElementType from .element import ElementGroup from .element import ElementGroupingType from .element import ATTR_INSTRUCTION_ID @@ -9,7 +8,6 @@ __all__ = [ "Element", - "ElementType", "ElementGroup", "ElementGroupingType", "ATTR_INSTRUCTION_ID", diff --git a/src/compas_cadwork/datamodel/dimension.py b/src/compas_cadwork/datamodel/dimension.py index 82f66eb..0d77228 100644 --- a/src/compas_cadwork/datamodel/dimension.py +++ b/src/compas_cadwork/datamodel/dimension.py @@ -12,7 +12,6 @@ from compas_cadwork.conversions import vector_to_compas from .element import Element -from .element import ElementType TOL = Tolerance(unit="MM", absolute=1e-3, relative=1e-3) @@ -53,7 +52,7 @@ class Dimension(Element): """Represents a cadwork dimension""" def __init__(self, id): - super().__init__(id, ElementType.DIMENSION) + super().__init__(id) self._frame = None # not lazy-instantiating this so that it can be used to compare the modified instances of the same dimension # otherwise, the anchors values that are compared depend on the time `anchors` was first accessed diff --git a/src/compas_cadwork/datamodel/element.py b/src/compas_cadwork/datamodel/element.py index 07ab1ba..4bc3941 100644 --- a/src/compas_cadwork/datamodel/element.py +++ b/src/compas_cadwork/datamodel/element.py @@ -1,9 +1,7 @@ from __future__ import annotations from dataclasses import dataclass -from enum import Enum from enum import IntEnum -from enum import auto from typing import Generator from typing import List from typing import Optional @@ -13,7 +11,6 @@ import cadwork # noqa: F401 import element_controller as ec import geometry_controller as gc -import utility_controller as uc from compas.geometry import Frame from compas.geometry import Line from compas.geometry import Point @@ -55,45 +52,6 @@ def to_cadwork(self): return cadwork.element_grouping_type(self.value) -class ElementType(str, Enum): - """CADWork Element type""" - - BEAM = auto() # Stab - PLATE = auto() # Platte - SURFACE = auto() - SHAFT = auto() - LINE = auto() - INSTALLATION_ROUND = auto() - INSTALLATION_STRAIGHT = auto() - DIMENSION = auto() - OTHER = auto() - - -ELEMENT_TYPE_MAP = { - "de": { - "Stab": ElementType.BEAM, - "Platte": ElementType.PLATE, - "Achse": ElementType.SHAFT, - "Linie": ElementType.LINE, - "Installation rechteckig": ElementType.INSTALLATION_STRAIGHT, - "Fläche": ElementType.SURFACE, - "Installation rund": ElementType.INSTALLATION_ROUND, - "Measurement": ElementType.DIMENSION, - }, - "en": { - "Beam": ElementType.BEAM, - "Plate": ElementType.PLATE, - "Bemassung": ElementType.DIMENSION, - }, -} - -# TODO: get rid of this whole thing -try: - LOCAL_TYPE_MAP = ELEMENT_TYPE_MAP[uc.get_language()] -except AttributeError: - pass - - @dataclass class ElementGroup: """Represents a cadwork Element Group @@ -152,9 +110,6 @@ class Element: ---------- id : int The ID of the Element - type : ElementType - The type of the Element - Attributes ---------- @@ -180,6 +135,8 @@ class Element: The midpoint of the Element's centerline. ifc_guid : str The IFC GUID of the Element. See also: ifc_base64_guid. + is_beam : bool + Whether the Element is a beam is_wall : bool Whether the Element is a framed wall i.e. container for all other elements in the building group. is_drilling : bool @@ -192,7 +149,6 @@ class Element: """ id: int - type: ElementType @property def name(self) -> str: @@ -251,6 +207,10 @@ def midpoint(self) -> Point: def ifc_guid(self) -> str: return bc.get_ifc_guid(self.id) + @property + def is_beam(self) -> bool: + return ac.is_beam(self.id) + @property def is_wall(self) -> bool: return ac.is_framed_wall(self.id) @@ -280,28 +240,6 @@ def is_beam(self) -> bool: type_ = ac.get_element_type(self.id) return type_.is_rectangular_beam() - @classmethod - def from_id(cls, element_id: int) -> Element: - """Returns an Element object for the cadwork Element with the given ID - - Parameters - ---------- - element_id : int - The ID of the Element - - Returns - ------- - Element - The Element object for the given ID - - """ - type_description = ec.get_element_type_description(element_id) - try: - type_ = LOCAL_TYPE_MAP[type_description] - except KeyError: - type_ = ElementType.OTHER - return Element(element_id, type_) - @classmethod def from_selection(cls) -> Generator[Element]: """Returns a generator containing Element objects for all currently activated Elements @@ -312,7 +250,7 @@ def from_selection(cls) -> Generator[Element]: A generator containing Element objects for all currently activated Elements """ - return (Element.from_id(e_id) for e_id in ec.get_active_identifiable_element_ids()) + return (Element(e_id) for e_id in ec.get_active_identifiable_element_ids()) def set_attribute(self, name, value): """Sets an attribute on the Element @@ -371,7 +309,7 @@ def get_instruction_id(self) -> Optional[str]: def get_elements_in_contact(self) -> List[Element]: """Returns a list of elements in contact with the current element""" - return [Element.from_id(e_id) for e_id in ec.get_elements_in_contact(self.id)] + return [Element(e_id) for e_id in ec.get_elements_in_contact(self.id)] def remove(self): """Removes the Element from the cadwork file""" diff --git a/src/compas_cadwork/scene/scene.py b/src/compas_cadwork/scene/scene.py index eb5b3ef..50594b1 100644 --- a/src/compas_cadwork/scene/scene.py +++ b/src/compas_cadwork/scene/scene.py @@ -20,7 +20,7 @@ def add_element(self, element_id) -> Element: """ self.DRAWN_ELEMENTS.append(element_id) - return Element.from_id(element_id) + return Element(element_id) @classmethod def refresh(cls): diff --git a/src/compas_cadwork/utilities/__init__.py b/src/compas_cadwork/utilities/__init__.py index 5e3c556..d489a7c 100644 --- a/src/compas_cadwork/utilities/__init__.py +++ b/src/compas_cadwork/utilities/__init__.py @@ -113,7 +113,7 @@ def get_active_elements() -> list[Element]: List of currently selected elements. """ - return [Element.from_id(e_id) for e_id in ec.get_active_identifiable_element_ids()] + return [Element(e_id) for e_id in ec.get_active_identifiable_element_ids()] def get_language() -> str: @@ -205,7 +205,7 @@ def get_element_groups(is_wall_frame: bool = True) -> Dict[str, ElementGroup]: if group_name not in groups_elements: groups_elements[group_name] = ElementGroup(group_name) - groups_elements[group_name].add_element(Element.from_id(element_id)) + groups_elements[group_name].add_element(Element(element_id)) if is_wall_frame: _remove_wallless_groups(groups_elements) @@ -372,7 +372,7 @@ def get_all_elements(include_instructions: bool = False) -> Generator[Element, N """ for element_id in ec.get_all_identifiable_element_ids(): - element = Element.from_id(element_id) + element = Element(element_id) if include_instructions or not element.is_instruction: yield element @@ -394,7 +394,7 @@ def get_all_elements_with_attrib(attrib_number, attrib_value=None): """ for element_id in ec.get_all_identifiable_element_ids(): if ac.get_user_attribute(element_id, attrib_number) == attrib_value: - yield Element.from_id(element_id) + yield Element(element_id) def remove_elements(elements: List[Union[Element, int]]) -> None: diff --git a/src/compas_cadwork/utilities/events.py b/src/compas_cadwork/utilities/events.py index 051fc47..6a503ac 100644 --- a/src/compas_cadwork/utilities/events.py +++ b/src/compas_cadwork/utilities/events.py @@ -23,7 +23,7 @@ def check_for_changed_elements(self): new_ids = current_ids - self._known_element_ids removed_ids = self._known_element_ids - current_ids self._known_element_ids = current_ids - return [Element.from_id(id) for id in new_ids], [Element.from_id(id) for id in removed_ids] + return [Element(id) for id in new_ids], [Element(id) for id in removed_ids] def reset(self): """Reset the known element ids""" From d6878e6233ddb0a7a12c838d2eaaa351aeeb9f08 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Wed, 20 Nov 2024 13:31:16 +0100 Subject: [PATCH 2/4] removed references to deleted class --- docs/api/compas_cadwork.datamodel.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/api/compas_cadwork.datamodel.rst b/docs/api/compas_cadwork.datamodel.rst index 2a1a452..8d38e41 100644 --- a/docs/api/compas_cadwork.datamodel.rst +++ b/docs/api/compas_cadwork.datamodel.rst @@ -12,7 +12,6 @@ Classes :nosignatures: ElementGroupingType - ElementType ElementGroup Element From ecd58a7003d7f9fc03fda4cc788b131e960a10f4 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Wed, 20 Nov 2024 13:34:00 +0100 Subject: [PATCH 3/4] there already was is_beam --- CHANGELOG.md | 4 +--- src/compas_cadwork/datamodel/element.py | 4 ---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 967eb15..0253fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,15 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -* Added `Element.is_beam` property. - ### Changed ### Removed * Removed `ElementType` class. * Removed `Element.from_id` method. -* Removed `Element.type` property. +* Removed `Element.type` property. Use `Element.is_*` properties instead. ## [0.8.0] 2024-11-15 diff --git a/src/compas_cadwork/datamodel/element.py b/src/compas_cadwork/datamodel/element.py index 4bc3941..4abf0c1 100644 --- a/src/compas_cadwork/datamodel/element.py +++ b/src/compas_cadwork/datamodel/element.py @@ -207,10 +207,6 @@ def midpoint(self) -> Point: def ifc_guid(self) -> str: return bc.get_ifc_guid(self.id) - @property - def is_beam(self) -> bool: - return ac.is_beam(self.id) - @property def is_wall(self) -> bool: return ac.is_framed_wall(self.id) From c86f4388c397da6d2ee381cdae153aa0c68494a7 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Wed, 20 Nov 2024 13:39:17 +0100 Subject: [PATCH 4/4] removed unnecessary class methods in Dimension --- CHANGELOG.md | 2 ++ src/compas_cadwork/datamodel/dimension.py | 36 ----------------------- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0253fad..6906d21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Removed `ElementType` class. * Removed `Element.from_id` method. * Removed `Element.type` property. Use `Element.is_*` properties instead. +* Removed `Dimension.from_element` method. Use `Dimension(element_id)` instead. +* Removed `Dimension.from_id` method. Use `Dimension(element_id)` instead. ## [0.8.0] 2024-11-15 diff --git a/src/compas_cadwork/datamodel/dimension.py b/src/compas_cadwork/datamodel/dimension.py index 0d77228..7243e5e 100644 --- a/src/compas_cadwork/datamodel/dimension.py +++ b/src/compas_cadwork/datamodel/dimension.py @@ -105,39 +105,3 @@ def _init_anchors(self): direction = dc.get_segment_direction(self.id, index) anchors.append(AnchorPoint(point_to_compas(point), distance, vector_to_compas(direction))) return tuple(anchors) - - @classmethod - def from_id(cls, element_id: int) -> Dimension: - """Creates a dimension object from an element id. - - This is an override of :func:`Element.from_id`. - - Parameters - ---------- - element_id : int - The id of the element to create the dimension from. - - Returns - ------- - :class:`Dimension` - The dimension object created from the element id. - - """ - return cls(id=element_id) - - @classmethod - def from_element(cls, element: Element) -> Dimension: - """Creates a dimension object from an element. - - Parameters - ---------- - element : :class:`Element` - The element to create the dimension from. - - Returns - ------- - :class:`Dimension` - The dimension object created from the element. - - """ - return cls(id=element.id)