Skip to content

Commit a186957

Browse files
committed
temp unstructured stuff for data structures
1 parent d5bab1d commit a186957

File tree

7 files changed

+27
-2
lines changed

7 files changed

+27
-2
lines changed

src/compas/datastructures/assembly/assembly.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,22 @@ class Assembly(Datastructure):
3434
"type": "object",
3535
"properties": {
3636
"graph": Graph.DATASCHEMA,
37+
"attributes": {"type": "object"},
3738
},
38-
"required": ["graph"],
39+
"required": ["graph", "attributes"],
3940
}
4041

4142
@property
4243
def __data__(self):
4344
return {
4445
"graph": self.graph.__data__,
46+
"attributes": self.attributes,
4547
}
4648

4749
@classmethod
4850
def __from_data__(cls, data):
4951
assembly = cls()
52+
assembly.attributes.update(data["attributes"] or {})
5053
assembly.graph = Graph.__from_data__(data["graph"])
5154
assembly._parts = {part.guid: part.key for part in assembly.parts()} # type: ignore
5255
return assembly

src/compas/datastructures/cell_network/cell_network.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CellNetwork(Datastructure):
8585
DATASCHEMA = {
8686
"type": "object",
8787
"properties": {
88+
"attributes": {"type": "object"},
8889
"default_vertex_attributes": {"type": "object"},
8990
"default_edge_attributes": {"type": "object"},
9091
"default_face_attributes": {"type": "object"},
@@ -146,6 +147,7 @@ class CellNetwork(Datastructure):
146147
"max_cell": {"type": "number", "minimum": -1},
147148
},
148149
"required": [
150+
"attributes",
149151
"default_vertex_attributes",
150152
"default_edge_attributes",
151153
"default_face_attributes",
@@ -173,6 +175,7 @@ def __data__(self):
173175
cell[c] = sorted(list(faces))
174176

175177
return {
178+
"attributes": self.attributes,
176179
"default_vertex_attributes": self.default_vertex_attributes,
177180
"default_edge_attributes": self.default_edge_attributes,
178181
"default_face_attributes": self.default_face_attributes,
@@ -196,6 +199,7 @@ def __from_data__(cls, data):
196199
default_face_attributes=data.get("default_face_attributes"),
197200
default_cell_attributes=data.get("default_cell_attributes"),
198201
)
202+
cell_network.attributes.update(data.get("attributes") or {})
199203

200204
vertex = data["vertex"] or {}
201205
edge = data["edge"] or {}

src/compas/datastructures/graph/graph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Graph(Datastructure):
9090
DATASCHEMA = {
9191
"type": "object",
9292
"properties": {
93+
"attributes": {"type": "object"},
9394
"default_node_attributes": {"type": "object"},
9495
"default_edge_attributes": {"type": "object"},
9596
"node": {
@@ -106,6 +107,7 @@ class Graph(Datastructure):
106107
"max_node": {"type": "integer", "minimum": -1},
107108
},
108109
"required": [
110+
"attributes",
109111
"default_node_attributes",
110112
"default_edge_attributes",
111113
"node",
@@ -118,6 +120,7 @@ class Graph(Datastructure):
118120
def __data__(self):
119121
return self.__before_json_dump__(
120122
{
123+
"attributes": self.attributes,
121124
"default_node_attributes": self.default_node_attributes,
122125
"default_edge_attributes": self.default_edge_attributes,
123126
"node": self.node,
@@ -145,6 +148,7 @@ def __from_data__(cls, data):
145148
default_node_attributes=data.get("default_node_attributes"),
146149
default_edge_attributes=data.get("default_edge_attributes"),
147150
)
151+
graph.attributes.update(data["attributes"] or {})
148152
data = graph.__after_json_load__(data)
149153
for node, attr in iter(data["node"].items()):
150154
graph.add_node(key=node, attr_dict=attr)

src/compas/datastructures/mesh/mesh.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class Mesh(Datastructure):
138138
DATASCHEMA = {
139139
"type": "object",
140140
"properties": {
141+
"attributes": {"type": "object"},
141142
"default_vertex_attributes": {"type": "object"},
142143
"default_edge_attributes": {"type": "object"},
143144
"default_face_attributes": {"type": "object"},
@@ -171,6 +172,7 @@ class Mesh(Datastructure):
171172
"max_face": {"type": "integer", "minimum": -1},
172173
},
173174
"required": [
175+
"attributes",
174176
"default_vertex_attributes",
175177
"default_edge_attributes",
176178
"default_face_attributes",
@@ -187,6 +189,7 @@ class Mesh(Datastructure):
187189
def __data__(self):
188190
return self.__before_json_dump__(
189191
{
192+
"attributes": self.attributes,
190193
"default_vertex_attributes": self.default_vertex_attributes,
191194
"default_edge_attributes": self.default_edge_attributes,
192195
"default_face_attributes": self.default_face_attributes,
@@ -212,6 +215,7 @@ def __from_data__(cls, data):
212215
default_face_attributes=data.get("default_face_attributes"),
213216
default_edge_attributes=data.get("default_edge_attributes"),
214217
)
218+
mesh.attributes.update(data.get("attributes") or {})
215219

216220
vertex = data["vertex"] or {}
217221
face = data["face"] or {}

src/compas/datastructures/tree/tree.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,22 @@ class Tree(Datastructure):
246246
"type": "object",
247247
"properties": {
248248
"root": TreeNode.DATASCHEMA,
249+
"attributes": {"type": "object"},
249250
},
250-
"required": ["root"],
251+
"required": ["root", "attributes"],
251252
}
252253

253254
@property
254255
def __data__(self):
255256
return {
257+
"attributes": self.attributes,
256258
"root": self.root.__data__, # type: ignore
257259
}
258260

259261
@classmethod
260262
def __from_data__(cls, data):
261263
tree = cls()
264+
tree.attributes.update(data["attributes"] or {})
262265
root = TreeNode.__from_data__(data["root"])
263266
tree.add(root)
264267
return tree

src/compas/datastructures/volmesh/volmesh.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class VolMesh(Datastructure):
8080
DATASCHEMA = {
8181
"type": "object",
8282
"properties": {
83+
"attributes": {"type": "object"},
8384
"default_vertex_attributes": {"type": "object"},
8485
"default_edge_attributes": {"type": "object"},
8586
"default_face_attributes": {"type": "object"},
@@ -124,6 +125,7 @@ class VolMesh(Datastructure):
124125
"max_cell": {"type": "number", "minimum": -1},
125126
},
126127
"required": [
128+
"attributes",
127129
"default_vertex_attributes",
128130
"default_edge_attributes",
129131
"default_face_attributes",
@@ -149,6 +151,7 @@ def __data__(self):
149151
_cell[c] = faces
150152

151153
return {
154+
"attributes": self.attributes,
152155
"default_vertex_attributes": self.default_vertex_attributes,
153156
"default_edge_attributes": self.default_edge_attributes,
154157
"default_face_attributes": self.default_face_attributes,
@@ -171,6 +174,7 @@ def __from_data__(cls, data):
171174
default_face_attributes=data.get("default_face_attributes"),
172175
default_cell_attributes=data.get("default_cell_attributes"),
173176
)
177+
volmesh.attributes.update(data["attributes"] or {})
174178

175179
vertex = data["vertex"] or {}
176180
cell = data["cell"] or {}

tests/compas/data/test_dataschema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,20 +596,23 @@ def test_schema_pointcloud_invalid(pointcloud):
596596
"graph",
597597
[
598598
{
599+
"attributes": {},
599600
"default_node_attributes": {},
600601
"default_edge_attributes": {},
601602
"node": {},
602603
"edge": {},
603604
"max_node": -1,
604605
},
605606
{
607+
"attributes": {},
606608
"default_node_attributes": {},
607609
"default_edge_attributes": {},
608610
"node": {},
609611
"edge": {},
610612
"max_node": 0,
611613
},
612614
{
615+
"attributes": {},
613616
"default_node_attributes": {},
614617
"default_edge_attributes": {},
615618
"node": {},

0 commit comments

Comments
 (0)