From 67d1481b9867ba55978ce6d855ff7c22f3513abb Mon Sep 17 00:00:00 2001 From: Li Date: Thu, 28 Mar 2024 13:12:45 +0100 Subject: [PATCH 1/9] remove print from tree use __str__ --- src/compas/datastructures/tree/tree.py | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/compas/datastructures/tree/tree.py b/src/compas/datastructures/tree/tree.py index aaff66dcc23..a72f140128a 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.hierarchy(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 hierarchy(self, max_depth=None): """ - Print the spatial hierarchy of the tree. + Return string for the spatial hierarchy of the tree. Parameters ---------- @@ -450,22 +449,27 @@ def print_hierarchy(self, max_depth=None): Returns ------- - None + str + The spatial hierarchy of the tree. """ - def _print(node, prefix="", last=True, depth=0): + hierarchy = {"string": ""} + + 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["string"] += "{}{}{}\n".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 hierarchy["string"] def to_graph(self, key_mapper=None): """Convert the tree to a graph. From f13b2bd2735b35e7046739a191cfd55dca7ed670 Mon Sep 17 00:00:00 2001 From: Licini Date: Thu, 28 Mar 2024 13:14:55 +0100 Subject: [PATCH 2/9] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf9dcdaab07..cc09f2ba55c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,11 +14,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed and updated the `compas_view2` examples into `compas_viewer`. * Changed `compas.scene.Scene` to inherent from `compas.datastructrues.Tree`. * Changed `compas.scene.SceneObject` to inherent from `compas.datastructrues.TreeNode`. +* Changed `compas.datastructures.Tree.print_hierarchy` to `compas.datastructures.Tree.__str__`. ### Removed * Removed `compas.scene.SceneObjectNode`, functionalities merged into `compas.scene.SceneObject`. * Removed `compas.scene.SceneTree`, functionalities merged into `compas.scene.Scene`. +* Removed `compas.datastructures.Tree.print_hierarchy`. ## [2.1.0] 2024-03-01 From 8283d7403c91427559946ee38536a4fa5847be3c Mon Sep 17 00:00:00 2001 From: Li Date: Mon, 29 Apr 2024 17:00:35 +0200 Subject: [PATCH 3/9] allow Rhino.Geometry.Point --- src/compas_rhino/conversions/geometry.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compas_rhino/conversions/geometry.py b/src/compas_rhino/conversions/geometry.py index 118e4302e84..bb7e04bb883 100644 --- a/src/compas_rhino/conversions/geometry.py +++ b/src/compas_rhino/conversions/geometry.py @@ -103,14 +103,19 @@ 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) + if isinstance(point, Rhino.Geometry.Point3d): + return Point(point.X, point.Y, point.Z) + elif isinstance(point, Rhino.Geometry.Point): + return Point(point.Location.X, point.Location.Y, point.Location.Z) + else: + raise TypeError("Expected Rhino.Geometry.Point3d or Rhino.Geometry.Point., got: {}".format(type(point))) def vector_to_compas(vector): From 7b5b5e3e5f66e556b8616879627bf643ce76b9ea Mon Sep 17 00:00:00 2001 From: Li Date: Mon, 29 Apr 2024 17:01:57 +0200 Subject: [PATCH 4/9] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afce9e69104..9cb89d700b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`. * Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`. * Changed imports of itertools to `compas.itertools` instead of `compas.utilities`. +* Updated `compas_rhino.conversions.point_to_compas` to allow for `compas.geometry.Point` as input. ### Removed From 94546998f95fc37bc9adf5265caef71a4809beb9 Mon Sep 17 00:00:00 2001 From: Licini Date: Mon, 29 Apr 2024 17:50:58 +0200 Subject: [PATCH 5/9] use try except --- CHANGELOG.md | 2 +- src/compas_rhino/conversions/geometry.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb89d700b2..8baf02dc1b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`. * Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`. * Changed imports of itertools to `compas.itertools` instead of `compas.utilities`. -* Updated `compas_rhino.conversions.point_to_compas` to allow for `compas.geometry.Point` as input. +* Updated `compas_rhino.conversions.point_to_compas` to allow for `Rhino.Geometry.Point` as input. ### Removed diff --git a/src/compas_rhino/conversions/geometry.py b/src/compas_rhino/conversions/geometry.py index bb7e04bb883..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 @@ -110,12 +111,13 @@ def point_to_compas(point): :class:`compas.geometry.Point` """ - if isinstance(point, Rhino.Geometry.Point3d): + try: return Point(point.X, point.Y, point.Z) - elif isinstance(point, Rhino.Geometry.Point): - return Point(point.Location.X, point.Location.Y, point.Location.Z) - else: - raise TypeError("Expected Rhino.Geometry.Point3d or Rhino.Geometry.Point., got: {}".format(type(point))) + 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): From 997f2cedda38ad8e5a804dbbab8336a1377f4349 Mon Sep 17 00:00:00 2001 From: Licini Date: Mon, 29 Apr 2024 18:14:12 +0200 Subject: [PATCH 6/9] use list --- src/compas/datastructures/tree/tree.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compas/datastructures/tree/tree.py b/src/compas/datastructures/tree/tree.py index 4038f69d1c7..27fec5171e8 100644 --- a/src/compas/datastructures/tree/tree.py +++ b/src/compas/datastructures/tree/tree.py @@ -454,7 +454,7 @@ def hierarchy(self, max_depth=None): """ - hierarchy = {"string": ""} + hierarchy = [] def traverse(node, hierarchy, prefix="", last=True, depth=0): @@ -462,14 +462,14 @@ def traverse(node, hierarchy, prefix="", last=True, depth=0): return connector = "└── " if last else "├── " - hierarchy["string"] += "{}{}{}\n".format(prefix, connector, node) + hierarchy.append("{}{}{}".format(prefix, connector, node)) prefix += " " if last else "│ " for i, child in enumerate(node.children): traverse(child, hierarchy, prefix, i == len(node.children) - 1, depth + 1) traverse(self.root, hierarchy) - return hierarchy["string"] + return "\n".join(hierarchy) def to_graph(self, key_mapper=None): """Convert the tree to a graph. From ded69879b81b40ecb13740d0cae9332fab5af4e5 Mon Sep 17 00:00:00 2001 From: Licini Date: Tue, 30 Apr 2024 09:15:53 +0200 Subject: [PATCH 7/9] function name --- src/compas/datastructures/tree/tree.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compas/datastructures/tree/tree.py b/src/compas/datastructures/tree/tree.py index 27fec5171e8..30727413ad3 100644 --- a/src/compas/datastructures/tree/tree.py +++ b/src/compas/datastructures/tree/tree.py @@ -281,7 +281,7 @@ def __init__(self, name=None, **kwargs): self._root = None def __str__(self): - return "\n{}".format(len(list(self.nodes)), self.hierarchy(max_depth=3)) + return "\n{}".format(len(list(self.nodes)), self.get_hierarchy_string(max_depth=3)) @property def root(self): @@ -437,9 +437,9 @@ def get_nodes_by_name(self, name): nodes.append(node) return nodes - def hierarchy(self, max_depth=None): + def get_hierarchy_string(self, max_depth=None): """ - Return string for the spatial hierarchy of the tree. + Return string representation for the spatial hierarchy of the tree. Parameters ---------- @@ -450,7 +450,7 @@ def hierarchy(self, max_depth=None): Returns ------- str - The spatial hierarchy of the tree. + String representing the spatial hierarchy of the tree. """ From 5f93bb58f6d7864aa3bc5c76ecb80346160df5cf Mon Sep 17 00:00:00 2001 From: Gonzalo Casas Date: Wed, 1 May 2024 22:18:12 +0200 Subject: [PATCH 8/9] Remove debug print statements --- src/compas_blender/scene/capsuleobject.py | 1 - src/compas_rhino/geometry/brep/brep.py | 1 - 2 files changed, 2 deletions(-) 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/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): From 75f49bb09cbde9386d1b462fd18b6142448585b5 Mon Sep 17 00:00:00 2001 From: Li Date: Tue, 7 May 2024 15:36:42 +0200 Subject: [PATCH 9/9] add SceneObject.scene --- CHANGELOG.md | 1 + src/compas/scene/sceneobject.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c837680779b..e85296714c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `compas.colors.Color.contrast`. * Added `compas.geometry.Brep.from_plane`. * Added `compas.tolerance.Tolerance.angulardeflection`. +* Added `compas.scene.SceneObject.scene` attribute. ### Changed 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