compas-cadwork 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. compas_cadwork-0.7.0/LICENSE +21 -0
  2. compas_cadwork-0.7.0/PKG-INFO +101 -0
  3. compas_cadwork-0.7.0/README.md +49 -0
  4. compas_cadwork-0.7.0/pyproject.toml +132 -0
  5. compas_cadwork-0.7.0/requirements-dev.txt +9 -0
  6. compas_cadwork-0.7.0/requirements.txt +2 -0
  7. compas_cadwork-0.7.0/setup.cfg +4 -0
  8. compas_cadwork-0.7.0/src/compas_cadwork/__init__.py +36 -0
  9. compas_cadwork-0.7.0/src/compas_cadwork/conversions/__init__.py +12 -0
  10. compas_cadwork-0.7.0/src/compas_cadwork/conversions/primitives.py +71 -0
  11. compas_cadwork-0.7.0/src/compas_cadwork/datamodel/__init__.py +18 -0
  12. compas_cadwork-0.7.0/src/compas_cadwork/datamodel/dimension.py +144 -0
  13. compas_cadwork-0.7.0/src/compas_cadwork/datamodel/element.py +389 -0
  14. compas_cadwork-0.7.0/src/compas_cadwork/scene/__init__.py +40 -0
  15. compas_cadwork-0.7.0/src/compas_cadwork/scene/camera.py +243 -0
  16. compas_cadwork-0.7.0/src/compas_cadwork/scene/instructionobject.py +137 -0
  17. compas_cadwork-0.7.0/src/compas_cadwork/scene/scene.py +37 -0
  18. compas_cadwork-0.7.0/src/compas_cadwork/storage.py +132 -0
  19. compas_cadwork-0.7.0/src/compas_cadwork/utilities/__init__.py +445 -0
  20. compas_cadwork-0.7.0/src/compas_cadwork/utilities/dimensions.py +68 -0
  21. compas_cadwork-0.7.0/src/compas_cadwork/utilities/events.py +61 -0
  22. compas_cadwork-0.7.0/src/compas_cadwork/utilities/ifc_export.py +99 -0
  23. compas_cadwork-0.7.0/src/compas_cadwork.egg-info/PKG-INFO +101 -0
  24. compas_cadwork-0.7.0/src/compas_cadwork.egg-info/SOURCES.txt +27 -0
  25. compas_cadwork-0.7.0/src/compas_cadwork.egg-info/dependency_links.txt +1 -0
  26. compas_cadwork-0.7.0/src/compas_cadwork.egg-info/not-zip-safe +1 -0
  27. compas_cadwork-0.7.0/src/compas_cadwork.egg-info/requires.txt +13 -0
  28. compas_cadwork-0.7.0/src/compas_cadwork.egg-info/top_level.txt +1 -0
  29. compas_cadwork-0.7.0/tests/test_placeholder.py +2 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.1
