Skip to content

Commit

Permalink
local setup wrongly configured
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Jan 15, 2024
1 parent 9702d00 commit 1995ac5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
42 changes: 21 additions & 21 deletions src/compas/datastructures/assembly/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import division

from compas.datastructures import Datastructure
from compas.datastructures import Graph
from compas.datastructures import Network
from .exceptions import AssemblyError


Expand All @@ -19,8 +19,8 @@ class Assembly(Datastructure):
----------
attributes : dict[str, Any]
General attributes of the data structure that will be included in the data dict and serialization.
graph : :class:`compas.datastructures.Graph`
The graph that is used under the hood to store the parts and their connections.
network : :class:`compas.datastructures.Network`
The network that is used under the hood to store the parts and their connections.
See Also
--------
Expand All @@ -34,21 +34,21 @@ class Assembly(Datastructure):
"type": "object",
"properties": {
"attributes": {"type": "object"},
"graph": Graph.DATASCHEMA,
"network": Network.DATASCHEMA,
},
"required": ["graph"],
"required": ["network"],
}

def __init__(self, name=None, **kwargs):
super(Assembly, self).__init__()
self.attributes = {"name": name or "Assembly"}
self.attributes.update(kwargs)
self.graph = Graph()
self.network = Network()
self._parts = {}

def __str__(self):
tpl = "<Assembly with {} parts and {} connections>"
return tpl.format(self.graph.number_of_nodes(), self.graph.number_of_edges())
return tpl.format(self.network.number_of_nodes(), self.network.number_of_edges())

# ==========================================================================
# Data
Expand All @@ -58,14 +58,14 @@ def __str__(self):
def data(self):
return {
"attributes": self.attributes,
"graph": self.graph.data,
"network": self.network.data,
}

@classmethod
def from_data(cls, data):
assembly = cls()
assembly.attributes.update(data["attributes"] or {})
assembly.graph = Graph.from_data(data["graph"])
assembly.network = Network.from_data(data["network"])
assembly._parts = {part.guid: part.key for part in assembly.parts()} # type: ignore
return assembly

Expand Down Expand Up @@ -107,12 +107,12 @@ def add_part(self, part, key=None, **kwargs):
Returns
-------
int | str
The identifier of the part in the current assembly graph.
The identifier of the part in the current assembly network.
"""
if part.guid in self._parts:
raise AssemblyError("Part already added to the assembly")
key = self.graph.add_node(key=key, part=part, **kwargs)
key = self.network.add_node(key=key, part=part, **kwargs)
part.key = key
self._parts[part.guid] = part.key
return key
Expand Down Expand Up @@ -143,9 +143,9 @@ def add_connection(self, a, b, **kwargs):
error_msg = "Both parts have to be added to the assembly before a connection can be created."
if a.key is None or b.key is None:
raise AssemblyError(error_msg)
if not self.graph.has_node(a.key) or not self.graph.has_node(b.key):
if not self.network.has_node(a.key) or not self.network.has_node(b.key):
raise AssemblyError(error_msg)
return self.graph.add_edge(a.key, b.key, **kwargs)
return self.network.add_edge(a.key, b.key, **kwargs)

def delete_part(self, part):
"""Remove a part from the assembly.
Expand All @@ -161,7 +161,7 @@ def delete_part(self, part):
"""
del self._parts[part.guid]
self.graph.delete_node(key=part.key)
self.network.delete_node(key=part.key)

def delete_connection(self, edge):
"""Delete a connection between two parts.
Expand All @@ -176,7 +176,7 @@ def delete_connection(self, edge):
None
"""
self.graph.delete_edge(edge=edge)
self.network.delete_edge(edge=edge)

def parts(self):
"""The parts of the assembly.
Expand All @@ -187,8 +187,8 @@ def parts(self):
The individual parts of the assembly.
"""
for node in self.graph.nodes():
yield self.graph.node_attribute(node, "part")
for node in self.network.nodes():
yield self.network.node_attribute(node, "part")

def connections(self, data=False):
"""Iterate over the connections between the parts.
Expand All @@ -205,7 +205,7 @@ def connections(self, data=False):
If `data` is True, the next connector identifier and its attributes as a ((u, v), attr) tuple.
"""
return self.graph.edges(data)
return self.network.edges(data)

def find(self, guid):
"""Find a part in the assembly by its GUID.
Expand All @@ -228,7 +228,7 @@ def find(self, guid):
if key is None:
return None

return self.graph.node_attribute(key, "part")
return self.network.node_attribute(key, "part")

def find_by_key(self, key):
"""Find a part in the assembly by its key.
Expand All @@ -245,7 +245,7 @@ def find_by_key(self, key):
or None if the part can't be found.
"""
if key not in self.graph.node:
if key not in self.network.node:
return None

return self.graph.node_attribute(key, "part")
return self.network.node_attribute(key, "part")
14 changes: 7 additions & 7 deletions tests/compas/data/test_dataschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from compas.geometry import Torus
from compas.geometry import Pointcloud

from compas.datastructures import Graph
from compas.datastructures import Network
from compas.datastructures import HalfEdge

if not compas.IPY:
Expand Down Expand Up @@ -593,7 +593,7 @@ def test_schema_pointcloud_invalid(pointcloud):
Pointcloud.validate_data(pointcloud)

@pytest.mark.parametrize(
"graph",
"network",
[
{
"dna": {},
Expand All @@ -618,11 +618,11 @@ def test_schema_pointcloud_invalid(pointcloud):
},
],
)
def test_schema_graph_valid(graph):
Graph.validate_data(graph)
def test_schema_network_valid(network):
Network.validate_data(network)

@pytest.mark.parametrize(
"graph",
"network",
[
{
"dna": {},
Expand Down Expand Up @@ -663,9 +663,9 @@ def test_schema_graph_valid(graph):
},
],
)
def test_schema_graph_invalid(graph):
def test_schema_network_invalid(network):
with pytest.raises(jsonschema.exceptions.ValidationError):
Graph.validate_data(graph)
Network.validate_data(network)

@pytest.mark.parametrize(
"halfedge",
Expand Down
3 changes: 1 addition & 2 deletions tests/compas/topology/test_traversal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from compas.datastructures import Graph
from compas.datastructures import Mesh
from compas.datastructures import Network
from compas.geometry import Box, Frame
Expand Down Expand Up @@ -49,7 +48,7 @@ def test_astar_shortest_path_mesh():


def test_astar_lightest_path():
g = Graph()
g = Network()
for i in range(4):
g.add_node(i)
g.add_edge(0, 1)
Expand Down

0 comments on commit 1995ac5

Please sign in to comment.