svg для графа сборки
|
@ -0,0 +1,44 @@
|
||||||
|
import json
|
||||||
|
import networkx as nx
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from PIL import Image
|
||||||
|
import matplotlib.image as mpimg
|
||||||
|
from networkx.drawing.nx_agraph import graphviz_layout
|
||||||
|
|
||||||
|
def load_assembly_sequence(filepath):
|
||||||
|
with open(filepath, 'r') as file:
|
||||||
|
return json.load(file)
|
||||||
|
|
||||||
|
def create_assembly_graph(sequence):
|
||||||
|
G = nx.DiGraph()
|
||||||
|
|
||||||
|
for i, part in enumerate(sequence):
|
||||||
|
G.add_node(part, image=f'{part}.svg')
|
||||||
|
if i > 0:
|
||||||
|
G.add_edge(sequence[i-1], part)
|
||||||
|
|
||||||
|
return G
|
||||||
|
|
||||||
|
def draw_graph(G):
|
||||||
|
pos = graphviz_layout(G, prog='dot')
|
||||||
|
fig, ax = plt.subplots(figsize=(12, 8))
|
||||||
|
|
||||||
|
for node in G.nodes(data=True):
|
||||||
|
x, y = pos[node[0]]
|
||||||
|
img = mpimg.imread(node[1]['image'])
|
||||||
|
ax.imshow(img, aspect='auto', extent=(x-0.5, x+0.5, y-0.5, y+0.5), zorder=1)
|
||||||
|
|
||||||
|
ax.text(x, y-0.6, s=node[0], horizontalalignment='center', fontsize=12, zorder=2)
|
||||||
|
|
||||||
|
nx.draw_networkx_edges(G, pos, ax=ax, arrows=True)
|
||||||
|
plt.axis('off')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
sequence = load_assembly_sequence('assembly_sequence.json')
|
||||||
|
assembly_graph = create_assembly_graph(sequence)
|
||||||
|
|
||||||
|
draw_graph(assembly_graph)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
34
test_models/img/body_down.svg
Normal file
After Width: | Height: | Size: 650 KiB |
30
test_models/img/body_up.svg
Normal file
After Width: | Height: | Size: 658 KiB |
18
test_models/img/bolt.svg
Normal file
After Width: | Height: | Size: 22 KiB |
18
test_models/img/bolt2.svg
Normal file
After Width: | Height: | Size: 22 KiB |
18
test_models/img/bolt3.svg
Normal file
After Width: | Height: | Size: 22 KiB |
18
test_models/img/bolt4.svg
Normal file
After Width: | Height: | Size: 22 KiB |
53
test_models/img/output_shaft.svg
Normal file
After Width: | Height: | Size: 728 KiB |
13
test_models/img/planet_gear.svg
Normal file
After Width: | Height: | Size: 104 KiB |
13
test_models/img/planet_gear002.svg
Normal file
After Width: | Height: | Size: 104 KiB |
13
test_models/img/planet_gear003.svg
Normal file
After Width: | Height: | Size: 104 KiB |
13
test_models/img/planet_gear004.svg
Normal file
After Width: | Height: | Size: 104 KiB |
13
test_models/img/planet_gear005.svg
Normal file
After Width: | Height: | Size: 104 KiB |
20
test_models/img/sol_gear.svg
Normal file
After Width: | Height: | Size: 414 KiB |