2
+ Name: compas_cadwork
3
+ Version: 0.7.0
4
+ Summary: COMPAS package for integrating with cadwork.
5
+ Author-email: Chen Kasirer <kasirer@arch.ethz.ch>, Matthias Helmreich <helmreich@arch.ethz.ch>, Gonzalo Casas <casas@arch.ethz.ch>
6
+ License: MIT License
7
+
8
+
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://gramaziokohler.github.io/compas_cadwork/latest/
29
+ Project-URL: Repository, https://github.com/gramaziokohler/compas_cadwork
30
+ Classifier: Development Status :: 4 - Beta
31
+ Classifier: Topic :: Scientific/Engineering
32
+ Classifier: Programming Language :: Python
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Requires-Python: >=3.9
38
+ Description-Content-Type: text/markdown
39
+ License-File: LICENSE
40
+ Requires-Dist: compas<3.0,>=2.0
41
+ Requires-Dist: cwapi3d>=30.498.0
42
+ Provides-Extra: dev
43
+ Requires-Dist: attrs>=17.4; extra == "dev"
44
+ Requires-Dist: black; extra == "dev"
45
+ Requires-Dist: bump-my-version; extra == "dev"
46
+ Requires-Dist: compas_invocations2; extra == "dev"
47
+ Requires-Dist: invoke>=0.14; extra == "dev"
48
+ Requires-Dist: sphinx_compas2_theme; extra == "dev"
49
+ Requires-Dist: twine; extra == "dev"
50
+ Requires-Dist: wheel; extra == "dev"
51
+ Requires-Dist: ruff; extra == "dev"
52
+
53
+ # compas_cadwork
54
+
55
+ [![Github Actions Build Status](https://github.com/gramaziokohler/compas_cadwork/workflows/build/badge.svg)](https://github.com/gramaziokohler/compas_cadwork/actions)
56
+ [![License](https://img.shields.io/github/license/gramaziokohler/compas_cadwork.svg)](https://pypi.python.org/pypi/compas_cadwork)
57
+ [![pip downloads](https://img.shields.io/pypi/dm/compas_cadwork)](https://pypi.python.org/project/compas_cadwork)
58
+ [![PyPI Package latest release](https://img.shields.io/pypi/v/compas_cadwork.svg)](https://pypi.python.org/pypi/compas_cadwork)
59
+ [![Supported implementations](https://img.shields.io/pypi/implementation/compas_cadwork.svg)](https://pypi.python.org/pypi/compas_cadwork)
60
+ [![Twitter Follow](https://img.shields.io/twitter/follow/compas_dev?style=social)](https://twitter.com/compas_dev)
61
+
62
+ ![COMPAS Cadwork](https://raw.githubusercontent.com/gramaziokohler/compas_cadwork/refs/heads/main/compas_cadwork.JPG)
63
+
64
+ COMPAS cadwork is an open-source Python package which allows you to harness the power of the COMPAS framework inside cadwork 3d.
65
+ Make use of COMPAS' extensive geometry kernel, data structures, and algorithms to create, manipulate, and analyze your 3d models in cadwork.
66
+ Gain access to the COMPAS ecosystem which includes a wide range of tools and libraries engineered for the AEC industry.
67
+
68
+ ## Installation
69
+
70
+ > For the different installation options please see the [installation guide](https://gramaziokohler.github.io/compas_cadwork/latest/installation.html).
71
+
72
+ To install `compas_cadwork` directly to cadwork 3d, run:
73
+
74
+ ```bash
75
+ pip install compas_cadwork --target "C:\Program Files\cadwork.dir\EXE_30\Pclib.x64\python310\site-packages" --upgrade
76
+ ```
77
+
78
+ ## First Steps
79
+
80
+ * [Documentation](https://gramaziokohler.github.io/compas_cadwork/)
81
+ * [COMPAS CADWORK API Reference](https://gramaziokohler.github.io/compas_cadwork/latest/api.html)
82
+
83
+ ## Questions and feedback
84
+
85
+ We encourage the use of the [COMPAS framework forum](https://forum.compas-framework.org/)
86
+ for questions and discussions.
87
+
88
+ ## Issue tracker
89
+
90
+ If you found an issue or have a suggestion for a dandy new feature, please file a new issue in our [issue tracker](https://github.com/gramaziokohler/compas_cadwork/issues).
91
+
92
+ ## Contributing
93
+
94
+ We love contributions!
95
+
96
+ Check the [Contributor's Guide](https://compas.dev/compas/latest/devguide/)
97
+ for more details.
98
+
99
+ ## Credits
100
+
101
+ `compas_cadwork` is currently developed by [Gramazio Kohler Research](https://gramaziokohler.arch.ethz.ch/).
@@ -0,0 +1,49 @@
1
+ # compas_cadwork
2
+
3
+ [![Github Actions Build Status](https://github.com/gramaziokohler/compas_cadwork/workflows/build/badge.svg)](https://github.com/gramaziokohler/compas_cadwork/actions)
4
+ [![License](https://img.shields.io/github/license/gramaziokohler/compas_cadwork.svg)](https://pypi.python.org/pypi/compas_cadwork)
5
+ [![pip downloads](https://img.shields.io/pypi/dm/compas_cadwork)](https://pypi.python.org/project/compas_cadwork)
6
+ [![PyPI Package latest release](https://img.shields.io/pypi/v/compas_cadwork.svg)](https://pypi.python.org/pypi/compas_cadwork)
7
+ [![Supported implementations](https://img.shields.io/pypi/implementation/compas_cadwork.svg)](https://pypi.python.org/pypi/compas_cadwork)
8
+ [![Twitter Follow](https://img.shields.io/twitter/follow/compas_dev?style=social)](https://twitter.com/compas_dev)
9
+
10
+ ![COMPAS Cadwork](https://raw.githubusercontent.com/gramaziokohler/compas_cadwork/refs/heads/main/compas_cadwork.JPG)
11
+
12
+ COMPAS cadwork is an open-source Python package which allows you to harness the power of the COMPAS framework inside cadwork 3d.
13
+ Make use of COMPAS' extensive geometry kernel, data structures, and algorithms to create, manipulate, and analyze your 3d models in cadwork.
14
+ Gain access to the COMPAS ecosystem which includes a wide range of tools and libraries engineered for the AEC industry.
15
+
16
+ ## Installation
17
+
18
+ > For the different installation options please see the [installation guide](https://gramaziokohler.github.io/compas_cadwork/latest/installation.html).
19
+
20
+ To install `compas_cadwork` directly to cadwork 3d, run:
21
+
22
+ ```bash
23
+ pip install compas_cadwork --target "C:\Program Files\cadwork.dir\EXE_30\Pclib.x64\python310\site-packages" --upgrade
24
+ ```
25
+
26
+ ## First Steps
27
+
28
+ * [Documentation](https://gramaziokohler.github.io/compas_cadwork/)
29
+ * [COMPAS CADWORK API Reference](https://gramaziokohler.github.io/compas_cadwork/latest/api.html)
30
+
31
+ ## Questions and feedback
32
+
33
+ We encourage the use of the [COMPAS framework forum](https://forum.compas-framework.org/)
34
+ for questions and discussions.
35
+
36
+ ## Issue tracker
37
+
38
+ If you found an issue or have a suggestion for a dandy new feature, please file a new issue in our [issue tracker](https://github.com/gramaziokohler/compas_cadwork/issues).
39
+
40
+ ## Contributing
41
+
42
+ We love contributions!
43
+
44
+ Check the [Contributor's Guide](https://compas.dev/compas/latest/devguide/)
45
+ for more details.
46
+
47
+ ## Credits
48
+
49
+ `compas_cadwork` is currently developed by [Gramazio Kohler Research](https://gramaziokohler.arch.ethz.ch/).
@@ -0,0 +1,132 @@
1
+ # ============================================================================
2
+ # Project info
3
+ # ============================================================================
4
+
5
+ [project]
6
+ name = "compas_cadwork"
7
+ description = "COMPAS package for integrating with cadwork."
8
+ authors = [
9
+ { name = "Chen Kasirer", email = "kasirer@arch.ethz.ch" },
10
+ { name = "Matthias Helmreich", email = "helmreich@arch.ethz.ch" },
11
+ { name = "Gonzalo Casas", email = "casas@arch.ethz.ch" }
12
+ ]
13
+ license = { file = "LICENSE" }
14
+ readme = "README.md"
15
+ requires-python = ">=3.9"
16
+ dynamic = ["dependencies", "optional-dependencies", "version"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Topic :: Scientific/Engineering",
20
+ "Programming Language :: Python",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ ]
26
+
27
+ [project.urls]
28
+ Homepage = "https://gramaziokohler.github.io/compas_cadwork/latest/"
29
+ Repository = "https://github.com/gramaziokohler/compas_cadwork"
30
+
31
+ # ============================================================================
32
+ # Setup and build
33
+ # ============================================================================
34
+
35
+ [tool.setuptools]
36
+ package-dir = { "" = "src" }
37
+ include-package-data = true
38
+ zip-safe = false
39
+
40
+ [tool.setuptools.dynamic]
41
+ version = { attr = "compas_cadwork.__version__" }
42
+ dependencies = { file = "requirements.txt" }
43
+ optional-dependencies = { dev = { file = "requirements-dev.txt" } }
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["src"]
47
+
48
+ [tool.setuptools.package-data]
49
+
50
+ # ============================================================================
51
+ # Release
52
+ # ============================================================================
53
+
54
+ [tool.bumpversion]
55
+ current_version = "0.7.0"
56
+ message = "Bump version to {new_version}"
57
+ commit = true
58
+ tag = true
59
+
60
+ [[tool.bumpversion.files]]
61
+ filename = "src/compas_cadwork/__init__.py"
62
+ search = "{current_version}"
63
+ replace = "{new_version}"
64
+
65
+ [[tool.bumpversion.files]]
66
+ filename = "CHANGELOG.md"
67
+ search = "Unreleased"
68
+ replace = "[{new_version}] {now:%Y-%m-%d}"
69
+
70
+ # ============================================================================
71
+ # Formatting and linting
72
+ # ============================================================================
73
+
74
+ [tool.black]
75
+ line-length = 179
76
+
77
+ [tool.ruff]
78
+ line-length = 179
79
+ indent-width = 4
80
+ target-version = "py39"
81
+
82
+ [tool.ruff.lint]
83
+ select = ["E", "F", "I"]
84
+
85
+ [tool.ruff.lint.per-file-ignores]
86
+ "__init__.py" = ["I001"]
87
+ "tests/*" = ["I001"]
88
+ "tasks.py" = ["I001"]
89
+
90
+ [tool.ruff.lint.isort]
91
+ force-single-line = true
92
+ known-first-party = [
93
+ "compas_cadwork",
94
+ ]
95
+
96
+ [tool.ruff.lint.pydocstyle]
97
+ convention = "numpy"
98
+
99
+ [tool.ruff.lint.pycodestyle]
100
+ max-doc-length = 179
101
+
102
+ [tool.ruff.format]
103
+ docstring-code-format = true
104
+ docstring-code-line-length = "dynamic"
105
+
106
+ [tool.isort]
107
+ line_length = 179
108
+ multi_line_output = 3
109
+ include_trailing_comma = true
110
+ force_grid_wrap = 0
111
+ use_parentheses = true
112
+ force_single_line = true
113
+ ensure_newline_before_comments = true
114
+ known_first_party = "compas_cadwork"
115
+ default_section = "THIRDPARTY"
116
+ forced_separate = "test_compas_cadwork"
117
+ skip = ["__init__.py"]
118
+
119
+ # ============================================================================
120
+ # Testing
121
+ # ============================================================================
122
+
123
+ [tool.pytest.ini_options]
124
+ minversion = "6.0"
125
+ testpaths = ["tests"]
126
+ python_files = [
127
+ "test_*.py",
128
+ "tests.py"
129
+ ]
130
+ addopts = "-ra --strict --doctest-modules --doctest-glob=*.rst --tb=short"
131
+ doctest_optionflags= "NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ALLOW_UNICODE ALLOW_BYTES NUMBER"
132
+ filterwarnings = "ignore::DeprecationWarning"
@@ -0,0 +1,9 @@
1
+ attrs >=17.4
2
+ black
3
+ bump-my-version
4
+ compas_invocations2
5
+ invoke >=0.14
6
+ sphinx_compas2_theme
7
+ twine
8
+ wheel
9
+ ruff
@@ -0,0 +1,2 @@
1
+ compas>=2.0, <3.0
2
+ cwapi3d>=30.498.0
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,36 @@
1
+ from __future__ import print_function
2
+ import os
3
+ from datetime import datetime
4
+
5
+ __title__ = "compas_cadwork"
6
+ __description__ = "COMPAS package for integrating with cadwork"
7
+ __url__ = "https://github.com/gramaziokohler/compas_cadwork"
8
+ __version__ = "0.7.0"
9
+ __author__ = "Gramazio Kohler Research"
10
+ __author_email__ = "gramaziokohler@arch.ethz.ch"
11
+ __license__ = "MIT license"
12
+ __copyright__ = "Copyright {} Gramazio Kohler Research".format(datetime.today().year)
13
+
14
+ HERE = os.path.dirname(__file__)
15
+ HOME = os.path.abspath(os.path.join(HERE, "../../"))
16
+ DATA = os.path.abspath(os.path.join(HOME, "data"))
17
+ DOCS = os.path.abspath(os.path.join(HOME, "docs"))
18
+ TEMP = os.path.abspath(os.path.join(HOME, "temp"))
19
+
20
+
21
+ __all__ = [
22
+ "HOME",
23
+ "DATA",
24
+ "DOCS",
25
+ "TEMP",
26
+ "__author__",
27
+ "__author_email__",
28
+ "__copyright__",
29
+ "__description__",
30
+ "__license__",
31
+ "__title__",
32
+ "__url__",
33
+ "__version__",
34
+ ]
35
+
36
+ __all_plugins__ = ["compas_cadwork.scene"]
@@ -0,0 +1,12 @@
1
+ from .primitives import point_to_cadwork
2
+ from .primitives import vector_to_cadwork
3
+ from .primitives import point_to_compas
4
+ from .primitives import vector_to_compas
5
+
6
+
7
+ __all__ = [
8
+ "point_to_cadwork",
9
+ "vector_to_cadwork",
10
+ "point_to_compas",
11
+ "vector_to_compas",
12
+ ]
@@ -0,0 +1,71 @@
1
+ try:
2
+ from cadwork import point_3d
3
+ except ImportError:
4
+ pass
5
+
6
+ from compas.geometry import Point
7
+ from compas.geometry import Vector
8
+
9
+
10
+ def point_to_cadwork(point: Point):
11
+ """Convert a :class:`compas.geometry.Point` to a cadwork point_3d object.
12
+
13
+ Parameters
14
+ ----------
15
+ point : :class:`~compas.geometry.Point`
16
+ The point to convert
17
+
18
+ Returns
19
+ -------
20
+ :class:`cadwork.point_3d`
21
+
22
+ """
23
+ return point_3d(point.x, point.y, point.z)
24
+
25
+
26
+ def vector_to_cadwork(vector: Vector):
27
+ """Convert a :class:`compas.geometry.Vector` to a cadwork point_3d object.
28
+
29
+ Parameters
30
+ ----------
31
+ vector : :class:`~compas.geometry.Vector`
32
+ The vector to convert
33
+
34
+ Returns
35
+ -------
36
+ :class:`cadwork.point_3d`
37
+
38
+ """
39
+ return point_3d(vector.x, vector.y, vector.z)
40
+
41
+
42
+ def point_to_compas(point):
43
+ """Convert a cadwork point_3d to a :class:`compas.geometry.Point` object.
44
+
45
+ Parameters
46
+ ----------
47
+ point : :class:`cadwork.point_3d`
48
+ The point to convert
49
+
50
+ Returns
51
+ -------
52
+ :class:`~compas.geometry.Point`
53
+
54
+ """
55
+ return Point(point.x, point.y, point.z)
56
+
57
+
58
+ def vector_to_compas(vector):
59
+ """Convert a cadwork point_3d to a :class:`compas.geometry.Point` obhect.
60
+
61
+ Parameters
62
+ ----------
63
+ point : :class:`~compas.geometry.Point`
64
+ The point to convert
65
+
66
+ Returns
67
+ -------
68
+ :class:`cadwork.point_3d`
69
+
70
+ """
71
+ return Vector(*point_to_compas(vector))
@@ -0,0 +1,18 @@
1
+ from .element import Element
2
+ from .element import ElementType
3
+ from .element import ElementGroup
4
+ from .element import ElementGroupingType
5
+ from .element import ATTR_INSTRUCTION_ID
6
+ from .dimension import Dimension
7
+ from .dimension import AnchorPoint
8
+
9
+
10
+ __all__ = [
11
+ "Element",
12
+ "ElementType",
13
+ "ElementGroup",
14
+ "ElementGroupingType",
15
+ "ATTR_INSTRUCTION_ID",
16
+ "AnchorPoint",
17
+ "Dimension",
18
+ ]
@@ -0,0 +1,144 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ import dimension_controller as dc
6
+ from compas.geometry import Frame
7
+ from compas.geometry import Point
8
+ from compas.geometry import Vector
9
+ from compas.tolerance import Tolerance
10
+
11
+ from compas_cadwork.conversions import point_to_compas
12
+ from compas_cadwork.conversions import vector_to_compas
13
+
14
+ from .element import Element
15
+ from .element import ElementType
16
+
17
+ TOL = Tolerance(unit="MM", absolute=1e-3, relative=1e-3)
18
+
19
+
20
+ @dataclass
21
+ class AnchorPoint:
22
+ """Anchor point of a cadwork measurement. There may me 2 or more anchor points in a measurement.
23
+
24
+ Attributes
25
+ ----------
26
+ location : Point
27
+ The location of the anchor point in 3d space.
28
+ distance : float
29
+ The distance of the anchor point from the measurement line.
30
+ direction : Vector
31
+ The direction of the anchor point from the measurement line.
32
+
33
+ """
34
+
35
+ location: Point
36
+ distance: float
37
+ direction: Vector
38
+
39
+ def __eq__(self, other: AnchorPoint) -> bool:
40
+ if not isinstance(other, AnchorPoint):
41
+ return False
42
+
43
+ if not TOL.is_allclose([*self.location], [*other.location]):
44
+ return False
45
+
46
+ if not TOL.is_allclose([*self.direction], [*other.direction]):
47
+ return False
48
+
49
+ return TOL.is_close(self.distance, other.distance)
50
+
51
+
52
+ class Dimension(Element):
53
+ """Represents a cadwork dimension"""
54
+
55
+ def __init__(self, id):
56
+ super().__init__(id, ElementType.DIMENSION)
57
+ self._frame = None
58
+ # not lazy-instantiating this so that it can be used to compare the modified instances of the same dimension
59
+ # otherwise, the anchors values that are compared depend on the time `anchors` was first accessed
60
+ self.anchors = self._init_anchors()
61
+
62
+ def __str__(self) -> str:
63
+ return f"Dimension id:{self.id} length:{self.length:.0f} anchors:{len(self.anchors)}"
64
+
65
+ def __hash__(self):
66
+ return hash(self.cadwork_guid)
67
+
68
+ def __eq__(self, other: Dimension):
69
+ if not isinstance(other, Dimension):
70
+ return False
71
+
72
+ if self.cadwork_guid != other.cadwork_guid:
73
+ return False
74
+
75
+ if len(self.anchors) != len(other.anchors):
76
+ return False
77
+
78
+ for point_self, point_other in zip(self.anchors, other.anchors):
79
+ if point_self != point_other:
80
+ return False
81
+ return True
82
+
83
+ @property
84
+ def frame(self):
85
+ if not self._frame:
86
+ zaxis = -self.text_normal
87
+ xaxis = vector_to_compas(dc.get_plane_xl(self.id))
88
+ yaxis = xaxis.cross(zaxis).unitized()
89
+ self._frame = Frame(self.anchors[0].location, xaxis, yaxis)
90
+ return self._frame
91
+
92
+ @property
93
+ def text_normal(self):
94
+ return vector_to_compas(dc.get_plane_normal(self.id))
95
+
96
+ @property
97
+ def length(self):
98
+ start: Point = self.anchors[0].location
99
+ end: Point = self.anchors[-1].location
100
+ return start.distance_to_point(end)
101
+
102
+ def _init_anchors(self):
103
+ anchors = []
104
+ for index, point in enumerate(dc.get_dimension_points(self.id)):
105
+ distance = dc.get_segment_distance(self.id, index)
106
+ direction = dc.get_segment_direction(self.id, index)
107
+ anchors.append(AnchorPoint(point_to_compas(point), distance, vector_to_compas(direction)))
108
+ return tuple(anchors)
109
+
110
+ @classmethod
111
+ def from_id(cls, element_id: int) -> Dimension:
112
+ """Creates a dimension object from an element id.
113
+
114
+ This is an override of :func:`Element.from_id`.
115
+
116
+ Parameters
117
+ ----------
118
+ element_id : int
119
+ The id of the element to create the dimension from.
120
+
121
+ Returns
122
+ -------
123
+ :class:`Dimension`
124
+ The dimension object created from the element id.
125
+
126
+ """
127
+ return cls(id=element_id)
128
+
129
+ @classmethod
130
+ def from_element(cls, element: Element) -> Dimension:
131
+ """Creates a dimension object from an element.
132
+
133
+ Parameters
134
+ ----------
135
+ element : :class:`Element`
136
+ The element to create the dimension from.
137
+
138
+ Returns
139
+ -------
140
+ :class:`Dimension`
141
+ The dimension object created from the element.
142
+
143
+ """
144
+ return cls(id=element.id)