diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e7a4ebea29..065ac135f3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `compas.geometry.Brep.from_plane`. * Added `compas.tolerance.Tolerance.angulardeflection`. * Added `compas.tolerance.Tolerance.update_from_dict`. +* Added `compas.scene.SceneObject.scene` attribute. ### Changed @@ -36,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`. * Changed imports of itertools to `compas.itertools` instead of `compas.utilities`. * Changed `compas.tolerance.Tolerance` to a singleton, to ensure having only library-wide tolerance values. +* Updated `compas_rhino.conversions.point_to_compas` to allow for `Rhino.Geometry.Point` as input. +* Changed `compas.datastructures.Tree.print_hierarchy` to `compas.datastructures.Tree.__str__`. ### Removed @@ -45,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Removed `compas.utilities.geometric_key` and replaced it by `compas.tolerance.TOL.geometric_key`. * Removed `compas.utilities.geometric_key_xy` and replaced it by `compas.tolerance.TOL.geometric_key_xy`. * Removed indexed attribute access from all geometry classes except `Point`, `Vector`, `Line`, `Polygon`, `Polyline`. +* Removed `compas.datastructures.Tree.print_hierarchy`. ## [2.1.0] 2024-03-01 diff --git a/src/compas/datastructures/tree/tree.py b/src/compas/datastructures/tree/tree.py index 32ecc1c2703..30727413ad3 100644 --- a/src/compas/datastructures/tree/tree.py +++ b/src/compas/datastructures/tree/tree.py @@ -244,12 +244,11 @@ class Tree(Datastructure): >>> branch.add(leaf1) >>> branch.add(leaf2) >>> print(tree) - - >>> tree.print() - - - - + + |-- + |-- + |-- + |-- """ @@ -281,6 +280,9 @@ def __init__(self, name=None, **kwargs): super(Tree, self).__init__(kwargs, name=name) self._root = None + def __str__(self): + return "\n{}".format(len(list(self.nodes)), self.get_hierarchy_string(max_depth=3)) + @property def root(self): return self._root @@ -435,12 +437,9 @@ def get_nodes_by_name(self, name): nodes.append(node) return nodes - def __repr__(self): - return "".format(len(list(self.nodes))) - - def print_hierarchy(self, max_depth=None): + def get_hierarchy_string(self, max_depth=None): """ - Print the spatial hierarchy of the tree. + Return string representation for the spatial hierarchy of the tree. Parameters ---------- @@ -450,22 +449,27 @@ def print_hierarchy(self, max_depth=None): Returns ------- - None + str + String representing the spatial hierarchy of the tree. """ - def _print(node, prefix="", last=True, depth=0): + hierarchy = [] + + def traverse(node, hierarchy, prefix="", last=True, depth=0): if max_depth is not None and depth > max_depth: return connector = "└── " if last else "├── " - print("{}{}{}".format(prefix, connector, node)) + hierarchy.append("{}{}{}".format(prefix, connector, node)) prefix += " " if last else "│ " for i, child in enumerate(node.children): - _print(child, prefix, i == len(node.children) - 1, depth + 1) + traverse(child, hierarchy, prefix, i == len(node.children) - 1, depth + 1) + + traverse(self.root, hierarchy) - _print(self.root) + return "\n".join(hierarchy) def to_graph(self, key_mapper=None): """Convert the tree to a graph. diff --git a/src/compas/scene/sceneobject.py b/src/compas/scene/sceneobject.py index 02ce2806e88..a3ea109818b 100644 --- a/src/compas/scene/sceneobject.py +++ b/src/compas/scene/sceneobject.py @@ -72,6 +72,8 @@ class SceneObject(TreeNode): The settings including necessary attributes for reconstructing the scene object besides the Data item. context : str The context in which the scene object is created. + scene : :class:`compas.scene.Scene` + The scene to which the scene object belongs. """ @@ -120,6 +122,11 @@ def __repr__(self): # type: () -> str return "<{}: {}>".format(self.__class__.__name__, self.name) + @property + def scene(self): + # type: () -> compas.scene.Scene + return self.tree + @property def item(self): # type: () -> compas.geometry.Geometry | compas.datastructures.Datastructure diff --git a/src/compas_blender/scene/capsuleobject.py b/src/compas_blender/scene/capsuleobject.py index 340c6d8cfef..da8f157d93e 100644 --- a/src/compas_blender/scene/capsuleobject.py +++ b/src/compas_blender/scene/capsuleobject.py @@ -64,7 +64,6 @@ def draw( vertices, faces = self.geometry.to_vertices_and_faces(u=u, v=v) mesh = conversions.vertices_and_faces_to_blender_mesh(vertices, faces, name=self.geometry.name) if shade_smooth: - print(dir(mesh)) mesh.shade_smooth() obj = self.create_object(mesh, name=name) diff --git a/src/compas_rhino/conversions/geometry.py b/src/compas_rhino/conversions/geometry.py index 118e4302e84..cceb72bbe7e 100644 --- a/src/compas_rhino/conversions/geometry.py +++ b/src/compas_rhino/conversions/geometry.py @@ -3,6 +3,7 @@ from __future__ import print_function import Rhino # type: ignore +from System import MissingMemberException # type: ignore from compas.geometry import Frame from compas.geometry import Plane @@ -103,14 +104,20 @@ def point_to_compas(point): Parameters ---------- - point : :rhino:`Rhino.Geometry.Point3d` + point : :rhino:`Rhino.Geometry.Point3d` | :rhino:`Rhino.Geometry.Point` Returns ------- :class:`compas.geometry.Point` """ - return Point(point.X, point.Y, point.Z) + try: + return Point(point.X, point.Y, point.Z) + except MissingMemberException: + try: + return Point(point.Location.X, point.Location.Y, point.Location.Z) + except MissingMemberException: + raise TypeError("Unexpected point type, got: {}".format(type(point))) def vector_to_compas(vector): diff --git a/src/compas_rhino/geometry/brep/brep.py b/src/compas_rhino/geometry/brep/brep.py index 1a7f8e589ce..b2e77451aa2 100644 --- a/src/compas_rhino/geometry/brep/brep.py +++ b/src/compas_rhino/geometry/brep/brep.py @@ -534,7 +534,6 @@ def slice(self, plane): if isinstance(plane, Frame): plane = Plane.from_frame(plane) curves = Rhino.Geometry.Brep.CreateContourCurves(self._brep, plane_to_rhino(plane)) - print("curves:{}".format(curves)) return [curve_to_compas(curve) for curve in curves] def split(self, cutter):