topologicpy 0.5.8__py3-none-any.whl → 6.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. topologicpy/Aperture.py +72 -72
  2. topologicpy/Cell.py +2169 -2169
  3. topologicpy/CellComplex.py +1137 -1137
  4. topologicpy/Cluster.py +1288 -1280
  5. topologicpy/Color.py +423 -393
  6. topologicpy/Context.py +79 -79
  7. topologicpy/DGL.py +3213 -3136
  8. topologicpy/Dictionary.py +698 -695
  9. topologicpy/Edge.py +1187 -1187
  10. topologicpy/EnergyModel.py +1180 -1171
  11. topologicpy/Face.py +2141 -2141
  12. topologicpy/Graph.py +7768 -7700
  13. topologicpy/Grid.py +353 -353
  14. topologicpy/Helper.py +507 -507
  15. topologicpy/Honeybee.py +461 -461
  16. topologicpy/Matrix.py +271 -271
  17. topologicpy/Neo4j.py +521 -521
  18. topologicpy/Plotly.py +2 -2
  19. topologicpy/Polyskel.py +541 -541
  20. topologicpy/Shell.py +1768 -1768
  21. topologicpy/Speckle.py +508 -508
  22. topologicpy/Topology.py +7060 -6988
  23. topologicpy/Vector.py +905 -905
  24. topologicpy/Vertex.py +1585 -1585
  25. topologicpy/Wire.py +3050 -3050
  26. topologicpy/__init__.py +22 -38
  27. topologicpy/version.py +1 -0
  28. {topologicpy-0.5.8.dist-info → topologicpy-6.0.0.dist-info}/LICENSE +661 -704
  29. topologicpy-6.0.0.dist-info/METADATA +751 -0
  30. topologicpy-6.0.0.dist-info/RECORD +32 -0
  31. topologicpy/bin/linux/topologic/__init__.py +0 -2
  32. topologicpy/bin/linux/topologic/libTKBO-6bdf205d.so.7.7.0 +0 -0
  33. topologicpy/bin/linux/topologic/libTKBRep-2960a069.so.7.7.0 +0 -0
  34. topologicpy/bin/linux/topologic/libTKBool-c44b74bd.so.7.7.0 +0 -0
  35. topologicpy/bin/linux/topologic/libTKFillet-9a670ba0.so.7.7.0 +0 -0
  36. topologicpy/bin/linux/topologic/libTKG2d-8f31849e.so.7.7.0 +0 -0
  37. topologicpy/bin/linux/topologic/libTKG3d-4c6bce57.so.7.7.0 +0 -0
  38. topologicpy/bin/linux/topologic/libTKGeomAlgo-26066fd9.so.7.7.0 +0 -0
  39. topologicpy/bin/linux/topologic/libTKGeomBase-2116cabe.so.7.7.0 +0 -0
  40. topologicpy/bin/linux/topologic/libTKMath-72572fa8.so.7.7.0 +0 -0
  41. topologicpy/bin/linux/topologic/libTKMesh-2a060427.so.7.7.0 +0 -0
  42. topologicpy/bin/linux/topologic/libTKOffset-6cab68ff.so.7.7.0 +0 -0
  43. topologicpy/bin/linux/topologic/libTKPrim-eb1262b3.so.7.7.0 +0 -0
  44. topologicpy/bin/linux/topologic/libTKShHealing-e67e5cc7.so.7.7.0 +0 -0
  45. topologicpy/bin/linux/topologic/libTKTopAlgo-e4c96c33.so.7.7.0 +0 -0
  46. topologicpy/bin/linux/topologic/libTKernel-fb7fe3b7.so.7.7.0 +0 -0
  47. topologicpy/bin/linux/topologic/libgcc_s-32c1665e.so.1 +0 -0
  48. topologicpy/bin/linux/topologic/libstdc++-672d7b41.so.6.0.30 +0 -0
  49. topologicpy/bin/linux/topologic/topologic.cpython-310-x86_64-linux-gnu.so +0 -0
  50. topologicpy/bin/linux/topologic/topologic.cpython-311-x86_64-linux-gnu.so +0 -0
  51. topologicpy/bin/linux/topologic/topologic.cpython-38-x86_64-linux-gnu.so +0 -0
  52. topologicpy/bin/linux/topologic/topologic.cpython-39-x86_64-linux-gnu.so +0 -0
  53. topologicpy/bin/linux/topologic.libs/libTKBO-6bdf205d.so.7.7.0 +0 -0
  54. topologicpy/bin/linux/topologic.libs/libTKBRep-2960a069.so.7.7.0 +0 -0
  55. topologicpy/bin/linux/topologic.libs/libTKBool-c44b74bd.so.7.7.0 +0 -0
  56. topologicpy/bin/linux/topologic.libs/libTKFillet-9a670ba0.so.7.7.0 +0 -0
  57. topologicpy/bin/linux/topologic.libs/libTKG2d-8f31849e.so.7.7.0 +0 -0
  58. topologicpy/bin/linux/topologic.libs/libTKG3d-4c6bce57.so.7.7.0 +0 -0
  59. topologicpy/bin/linux/topologic.libs/libTKGeomAlgo-26066fd9.so.7.7.0 +0 -0
  60. topologicpy/bin/linux/topologic.libs/libTKGeomBase-2116cabe.so.7.7.0 +0 -0
  61. topologicpy/bin/linux/topologic.libs/libTKMath-72572fa8.so.7.7.0 +0 -0
  62. topologicpy/bin/linux/topologic.libs/libTKMesh-2a060427.so.7.7.0 +0 -0
  63. topologicpy/bin/linux/topologic.libs/libTKOffset-6cab68ff.so.7.7.0 +0 -0
  64. topologicpy/bin/linux/topologic.libs/libTKPrim-eb1262b3.so.7.7.0 +0 -0
  65. topologicpy/bin/linux/topologic.libs/libTKShHealing-e67e5cc7.so.7.7.0 +0 -0
  66. topologicpy/bin/linux/topologic.libs/libTKTopAlgo-e4c96c33.so.7.7.0 +0 -0
  67. topologicpy/bin/linux/topologic.libs/libTKernel-fb7fe3b7.so.7.7.0 +0 -0
  68. topologicpy/bin/linux/topologic.libs/libgcc_s-32c1665e.so.1 +0 -0
  69. topologicpy/bin/linux/topologic.libs/libstdc++-672d7b41.so.6.0.30 +0 -0
  70. topologicpy/bin/macos/topologic/__init__.py +0 -2
  71. topologicpy/bin/windows/topologic/TKBO-f6b191de.dll +0 -0
  72. topologicpy/bin/windows/topologic/TKBRep-e56a600e.dll +0 -0
  73. topologicpy/bin/windows/topologic/TKBool-7b8d47ae.dll +0 -0
  74. topologicpy/bin/windows/topologic/TKFillet-0ddbf0a8.dll +0 -0
  75. topologicpy/bin/windows/topologic/TKG2d-2e2dee3d.dll +0 -0
  76. topologicpy/bin/windows/topologic/TKG3d-6674513d.dll +0 -0
  77. topologicpy/bin/windows/topologic/TKGeomAlgo-d240e370.dll +0 -0
  78. topologicpy/bin/windows/topologic/TKGeomBase-df87aba5.dll +0 -0
  79. topologicpy/bin/windows/topologic/TKMath-45bd625a.dll +0 -0
  80. topologicpy/bin/windows/topologic/TKMesh-d6e826b1.dll +0 -0
  81. topologicpy/bin/windows/topologic/TKOffset-79b9cc94.dll +0 -0
  82. topologicpy/bin/windows/topologic/TKPrim-aa430a86.dll +0 -0
  83. topologicpy/bin/windows/topologic/TKShHealing-bb48be89.dll +0 -0
  84. topologicpy/bin/windows/topologic/TKTopAlgo-7d0d1e22.dll +0 -0
  85. topologicpy/bin/windows/topologic/TKernel-08c8cfbb.dll +0 -0
  86. topologicpy/bin/windows/topologic/__init__.py +0 -2
  87. topologicpy/bin/windows/topologic/topologic.cp310-win_amd64.pyd +0 -0
  88. topologicpy/bin/windows/topologic/topologic.cp311-win_amd64.pyd +0 -0
  89. topologicpy/bin/windows/topologic/topologic.cp38-win_amd64.pyd +0 -0
  90. topologicpy/bin/windows/topologic/topologic.cp39-win_amd64.pyd +0 -0
  91. topologicpy-0.5.8.dist-info/METADATA +0 -96
  92. topologicpy-0.5.8.dist-info/RECORD +0 -91
  93. {topologicpy-0.5.8.dist-info → topologicpy-6.0.0.dist-info}/WHEEL +0 -0
  94. {topologicpy-0.5.8.dist-info → topologicpy-6.0.0.dist-info}/top_level.txt +0 -0
