Skip to content

Commit 89b8b7c

Browse files
committed
Merge branch 'main' into tolerance-singleton
2 parents 182f8dc + 835f233 commit 89b8b7c

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
* Added `compas.geometry.Brep.from_plane`.
1717
* Added `compas.tolerance.Tolerance.angulardeflection`.
1818
* Added `compas.tolerance.Tolerance.update_from_dict`.
19+
* Added `compas.scene.SceneObject.scene` attribute.
1920

2021
### Changed
2122

@@ -36,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3637
* Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`.
3738
* Changed imports of itertools to `compas.itertools` instead of `compas.utilities`.
3839
* Changed `compas.tolerance.Tolerance` to a singleton, to ensure having only library-wide tolerance values.
40+
* Updated `compas_rhino.conversions.point_to_compas` to allow for `Rhino.Geometry.Point` as input.
41+
* Changed `compas.datastructures.Tree.print_hierarchy` to `compas.datastructures.Tree.__str__`.
3942

4043
### Removed
4144

@@ -45,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4548
* Removed `compas.utilities.geometric_key` and replaced it by `compas.tolerance.TOL.geometric_key`.
4649
* Removed `compas.utilities.geometric_key_xy` and replaced it by `compas.tolerance.TOL.geometric_key_xy`.
4750
* Removed indexed attribute access from all geometry classes except `Point`, `Vector`, `Line`, `Polygon`, `Polyline`.
51+
* Removed `compas.datastructures.Tree.print_hierarchy`.
4852

4953
## [2.1.0] 2024-03-01
5054

src/compas/datastructures/tree/tree.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,11 @@ class Tree(Datastructure):
244244
>>> branch.add(leaf1)
245245
>>> branch.add(leaf2)
246246
>>> print(tree)
247-
<Tree with 4 nodes, 1 branches, and 2 leaves>
248-
>>> tree.print()
249-
<TreeNode root>
250-
<TreeNode branch>
251-
<TreeNode leaf2>
252-
<TreeNode leaf1>
247+
<Tree with 4 nodes>
248+
|--<TreeNode: root>
249+
|-- <TreeNode: branch>
250+
|-- <TreeNode: leaf1>
251+
|-- <TreeNode: leaf2>
253252
254253
"""
255254

@@ -281,6 +280,9 @@ def __init__(self, name=None, **kwargs):
281280
super(Tree, self).__init__(kwargs, name=name)
282281
self._root = None
283282

283+
def __str__(self):
284+
return "<Tree with {} nodes>\n{}".format(len(list(self.nodes)), self.get_hierarchy_string(max_depth=3))
285+
284286
@property
285287
def root(self):
286288
return self._root
@@ -435,12 +437,9 @@ def get_nodes_by_name(self, name):
435437
nodes.append(node)
436438
return nodes
437439

438-
def __repr__(self):
439-
return "<Tree with {} nodes>".format(len(list(self.nodes)))
440-
441-
def print_hierarchy(self, max_depth=None):
440+
def get_hierarchy_string(self, max_depth=None):
442441
"""
443-
Print the spatial hierarchy of the tree.
442+
Return string representation for the spatial hierarchy of the tree.
444443
445444
Parameters
446445
----------
@@ -450,22 +449,27 @@ def print_hierarchy(self, max_depth=None):
450449
451450
Returns
452451
-------
453-
None
452+
str
453+
String representing the spatial hierarchy of the tree.
454454
455455
"""
456456

457-
def _print(node, prefix="", last=True, depth=0):
457+
hierarchy = []
458+
459+
def traverse(node, hierarchy, prefix="", last=True, depth=0):
458460

459461
if max_depth is not None and depth > max_depth:
460462
return
461463

462464
connector = "└── " if last else "├── "
463-
print("{}{}{}".format(prefix, connector, node))
465+
hierarchy.append("{}{}{}".format(prefix, connector, node))
464466
prefix += " " if last else "│ "
465467
for i, child in enumerate(node.children):
466-
_print(child, prefix, i == len(node.children) - 1, depth + 1)
468+
traverse(child, hierarchy, prefix, i == len(node.children) - 1, depth + 1)
469+
470+
traverse(self.root, hierarchy)
467471

468-
_print(self.root)
472+
return "\n".join(hierarchy)
469473

470474
def to_graph(self, key_mapper=None):
471475
"""Convert the tree to a graph.

src/compas/scene/sceneobject.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class SceneObject(TreeNode):
7272
The settings including necessary attributes for reconstructing the scene object besides the Data item.
7373
context : str
7474
The context in which the scene object is created.
75+
scene : :class:`compas.scene.Scene`
76+
The scene to which the scene object belongs.
7577
7678
"""
7779

@@ -120,6 +122,11 @@ def __repr__(self):
120122
# type: () -> str
121123
return "<{}: {}>".format(self.__class__.__name__, self.name)
122124

125+
@property
126+
def scene(self):
127+
# type: () -> compas.scene.Scene
128+
return self.tree
129+
123130
@property
124131
def item(self):
125132
# type: () -> compas.geometry.Geometry | compas.datastructures.Datastructure

src/compas_blender/scene/capsuleobject.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def draw(
6464
vertices, faces = self.geometry.to_vertices_and_faces(u=u, v=v)
6565
mesh = conversions.vertices_and_faces_to_blender_mesh(vertices, faces, name=self.geometry.name)
6666
if shade_smooth:
67-
print(dir(mesh))
6867
mesh.shade_smooth()
6968

7069
obj = self.create_object(mesh, name=name)

src/compas_rhino/conversions/geometry.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function
44

55
import Rhino # type: ignore
6+
from System import MissingMemberException # type: ignore
67

78
from compas.geometry import Frame
89
from compas.geometry import Plane
@@ -103,14 +104,20 @@ def point_to_compas(point):
103104
104105
Parameters
105106
----------
106-
point : :rhino:`Rhino.Geometry.Point3d`
107+
point : :rhino:`Rhino.Geometry.Point3d` | :rhino:`Rhino.Geometry.Point`
107108
108109
Returns
109110
-------
110111
:class:`compas.geometry.Point`
111112
112113
"""
113-
return Point(point.X, point.Y, point.Z)
114+
try:
115+
return Point(point.X, point.Y, point.Z)
116+
except MissingMemberException:
117+
try:
118+
return Point(point.Location.X, point.Location.Y, point.Location.Z)
119+
except MissingMemberException:
120+
raise TypeError("Unexpected point type, got: {}".format(type(point)))
114121

115122

116123
def vector_to_compas(vector):

src/compas_rhino/geometry/brep/brep.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ def slice(self, plane):
534534
if isinstance(plane, Frame):
535535
plane = Plane.from_frame(plane)
536536
curves = Rhino.Geometry.Brep.CreateContourCurves(self._brep, plane_to_rhino(plane))
537-
print("curves:{}".format(curves))
538537
return [curve_to_compas(curve) for curve in curves]
539538

540539
def split(self, cutter):

0 commit comments

Comments
 (0)