Skip to content

Commit

Permalink
Merge branch 'main' into update/sceneobject
Browse files Browse the repository at this point in the history
  • Loading branch information
Licini committed Jun 10, 2024
2 parents 5f7dd1d + 10a8ee1 commit 70f63f9
Show file tree
Hide file tree
Showing 40 changed files with 1,113 additions and 2,208 deletions.
25 changes: 21 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added implementation of `compute_vertices`, `compute_edges`, `compute_faces` to `compas.geometry.Cylinder`.
* Added implementation of `compute_vertices`, `compute_edges`, `compute_faces` to `compas.geometry.Sphere`.
* Added implementation of `compute_vertices`, `compute_edges`, `compute_faces` to `compas.geometry.Torus`.
* Added `compas_blender.scene.ShapeObject`.
* Added `compas.geometry.vector.__radd__`.
* Added `compas.geometry.vector.__rsub__`.
* Added `compas.geometry.vector.__rmul__`.
* Added `compas.geometry.vector.__rtruediv__`.

### Changed

Expand All @@ -28,10 +33,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed check for empty vertices and faces to use `is None` to add support for `numpy` arrays.
* Changed order of `u` and `v` of `compas.geometry.SphericalSurface` to the match the excpected parametrisation.
* Changed `compas.geometry.Shape.to_vertices_and_faces` to use `Shape.vertices` and `Shape.faces` or `Shape.triangles`.

### Removed

* Removed `System`dependency in `compas_ghpython/utilities/drawing.py`.
* Changed default of `compas.scene.descriptors.color.ColorAttribute` to `None` to support native coloring in CAD contexts.
* Changed `compas.colors.ColorDict.__data__` and `compas.colors.ColorDict.__from_data__` to properly support serialisation.
* Moved `compas_blender.utilities.drawing` to `compas_blender.drawing` with backward compatible imports and deprecation warning.
* Moved `compas_ghpython.utilities.drawing` to `compas_ghpython.drawing` with backward compatible imports and deprecation warning.
* Moved `compas_rhino.utilities.drawing` to `compas_rhino.drawing` with backward compatible imports and deprecation warning.
* Changed `draw_nodes` and `draw_edges` of `compas_blender.scene.GraphObject`, `compas_ghpython.scene.GraphObject`, and `compas_rhino.scene.GraphObject` to use only attributes instead of parameters.
* Changed `draw_vertices`, `draw_edges` and `draw_faces` of `compas_blender.scene.MeshObject`, `compas_ghpython.scene.MeshObject`, and `compas_rhino.scene.MeshObject` to use only attributes instead of parameters.
* Changed `draw_vertices`, `draw_edges` and `draw_faces` of `compas_blender.scene.VolMeshObject`, `compas_ghpython.scene.VolMeshObject`, and `compas_rhino.scene.VolMeshObject` to use only attributes instead of parameters.
* Changed registration of `Capsule`, `Cone`, `Cylinder`, `Sphere`, `Torus` to `ShapeObject` in `compas_blender.scene`.
* Updated `compas.geometry.vector.__mul__` to allow element-wise multiplication with another vector.
* Updated `compas.geometry.vector.__truediv__` to allow element-wise division with another vector.

### Removed

* Removed `System` dependency in `compas_ghpython/utilities/drawing.py`.
* Removed GH plugin for `compas.scene.clear` since it clashed with the Rhino version.

## [2.1.1] 2024-05-14

Expand Down
10 changes: 9 additions & 1 deletion src/compas/colors/colordict.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ class ColorDict(Data):

@property
def __data__(self):
return {"default": self.default.__data__, "dict": self._dict}
return {"default": self.default, "dict": self._dict}

@classmethod
def __from_data__(cls, data):
colordict = cls(data["default"])
# note: this is specific to color dicts for vertices of meshes
# perhaps the color dict needs to be subclassed per scene object type
colordict.update({int(key): value for key, value in data["dict"].items()})
return colordict

def __init__(self, default, name=None):
super(ColorDict, self).__init__(name=name)
Expand Down
44 changes: 39 additions & 5 deletions src/compas/geometry/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,25 @@ def __add__(self, other):
def __sub__(self, other):
return Vector(self.x - other[0], self.y - other[1], self.z - other[2])

def __mul__(self, n):
return Vector(self.x * n, self.y * n, self.z * n)

def __truediv__(self, n):
return Vector(self.x / n, self.y / n, self.z / n)
def __mul__(self, other):
if isinstance(other, (int, float)):
return Vector(self.x * other, self.y * other, self.z * other)

try:
other = Vector(*other)
return Vector(self.x * other.x, self.y * other.y, self.z * other.z)
except TypeError:
raise TypeError("Cannot cast {} {} to Vector".format(other, type(other)))

def __truediv__(self, other):
if isinstance(other, (int, float)):
return Vector(self.x / other, self.y / other, self.z / other)

try:
other = Vector(*other)
return Vector(self.x / other.x, self.y / other.y, self.z / other.z)
except TypeError:
raise TypeError("Cannot cast {} {} to Vector".format(other, type(other)))

def __pow__(self, n):
return Vector(self.x**n, self.y**n, self.z**n)
Expand Down Expand Up @@ -190,6 +204,26 @@ def __ipow__(self, n):
self.z **= n
return self

def __rmul__(self, n):
return self.__mul__(n)

def __radd__(self, other):
return self.__add__(other)

def __rsub__(self, other):
try:
other = Vector(*other)
return other - self
except TypeError:
raise TypeError("Cannot cast {} {} to Vector".format(other, type(other)))