topologicpy/Speckle.py CHANGED
@@ -1,509 +1,509 @@
1
- # Copyright (C) 2024
2
- # Wassim Jabi <wassim.jabi@gmail.com>
3
- #
4
- # This program is free software: you can redistribute it and/or modify it under
5
- # the terms of the GNU Affero General Public License as published by the Free Software
6
- # Foundation, either version 3 of the License, or (at your option) any later
7
- # version.
8
- #
9
- # This program is distributed in the hope that it will be useful, but WITHOUT
10
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
- # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
12
- # details.
13
- #
14
- # You should have received a copy of the GNU Affero General Public License along with
15
- # this program. If not, see <https://www.gnu.org/licenses/>.
16
-
17
- from specklepy.api.client import SpeckleClient
18
- from specklepy.api.wrapper import StreamWrapper
19
- from specklepy.api import operations
20
- from specklepy.objects import Base
21
- from specklepy.objects.other import RenderMaterial
22
- from specklepy.transports.server import ServerTransport
23
- from topologicpy.Topology import Topology
24
- from specklepy.objects.geometry import (Mesh, Point, Polyline)
25
- class Speckle:
26
-
27
- @staticmethod
28
- def mesh_to_speckle(topology) -> Base:
29
- b = Base()
30
- b["name"] = "Topologic_Object"
31
- b["@displayValue"] = Speckle.mesh_to_speckle_mesh(topology)
32
- return b
33
-
34
- @staticmethod
35
- def mesh_to_speckle_mesh(topology, mantissa: int = 6) -> Mesh:
36
-
37
- geom = Topology.Geometry(topology, mantissa=mantissa)
38
- vertices = geom['vertices']
39
- faces = geom['faces']
40
- #m_verts: List[float] = []
41
- #m_faces: List[int] = []
42
- m_verts = []
43
- m_faces = []
44
-
45
- for v in vertices:
46
- m_verts.append(v[0])
47
- m_verts.append(v[1])
48
- m_verts.append(v[2])
49
-
50
- for f in faces:
51
- n = len(f)
52
- m_faces.append(n)
53
- for i in range(n):
54
- m_faces.append(f[i])
55
-
56
- speckle_mesh = Mesh(
57
- vertices=m_verts,
58
- faces=m_faces,
59
- )
60
- speckle_mat = RenderMaterial()
61
- speckle_mat['Opacity'] = 0.5
62
- speckle_mesh["renderMaterial"] = speckle_mat
63
- return speckle_mesh
64
-
65
- @staticmethod
66
- def SpeckleBranchByID(branch_list, branch_id):
67
- """
68
- Parameters
69
- ----------
70
- branch_list : TYPE
71
- DESCRIPTION.
72
- branch_id : TYPE
73
- DESCRIPTION.
74
-
75
- Returns
76
- -------
77
- branch : TYPE
78
- DESCRIPTION.
79
-
80
- """
81
- # branch_list, branch_id = item
82
- for branch in branch_list:
83
- if branch.id == branch_id:
84
- return branch
85
- return None
86
-
87
- @staticmethod
88
- def BranchesByStream(client, stream):
89
- """
90
- Parameters
91
- ----------
92
- client : TYPE
93
- DESCRIPTION.
94
- stream : TYPE
95
- DESCRIPTION.
96
-
97
- Returns
98
- -------
99
- branches : TYPE
100
- DESCRIPTION.
101
-
102
- """
103
- # client, stream = item
104
- bList = client.branch.list(stream.id)
105
- branches = []
106
- for b in bList:
107
- branches.append(client.branch.get(stream.id, b.name))
108
- return branches
109
-
110
- @staticmethod
111
- def ClientByURL(url="speckle.xyz", token=None):
112
- """
113
- Parameters
114
- ----------
115
- url : TYPE
116
- DESCRIPTION.
117
- token : TYPE
118
- DESCRIPTION.
119
-
120
- Returns
121
- -------
122
- client : TYPE
123
- DESCRIPTION.
124
-
125
- """
126
- import getpass
127
- if token == None:
128
- token = getpass.getpass()
129
- if token == None:
130
- print("Speckle.ClientByHost - Error: Could not retrieve token. Returning None.")
131
- return None
132
- client = SpeckleClient(host=url) # or whatever your host is
133
- client.authenticate_with_token(token)
134
- return client
135
-
136
- @staticmethod
137
- def CommitByID(commit_list, commit_id):
138
- """
139
- Parameters
140
- ----------
141
- commit_list : TYPE
142
- DESCRIPTION.
143
- commit_id : TYPE
144
- DESCRIPTION.
145
-
146
- Returns
147
- -------
148
- commit : TYPE
149
- DESCRIPTION.
150
-
151
- """
152
- # commit_list, commit_id = item
153
- for commit in commit_list:
154
- if commit.id == commit_id:
155
- return commit
156
- return None
157
-
158
- @staticmethod
159
- def SpeckleCommitByURL(url, token):
160
- """
161
- Parameters
162
- ----------
163
- url : TYPE
164
- DESCRIPTION.
165
- token : TYPE
166
- DESCRIPTION.
167
-
168
- Returns
169
- -------
170
- commit : TYPE
171
- DESCRIPTION.
172
-
173
- """
174
- # url, token = item
175
-
176
- def streamByID(item):
177
- stream_list, stream_id = item
178
- for stream in stream_list:
179
- if stream.id == stream_id:
180
- return stream
181
- return None
182
-
183
- def streamsByClient(client):
184
- return client.stream.list()
185
-
186
- def commitByID(item):
187
- commit_list, commit_id = item
188
- for commit in commit_list:
189
- if commit.id == commit_id:
190
- return commit
191
- return None
192
-
193
- # provide any stream, branch, commit, object, or globals url
194
- wrapper = StreamWrapper(url)
195
- client = wrapper.get_client()
196
- client.authenticate_with_token(token)
197
- print("Client", client)
198
- streams = streamsByClient(client)
199
- print("Streams", streams)
200
- stream = streamByID([streams, wrapper.stream_id])
201
- print("Stream", stream)
202
- commits = client.commit.list(wrapper.stream_id)
203
- commit = commitByID([commits, wrapper.commit_id])
204
- print(commit)
205
- return commit
206
-
207
- @staticmethod
208
- def SpeckleCommitDelete(client, stream, commit, confirm):
209
- """
210
- Parameters
211
- ----------
212
- client : TYPE
213
- DESCRIPTION.
214
- stream : TYPE
215
- DESCRIPTION.
216
- commit : TYPE
217
- DESCRIPTION.
218
- confirm : TYPE
219
- DESCRIPTION.
220
-
221
- Returns
222
- -------
223
- TYPE
224
- DESCRIPTION.
225
-
226
- """
227
- # client, stream, commit, confirm = item
228
- if confirm:
229
- try:
230
- deleted = client.commit.delete(stream_id=stream.id, commit_id=commit.id)
231
- return deleted
232
- except:
233
- return False
234
- return False
235
-
236
- @staticmethod
237
- def CommitsByBranch(branch):
238
- """
239
- Parameters
240
- ----------
241
- item : TYPE
242
- DESCRIPTION.
243
-
244
- Returns
245
- -------
246
- TYPE
247
- DESCRIPTION.
248
-
249
- """
250
- return branch.commits.items
251
-
252
- @staticmethod
253
- def SpeckleGlobalsByStream(client, stream):
254
- """
255
- Parameters
256
- ----------
257
- client : TYPE
258
- DESCRIPTION.
259
- stream : TYPE
260
- DESCRIPTION.
261
-
262
- Returns
263
- -------
264
- TYPE
265
- DESCRIPTION.
266
-
267
- """
268
- # client, stream = item
269
-
270
- def processBase(base):
271
- dictionary = {}
272
- dynamic_member_names = base.get_dynamic_member_names()
273
- for dynamic_member_name in dynamic_member_names:
274
- attribute = base[dynamic_member_name]
275
- if isinstance(attribute, float) or isinstance(attribute, int) or isinstance(attribute, str) or isinstance(attribute, list):
276
- dictionary[dynamic_member_name] = attribute
277
- if isinstance(attribute, Base):
278
- dictionary[dynamic_member_name] = processBase(attribute)
279
- return dictionary
280
-
281
- transport = ServerTransport(client=client, stream_id=stream.id)
282
-
283
- # get the `globals` branch
284
- branch = client.branch.get(stream.id, "globals")
285
-
286
- # get the latest commit
287
- if len(branch.commits.items) > 0:
288
- latest_commit = branch.commits.items[0]
289
-
290
- # receive the globals object
291
- globs = operations.receive(latest_commit.referencedObject, transport)
292
- return processBase(globs)
293
- return None
294
-
295
- @staticmethod
296
- def Send(client, stream, branch, description, message, key, data, run):
297
- """
298
- Parameters
299
- ----------
300
- client : TYPE
301
- DESCRIPTION.
302
- stream : TYPE
303
- DESCRIPTION.
304
- branch : TYPE
305
- DESCRIPTION.
306
- description : TYPE
307
- DESCRIPTION.
308
- message : TYPE
309
- DESCRIPTION.
310
- key : TYPE
311
- DESCRIPTION.
312
- data : TYPE
313
- DESCRIPTION.
314
- run : TYPE
315
- DESCRIPTION.
316
-
317
- Returns
318
- -------
319
- commit : TYPE
320
- DESCRIPTION.
321
-
322
- """
323
- # client, stream, branch, description, message, key, data, run = item
324
- if not run:
325
- return None
326
- # create a base object to hold data
327
- base = Base()
328
- base[key] = data
329
- transport = ServerTransport(stream.id, client)
330
- # and send the data to the server and get back the hash of the object
331
- obj_id = operations.send(base, [transport])
332
-
333
- # now create a commit on that branch with your updated data!
334
- commit_id = client.commit.create(
335
- stream.id,
336
- obj_id,
337
- key,
338
- message=message,
339
- )
340
- print("COMMIT ID", commit_id)
341
- for commit in branch.commits.items:
342
- print(" VS. COMMIT.ID", commit.id)
343
- if commit.id == commit_id:
344
- return commit
345
- return None
346
-
347
- @staticmethod
348
- def Object(client, stream, branch, commit):
349
- #from topologicpy.Dictionary import Dictionary
350
- from topologicpy.Topology import Topology
351
- def add_vertices(speckle_mesh, scale=1.0):
352
- sverts = speckle_mesh.vertices
353
- vertices = []
354
- if sverts and len(sverts) > 0:
355
- for i in range(0, len(sverts), 3):
356
- vertices.append([float(sverts[i]) * scale, float(sverts[i + 1]) * scale, float(sverts[i + 2]) * scale])
357
- return vertices
358
-
359
- def add_faces(speckle_mesh):
360
- sfaces = speckle_mesh.faces
361
- faces = []
362
- if sfaces and len(sfaces) > 0:
363
- i = 0
364
- while i < len(sfaces):
365
- n = sfaces[i]
366
- if n < 3:
367
- n += 3 # 0 -> 3, 1 -> 4
368
- i += 1
369
- faces.append([int(x) for x in sfaces[i : i + n]])
370
- i += n
371
- return faces
372
-
373
- def mesh_to_native(speckle_mesh, scale=1.0):
374
- vertices = add_vertices(speckle_mesh, scale)
375
- faces = add_faces(speckle_mesh)
376
- topology = Topology.ByGeometry(vertices=vertices, edges=[], faces=faces)
377
- return topology
378
-
379
- transport = ServerTransport(stream.id, client)
380
- last_obj_id = commit.referencedObject
381
- speckle_mesh = operations.receive(obj_id=last_obj_id, remote_transport=transport)
382
- print(speckle_mesh)
383
- return mesh_to_native(speckle_mesh["@display_value"])
384
-
385
- @staticmethod
386
- def SpeckleSendObjects(client, stream, branch, description, message, key, data, run):
387
- """
388
- Parameters
389
- ----------
390
- client : TYPE
391
- DESCRIPTION.
392
- stream : TYPE
393
- DESCRIPTION.
394
- branch : TYPE
395
- DESCRIPTION.
396
- description : TYPE
397
- DESCRIPTION.
398
- message : TYPE
399
- DESCRIPTION.
400
- key : TYPE
401
- DESCRIPTION.
402
- data : TYPE
403
- DESCRIPTION.
404
- run : TYPE
405
- DESCRIPTION.
406
-
407
- Returns
408
- -------
409
- commit : TYPE
410
- DESCRIPTION.
411
-
412
- """
413
- # client, stream, branch, description, message, key, data, run = item
414
- if not run:
415
- return None
416
- # create a base object to hold data
417
- base = Base()
418
- base[key] = data
419
- transport = ServerTransport(stream.id, client)
420
- # and send the data to the server and get back the hash of the object
421
- obj_id = operations.send(base, [transport])
422
-
423
- # now create a commit on that branch with your updated data!
424
- commit_id = client.commit.create(
425
- stream.id,
426
- obj_id,
427
- "gbxml",
428
- message=message,
429
- )
430
- print("COMMIT ID", commit_id)
431
- for commit in branch.commits.items:
432
- print(" VS. COMMIT.ID", commit.id)
433
- if commit.id == commit_id:
434
- return commit
435
- return None
436
-
437
- @staticmethod
438
- def SpeckleStreamByID(stream_list, stream_id):
439
- """
440
- Parameters
441
- ----------
442
- stream_list : TYPE
443
- DESCRIPTION.
444
- stream_id : TYPE
445
- DESCRIPTION.
446
-
447
- Returns
448
- -------
449
- stream : TYPE
450
- DESCRIPTION.
451
-
452
- """
453
- # stream_list, stream_id = item
454
- for stream in stream_list:
455
- if stream.id == stream_id:
456
- return stream
457
- return None
458
-
459
- @staticmethod
460
- def SpeckleStreamByURL(url, token):
461
- """
462
- Parameters
463
- ----------
464
- url : TYPE
465
- DESCRIPTION.
466
- token : TYPE
467
- DESCRIPTION.
468
-
469
- Returns
470
- -------
471
- stream : TYPE
472
- DESCRIPTION.
473
-
474
- """
475
- # url, token = item
476
-
477
- def streamByID(item):
478
- stream_list, stream_id = item
479
- for stream in stream_list:
480
- if stream.id == stream_id:
481
- return stream
482
- return None
483
-
484
- def streamsByClient(client):
485
- return client.stream.list()
486
-
487
- # provide any stream, branch, commit, object, or globals url
488
- wrapper = StreamWrapper(url)
489
- client = wrapper.get_client()
490
- client.authenticate_with_token(token)
491
- streams = streamsByClient(client)
492
- stream = streamByID([streams, wrapper.stream_id])
493
- return stream
494
-
495
- @staticmethod
496
- def StreamsByClient(item):
497
- """
498
- Parameters
499
- ----------
500
- item : TYPE
501
- DESCRIPTION.
502
-
503
- Returns
504
- -------
505
- TYPE
506
- DESCRIPTION.
507
-
508
- """
1
+ # Copyright (C) 2024
2
+ # Wassim Jabi <wassim.jabi@gmail.com>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify it under
5
+ # the terms of the GNU Affero General Public License as published by the Free Software
6
+ # Foundation, either version 3 of the License, or (at your option) any later
7
+ # version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful, but WITHOUT
10
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
12
+ # details.
13
+ #
14
+ # You should have received a copy of the GNU Affero General Public License along with
15
+ # this program. If not, see <https://www.gnu.org/licenses/>.
16
+
17
+ from specklepy.api.client import SpeckleClient
18
+ from specklepy.api.wrapper import StreamWrapper
19
+ from specklepy.api import operations
20
+ from specklepy.objects import Base
21
+ from specklepy.objects.other import RenderMaterial
22
+ from specklepy.transports.server import ServerTransport
23
+ from topologicpy.Topology import Topology
24
+ from specklepy.objects.geometry import (Mesh, Point, Polyline)
25
+ class Speckle:
26
+
27
+ @staticmethod
28
+ def mesh_to_speckle(topology) -> Base:
29
+ b = Base()
30
+ b["name"] = "Topologic_Object"
31
+ b["@displayValue"] = Speckle.mesh_to_speckle_mesh(topology)
32
+ return b
33
+
34
+ @staticmethod
35
+ def mesh_to_speckle_mesh(topology, mantissa: int = 6) -> Mesh:
36
+
37
+ geom = Topology.Geometry(topology, mantissa=mantissa)
38
+ vertices = geom['vertices']
39
+ faces = geom['faces']
40
+ #m_verts: List[float] = []
41
+ #m_faces: List[int] = []
42
+ m_verts = []
43
+ m_faces = []
44
+
45
+ for v in vertices:
46
+ m_verts.append(v[0])
47
+ m_verts.append(v[1])
48
+ m_verts.append(v[2])
49
+
50
+ for f in faces:
51
+ n = len(f)
52
+ m_faces.append(n)
53
+ for i in range(n):
54
+ m_faces.append(f[i])
55
+
56
+ speckle_mesh = Mesh(
57
+ vertices=m_verts,
58
+ faces=m_faces,
59
+ )
60
+ speckle_mat = RenderMaterial()
61
+ speckle_mat['Opacity'] = 0.5
62
+ speckle_mesh["renderMaterial"] = speckle_mat
63
+ return speckle_mesh
64
+
65
+ @staticmethod
66
+ def SpeckleBranchByID(branch_list, branch_id):
67
+ """
68
+ Parameters
69
+ ----------
70
+ branch_list : TYPE
71
+ DESCRIPTION.
72
+ branch_id : TYPE
73
+ DESCRIPTION.
74
+
75
+ Returns
76
+ -------
77
+ branch : TYPE
78
+ DESCRIPTION.
79
+
80
+ """
81
+ # branch_list, branch_id = item
82
+ for branch in branch_list:
83
+ if branch.id == branch_id:
84
+ return branch
85
+ return None
86
+
87
+ @staticmethod
88
+ def BranchesByStream(client, stream):
89
+ """
90
+ Parameters
91
+ ----------
92
+ client : TYPE
93
+ DESCRIPTION.
94
+ stream : TYPE
95
+ DESCRIPTION.
96
+
97
+ Returns
98
+ -------
99
+ branches : TYPE
100
+ DESCRIPTION.
101
+
102
+ """
103
+ # client, stream = item
104
+ bList = client.branch.list(stream.id)
105
+ branches = []
106
+ for b in bList:
107
+ branches.append(client.branch.get(stream.id, b.name))
108
+ return branches
109
+
110
+ @staticmethod
111
+ def ClientByURL(url="speckle.xyz", token=None):
112
+ """
113
+ Parameters
114
+ ----------
115
+ url : TYPE
116
+ DESCRIPTION.
117
+ token : TYPE
118
+ DESCRIPTION.
119
+
120
+ Returns
121
+ -------
122
+ client : TYPE
123
+ DESCRIPTION.
124
+
125
+ """
126
+ import getpass
127
+ if token == None:
128
+ token = getpass.getpass()
129
+ if token == None:
130
+ print("Speckle.ClientByHost - Error: Could not retrieve token. Returning None.")
131
+ return None
132
+ client = SpeckleClient(host=url) # or whatever your host is
133
+ client.authenticate_with_token(token)
134
+ return client
135
+
136
+ @staticmethod
137
+ def CommitByID(commit_list, commit_id):
138
+ """
139
+ Parameters
140
+ ----------
141
+ commit_list : TYPE
142
+ DESCRIPTION.
143
+ commit_id : TYPE
144
+ DESCRIPTION.
145
+
146
+ Returns
147
+ -------
148
+ commit : TYPE
149
+ DESCRIPTION.
150
+
151
+ """
152
+ # commit_list, commit_id = item
153
+ for commit in commit_list:
154
+ if commit.id == commit_id:
155
+ return commit
156
+ return None
157
+
158
+ @staticmethod
159
+ def SpeckleCommitByURL(url, token):
160
+ """
161
+ Parameters
162
+ ----------
163
+ url : TYPE
164
+ DESCRIPTION.
165
+ token : TYPE
166
+ DESCRIPTION.
167
+
168
+ Returns
169
+ -------
170
+ commit : TYPE
171
+ DESCRIPTION.
172
+
173
+ """
174
+ # url, token = item
175
+
176
+ def streamByID(item):
177
+ stream_list, stream_id = item
178
+ for stream in stream_list:
179
+ if stream.id == stream_id:
180
+ return stream
181
+ return None
182
+
183
+ def streamsByClient(client):
184
+ return client.stream.list()
185
+
186
+ def commitByID(item):
187
+ commit_list, commit_id = item
188
+ for commit in commit_list:
189
+ if commit.id == commit_id:
190
+ return commit
191
+ return None
192
+
193
+ # provide any stream, branch, commit, object, or globals url
194
+ wrapper = StreamWrapper(url)
195
+ client = wrapper.get_client()
196
+ client.authenticate_with_token(token)
197
+ print("Client", client)
198
+ streams = streamsByClient(client)
199
+ print("Streams", streams)
200
+ stream = streamByID([streams, wrapper.stream_id])
201
+ print("Stream", stream)
202
+ commits = client.commit.list(wrapper.stream_id)
203
+ commit = commitByID([commits, wrapper.commit_id])
204
+ print(commit)
205
+ return commit
206
+
207
+ @staticmethod
208
+ def SpeckleCommitDelete(client, stream, commit, confirm):
209
+ """
210
+ Parameters
211
+ ----------
212
+ client : TYPE
213
+ DESCRIPTION.
214
+ stream : TYPE
215
+ DESCRIPTION.
216
+ commit : TYPE
217
+ DESCRIPTION.
218
+ confirm : TYPE
219
+ DESCRIPTION.
220
+
221
+ Returns
222
+ -------
223
+ TYPE
224
+ DESCRIPTION.
225
+
226
+ """
227
+ # client, stream, commit, confirm = item
228
+ if confirm:
229
+ try:
230
+ deleted = client.commit.delete(stream_id=stream.id, commit_id=commit.id)
231
+ return deleted
232
+ except:
233
+ return False
234
+ return False
235
+
236
+ @staticmethod
237
+ def CommitsByBranch(branch):
238
+ """
239
+ Parameters
240
+ ----------
241
+ item : TYPE
242
+ DESCRIPTION.
243
+
244
+ Returns
245
+ -------
246
+ TYPE
247
+ DESCRIPTION.
248
+
249
+ """
250
+ return branch.commits.items
251
+
252
+ @staticmethod
253
+ def SpeckleGlobalsByStream(client, stream):
254
+ """
255
+ Parameters
256
+ ----------
257
+ client : TYPE
258
+ DESCRIPTION.
259
+ stream : TYPE
260
+ DESCRIPTION.
261
+
262
+ Returns
263
+ -------
264
+ TYPE
265
+ DESCRIPTION.
266
+
267
+ """
268
+ # client, stream = item
269
+
270
+ def processBase(base):
271
+ dictionary = {}
272
+ dynamic_member_names = base.get_dynamic_member_names()
273
+ for dynamic_member_name in dynamic_member_names:
274
+ attribute = base[dynamic_member_name]
275
+ if isinstance(attribute, float) or isinstance(attribute, int) or isinstance(attribute, str) or isinstance(attribute, list):
276
+ dictionary[dynamic_member_name] = attribute
277
+ if isinstance(attribute, Base):
278
+ dictionary[dynamic_member_name] = processBase(attribute)
279
+ return dictionary
280
+
281
+ transport = ServerTransport(client=client, stream_id=stream.id)
282
+
283
+ # get the `globals` branch
284
+ branch = client.branch.get(stream.id, "globals")
285
+
286
+ # get the latest commit
287
+ if len(branch.commits.items) > 0:
288
+ latest_commit = branch.commits.items[0]
289
+
290
+ # receive the globals object
291
+ globs = operations.receive(latest_commit.referencedObject, transport)
292
+ return processBase(globs)
293
+ return None
294
+
295
+ @staticmethod
296
+ def Send(client, stream, branch, description, message, key, data, run):
297
+ """
298
+ Parameters
299
+ ----------
300
+ client : TYPE
301
+ DESCRIPTION.
302
+ stream : TYPE
303
+ DESCRIPTION.
304
+ branch : TYPE
305
+ DESCRIPTION.
306
+ description : TYPE
307
+ DESCRIPTION.
308
+ message : TYPE
309
+ DESCRIPTION.
310
+ key : TYPE
311
+ DESCRIPTION.
312
+ data : TYPE
313
+ DESCRIPTION.
314
+ run : TYPE
315
+ DESCRIPTION.
316
+
317
+ Returns
318
+ -------
319
+ commit : TYPE
320
+ DESCRIPTION.
321
+
322
+ """
323
+ # client, stream, branch, description, message, key, data, run = item
324
+ if not run:
325
+ return None
326
+ # create a base object to hold data
327
+ base = Base()
328
+ base[key] = data
329
+ transport = ServerTransport(stream.id, client)
330
+ # and send the data to the server and get back the hash of the object
331
+ obj_id = operations.send(base, [transport])
332
+
333
+ # now create a commit on that branch with your updated data!
334
+ commit_id = client.commit.create(
335
+ stream.id,
336
+ obj_id,
337
+ key,
338
+ message=message,
339
+ )
340
+ print("COMMIT ID", commit_id)
341
+ for commit in branch.commits.items:
342
+ print(" VS. COMMIT.ID", commit.id)
343
+ if commit.id == commit_id:
344
+ return commit
345
+ return None
346
+
347
+ @staticmethod
348
+ def Object(client, stream, branch, commit):
349
+ #from topologicpy.Dictionary import Dictionary
350
+ from topologicpy.Topology import Topology
351
+ def add_vertices(speckle_mesh, scale=1.0):
352
+ sverts = speckle_mesh.vertices
353
+ vertices = []
354
+ if sverts and len(sverts) > 0:
355
+ for i in range(0, len(sverts), 3):
356
+ vertices.append([float(sverts[i]) * scale, float(sverts[i + 1]) * scale, float(sverts[i + 2]) * scale])
357
+ return vertices
358
+
359
+ def add_faces(speckle_mesh):
360
+ sfaces = speckle_mesh.faces
361
+ faces = []
362
+ if sfaces and len(sfaces) > 0:
363
+ i = 0
364
+ while i < len(sfaces):
365
+ n = sfaces[i]
366
+ if n < 3:
367
+ n += 3 # 0 -> 3, 1 -> 4
368
+ i += 1
369
+ faces.append([int(x) for x in sfaces[i : i + n]])
370
+ i += n
371
+ return faces
372
+
373
+ def mesh_to_native(speckle_mesh, scale=1.0):
374
+ vertices = add_vertices(speckle_mesh, scale)
375
+ faces = add_faces(speckle_mesh)
376
+ topology = Topology.ByGeometry(vertices=vertices, edges=[], faces=faces)
377
+ return topology
378
+
379
+ transport = ServerTransport(stream.id, client)
380
+ last_obj_id = commit.referencedObject
381
+ speckle_mesh = operations.receive(obj_id=last_obj_id, remote_transport=transport)
382
+ print(speckle_mesh)
383
+ return mesh_to_native(speckle_mesh["@display_value"])
384
+
385
+ @staticmethod
386
+ def SpeckleSendObjects(client, stream, branch, description, message, key, data, run):
387
+ """
388
+ Parameters
389
+ ----------
390
+ client : TYPE
391
+ DESCRIPTION.
392
+ stream : TYPE
393
+ DESCRIPTION.
394
+ branch : TYPE
395
+ DESCRIPTION.
396
+ description : TYPE
397
+ DESCRIPTION.
398
+ message : TYPE
399
+ DESCRIPTION.
400
+ key : TYPE
401
+ DESCRIPTION.
402
+ data : TYPE
403
+ DESCRIPTION.
404
+ run : TYPE
405
+ DESCRIPTION.
406
+
407
+ Returns
408
+ -------
409
+ commit : TYPE
410
+ DESCRIPTION.
411
+
412
+ """
413
+ # client, stream, branch, description, message, key, data, run = item
414
+ if not run:
415
+ return None
416
+ # create a base object to hold data
417
+ base = Base()
418
+ base[key] = data
419
+ transport = ServerTransport(stream.id, client)
420
+ # and send the data to the server and get back the hash of the object
421
+ obj_id = operations.send(base, [transport])
422
+
423
+ # now create a commit on that branch with your updated data!
424
+ commit_id = client.commit.create(
425
+ stream.id,
426
+ obj_id,
427
+ "gbxml",
428
+ message=message,
429
+ )
430
+ print("COMMIT ID", commit_id)
431
+ for commit in branch.commits.items:
432
+ print(" VS. COMMIT.ID", commit.id)
433
+ if commit.id == commit_id:
434
+ return commit
435
+ return None
436
+
437
+ @staticmethod
438
+ def SpeckleStreamByID(stream_list, stream_id):
439
+ """
440
+ Parameters
441
+ ----------
442
+ stream_list : TYPE
443
+ DESCRIPTION.
444
+ stream_id : TYPE
445
+ DESCRIPTION.
446
+
447
+ Returns
448
+ -------
449
+ stream : TYPE
450
+ DESCRIPTION.
451
+
452
+ """
453
+ # stream_list, stream_id = item
454
+ for stream in stream_list:
455
+ if stream.id == stream_id:
456
+ return stream
457
+ return None
458
+
459
+ @staticmethod
460
+ def SpeckleStreamByURL(url, token):
461
+ """
462
+ Parameters
463
+ ----------
464
+ url : TYPE
465
+ DESCRIPTION.
466
+ token : TYPE
467
+ DESCRIPTION.
468
+
469
+ Returns
470
+ -------
471
+ stream : TYPE
472
+ DESCRIPTION.
473
+
474
+ """
475
+ # url, token = item
476
+
477
+ def streamByID(item):
478
+ stream_list, stream_id = item
479
+ for stream in stream_list:
480
+ if stream.id == stream_id:
481
+ return stream
482
+ return None
483
+
484
+ def streamsByClient(client):
485
+ return client.stream.list()
486
+
487
+ # provide any stream, branch, commit, object, or globals url
488
+ wrapper = StreamWrapper(url)
489
+ client = wrapper.get_client()
490
+ client.authenticate_with_token(token)
491
+ streams = streamsByClient(client)
492
+ stream = streamByID([streams, wrapper.stream_id])
493
+ return stream
494
+
495
+ @staticmethod
496
+ def StreamsByClient(item):
497
+ """
498
+ Parameters
499
+ ----------
500
+ item : TYPE
501
+ DESCRIPTION.
502
+
503
+ Returns
504
+ -------
505
+ TYPE
506
+ DESCRIPTION.
507
+
508
+ """
509
509
  return item.stream.list()