def __rtruediv__(self, other):
try:
other = Vector(*other)
return other / self
except TypeError:
raise TypeError("Cannot cast {} {} to Vector".format(other, type(other)))

# ==========================================================================
# Properties
# ==========================================================================
Expand Down
3 changes: 0 additions & 3 deletions src/compas/scene/assemblyobject.py

This file was deleted.

1 change: 0 additions & 1 deletion src/compas/scene/descriptors/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ColorAttribute(object):

def __init__(self, default=None, **kwargs):
super(ColorAttribute, self).__init__(**kwargs)
default = default or Color.black()
self.default = Color.coerce(default)

def __set_name__(self, owner, name):
Expand Down
4 changes: 0 additions & 4 deletions src/compas/scene/geometryobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def __init__(self, pointcolor=None, linecolor=None, surfacecolor=None, pointsize
self.show_lines = show_lines
self.show_surfaces = show_surfaces

@property
def geometry(self):
return self.item

def draw(self):
"""Draw the geometry. Implemented by child classes."""
raise NotImplementedError
72 changes: 38 additions & 34 deletions src/compas/scene/graphobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import division
from __future__ import print_function

import compas.colors # noqa: F401
from compas.geometry import transform_points

from .descriptors.colordict import ColorDictAttribute
Expand Down Expand Up @@ -32,7 +31,7 @@ class GraphObject(SceneObject):
The size of the nodes. Default is ``1.0``.
edgewidth : float
The width of the edges. Default is ``1.0``.
show_nodes : Union[bool, sequence[float]]
show_nodes : Union[bool, sequence[hashable]]
Flag for showing or hiding the nodes. Default is ``True``.
show_edges : Union[bool, sequence[tuple[hashable, hashable]]]
Flag for showing or hiding the edges. Default is ``True``.
Expand All @@ -58,46 +57,62 @@ def __init__(self, nodecolor=None, edgecolor=None, nodesize=1.0, edgewidth=1.0,
self.show_nodes = show_nodes
self.show_edges = show_edges

@property
def settings(self):
# type: () -> dict
settings = super(GraphObject, self).settings
settings["show_nodes"] = self.show_nodes
settings["show_edges"] = self.show_edges
settings["nodecolor"] = self.nodecolor
settings["edgecolor"] = self.edgecolor
settings["nodesize"] = self.nodesize
settings["edgewidth"] = self.edgewidth
return settings

@property
def graph(self):
return self.item

@graph.setter
def graph(self, graph):
# type: (compas.datastructures.Graph) -> None
self._graph = graph
self._transformation = None
self._node_xyz = None

@property
def transformation(self):
# type: () -> compas.geometry.Transformation | None
return self._transformation

@transformation.setter
def transformation(self, transformation):
# type: (compas.geometry.Transformation) -> None
self._node_xyz = None
self._transformation = transformation

@property
def node_xyz(self):
# type: () -> dict[int | str | tuple, list[float]]
if self._node_xyz is None:
points = self.graph.nodes_attributes("xyz") # type: ignore
points = self.graph.nodes_attributes("xyz")
points = transform_points(points, self.worldtransformation)
self._node_xyz = dict(zip(self.graph.nodes(), points)) # type: ignore
self._node_xyz = dict(zip(self.graph.nodes(), points))
return self._node_xyz

@node_xyz.setter
def node_xyz(self, node_xyz):
# type: (dict[int | str | tuple, list[float]]) -> None
self._node_xyz = node_xyz

def draw_nodes(self, nodes=None, color=None, text=None):
def draw_nodes(self):
"""Draw the nodes of the graph.
Parameters
----------
nodes : list[int], optional
The nodes to include in the drawing.
Default is all nodes.
color : tuple[float, float, float] | :class:`compas.colors.Color` | dict[int, tuple[float, float, float] | :class:`compas.colors.Color`], optional
The color of the nodes,
as either a single color to be applied to all nodes,
or a color dict, mapping specific nodes to specific colors.
text : dict[int, str], optional
The text labels for the nodes
as a text dict, mapping specific nodes to specific text labels.
Nodes are drawn based on the values of
* `self.show_nodes`
* `self.nodecolor`
* `self.nodesize`
Returns
-------
Expand All @@ -107,21 +122,14 @@ def draw_nodes(self, nodes=None, color=None, text=None):
"""
raise NotImplementedError

def draw_edges(self, edges=None, color=None, text=None):
def draw_edges(self):
"""Draw the edges of the graph.
Parameters
----------
edges : list[tuple[int, int]], optional
The edges to include in the drawing.
Default is all edges.
color : tuple[float, float, float] | :class:`compas.colors.Color` | dict[tuple[int, int], tuple[float, float, float] | :class:`compas.colors.Color`], optional
The color of the edges,
as either a single color to be applied to all edges,
or a color dict, mapping specific edges to specific colors.
text : dict[tuple[int, int]], optional
The text labels for the edges
as a text dict, mapping specific edges to specific text labels.
Edges are drawn based on the values of
* `self.show_edges`
* `self.edgecolor`
* `self.edgewidth`
Returns
-------
Expand All @@ -131,10 +139,6 @@ def draw_edges(self, edges=None, color=None, text=None):
"""
raise NotImplementedError

def draw(self):
"""Draw the network."""
raise NotImplementedError

def clear_nodes(self):
"""Clear the nodes of the graph.
Expand Down
Loading

0 comments on commit 70f63f9

Please sign in to comment.